Implement addv and subv

master
Raymon Zutekouw 3 years ago
parent 5476b6d8f2
commit 20869b55c1
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 16
      src/main.rs

@ -131,7 +131,13 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
Rule::addv => { Rule::addv => {
let variable_name = operand; let variable_name = operand;
println!("Addition to variable '{}'", variable_name); println!("Addition to variable '{}'", variable_name);
out.append("addv\n"); let source_address = state.mem_pointer.to_string();
out.append("[");
to_bf(Rule::sub, "1", state, out);
to_bf(Rule::point, variable_name, state, out);
to_bf(Rule::add, "1", state, out);
to_bf(Rule::pointa, &source_address, state, out);
out.append("]");
} }
Rule::sub => { Rule::sub => {
let constant = operand; let constant = operand;
@ -145,7 +151,13 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
Rule::subv => { Rule::subv => {
let variable_name = operand; let variable_name = operand;
println!("Subtraction from variable '{}'", variable_name); println!("Subtraction from variable '{}'", variable_name);
out.append("subv\n"); let source_address = state.mem_pointer.to_string();
out.append("[");
to_bf(Rule::sub, "1", state, out);
to_bf(Rule::point, variable_name, state, out);
to_bf(Rule::sub, "1", state, out);
to_bf(Rule::pointa, &source_address, state, out);
out.append("]");
} }
Rule::copy => { Rule::copy => {
let variable_name = operand; let variable_name = operand;

Loading…
Cancel
Save