diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-02-19 15:24:20 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-02-19 15:24:20 -0800 |
commit | cae5461b1dfeb70dac6b66192fc6b12952beb723 (patch) | |
tree | 235f8f62fff902c3227d65c9c64c41d0e45e1485 /cpp/012run | |
parent | 01b2852b653a81c4d5e197a0c52659c7e0dcaf5f (diff) | |
download | mu-cae5461b1dfeb70dac6b66192fc6b12952beb723.tar.gz |
783
Diffstat (limited to 'cpp/012run')
-rw-r--r-- | cpp/012run | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/cpp/012run b/cpp/012run index f7b5469a..9696da43 100644 --- a/cpp/012run +++ b/cpp/012run @@ -4,8 +4,8 @@ recipe main [ 1:integer <- copy 23:literal ] +run: instruction 0 -+run: ingredient 23 -+mem: storing in location 1 ++run: ingredient 0 is 23 ++mem: storing in location 1 :(code) void run(string form) { @@ -20,11 +20,9 @@ void run(recipe_number r) { trace("run") << "instruction " << n; switch (p->operation) { case 1: { // copy - int arg = to_int(p->ingredients[0].name); - trace("run") << " ingredient " << arg; - int dest = to_int(p->products[0].name); - trace("mem") << " storing in location " << dest; - Memory[dest] = arg; + vector<int> data = read_memory(p->ingredients[0]); + trace("run") << "ingredient 0 is " << data[0]; + write_memory(p->products[0], data); break; } default: @@ -33,6 +31,18 @@ void run(recipe_number r) { } } +vector<int> read_memory(reagent x) { + vector<int> result; + result.push_back(to_int(x.name)); + return result; +} + +void write_memory(reagent x, vector<int> data) { + int dest = to_int(x.name); + trace("mem") << "storing in location " << dest; + Memory[dest] = data[0]; +} + int to_int(string n) { char* end = NULL; int result = strtol(n.c_str(), &end, /*any base*/0); |