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. 19
      src/main.rs

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

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

Loading…
Cancel
Save