Extract pointing to mem_address to new instruction

- pointa, point now uses this instruction
master
Raymon Zutekouw 3 years ago
parent d26500251d
commit 5476b6d8f2
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 2
      src/grammars/mblf.pest
  2. 21
      src/main.rs

@ -17,6 +17,7 @@ var =@{ "var" ~ spacing+ ~ variable }
delvar =@{ "delvar" ~ spacing+ ~ variable }
point =@{ "point" ~ spacing+ ~ variable }
pointa =@{ "pointa" ~ spacing+ ~ num }
pointm =@{ "pointm" ~ spacing+ ~ variable }
add =@{ "add" ~ spacing+ ~ constant }
@ -38,6 +39,7 @@ instruction =_{ macaroo
| delvar
| point
| pointa
| pointm
| add

@ -92,13 +92,20 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
.variables
.get(variable_name)
.unwrap_or_else(|| panic!("Variable '{}' did not exists", variable_name))
.address;
if address < state.mem_pointer {
out.append("<".repeat((state.mem_pointer - address) as usize))
} else if address > state.mem_pointer {
out.append(">".repeat((address - state.mem_pointer) as usize))
}
state.mem_pointer = address;
.address
.to_string();
to_bf(Rule::pointa, &address, state, out)
}
Rule::pointa => {
let address = operand;
let address_parsed = parse_constant(address).unwrap();
println!("Pointing to address '{}'", address);
if address_parsed < state.mem_pointer {
out.append("<".repeat((state.mem_pointer - address_parsed) as usize))
} else if address_parsed > state.mem_pointer {
out.append(">".repeat((address_parsed - state.mem_pointer) as usize))
}
state.mem_pointer = address_parsed;
}
Rule::pointm => {
let variable_name = operand;

Loading…
Cancel
Save