diff options
-rw-r--r-- | cpp/010vm | 10 | ||||
-rw-r--r-- | cpp/012run | 24 |
2 files changed, 25 insertions, 9 deletions
diff --git a/cpp/010vm b/cpp/010vm index 3b8a7c96..a8ce5bac 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -73,8 +73,11 @@ void setup_types() { Type.clear(); Type_number.clear(); Type_number["literal"] = 0; Next_type_number = 1; - int integer = Type_number["integer"] = Next_type_number++; + // New Types. + int integer = Type_number["integer"] = 1; Type[integer].size = 1; + Next_type_number++; + // End New Types. } :(before "End Setup") setup_types(); @@ -102,7 +105,10 @@ void setup_recipes() { Recipe.clear(); Recipe_number.clear(); Recipe_number["idle"] = 0; Next_recipe_number = 1; - Recipe_number["copy"] = Next_recipe_number++; + // New Recipes. + Recipe_number["copy"] = 1; + Next_recipe_number++; + // End New Recipes. } :(before "End Types") const int idle = 0; // always the first entry in the recipe book 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); |