From e1150e22805651c6c283d6a5e7d3f73cb0b4bae5 Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Mon, 3 Jan 2022 18:57:49 +0100 Subject: [PATCH] Fill-in struct fields --- src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c211726..70e1e4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::fs::File; use std::io::Write; @@ -16,7 +17,27 @@ use pest::Parser; #[grammar = "grammars/mblf.pest"] struct MblfParser; -struct State; +struct MemCell { + is_allocated: bool, + address: u32, + value: u8, +} + +impl MemCell { + pub fn allocate(address: u32) -> Self { + Self { + is_allocated: true, + address, + value: 0, + } + } +} + +struct State { + alloc_cnt: u32, + mem_pointer: u32, + variables: HashMap, +} #[derive(StructOpt)] struct Cli { @@ -177,7 +198,11 @@ fn main() -> Result<(), Box> { .next() .unwrap(); - let mut state = State; + let mut state = State { + alloc_cnt: 0, + mem_pointer: 0, + variables: HashMap::new(), + }; for statement in parsed_file.into_inner() { instruct(statement, &mut state, &mut builder); }