From aff0ed00342d9c1602388f3628db8672bb19a35f Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Fri, 7 Jan 2022 14:07:28 +0100 Subject: [PATCH] Implement copy --- src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1d7bf41..1a7ca13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,7 +162,24 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) { Rule::copy => { let variable_name = operand; println!("Copy to variable '{}'", variable_name); - out.append("copy\n"); + let source_address = state.mem_pointer.to_string(); + to_bf(Rule::var, "__temp", state, out); + 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::point, "__temp", state, out); + to_bf(Rule::add, "1", state, out); + to_bf(Rule::pointa, &source_address, state, out); + out.append("]"); + to_bf(Rule::point, "__temp", state, out); + out.append("["); + to_bf(Rule::sub, "1", state, out); + to_bf(Rule::pointa, &source_address, state, out); + to_bf(Rule::add, "1", state, out); + to_bf(Rule::point, "__temp", state, out); + out.append("]"); + to_bf(Rule::delvar, "__temp", state, out); } Rule::setz => { println!("Set current variable to zero");