about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/set_default_space6
-rw-r--r--cpp/027space13
2 files changed, 13 insertions, 6 deletions
diff --git a/cpp/.traces/set_default_space b/cpp/.traces/set_default_space
index 5c9d8cad..326ca4b1 100644
--- a/cpp/.traces/set_default_space
+++ b/cpp/.traces/set_default_space
@@ -2,7 +2,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "10", value: 0, type: 0, properties: [10: literal]}
 parse/0:   product: {name: "default-space", value: 0, type: 2-0, properties: [default-space: address:space]}
 parse/0: instruction: 1
-parse/0:   ingredient: {name: "12", value: 0, type: 0, properties: [12: literal]}
+parse/0:   ingredient: {name: "23", value: 0, type: 0, properties: [23: literal]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: [1: integer]}
 name/0: assign default-space 1
 after-brace/0: recipe main
@@ -11,5 +11,5 @@ after-brace/0: copy ...
 run/0: instruction main/0
 run/0: ingredient 0 is 10
 run/0: instruction main/1
-run/0: ingredient 0 is 12
-mem/0: storing 12 in location 11
+run/0: ingredient 0 is 23
+mem/0: storing 23 in location 12
diff --git a/cpp/027space b/cpp/027space
index 67092ca0..2fa6f36d 100644
--- a/cpp/027space
+++ b/cpp/027space
@@ -4,11 +4,13 @@
 
 :(scenarios run)
 :(scenario "set_default_space")
+# if default-space is 10, the array of locals begins at location 10
+# and so location 1 is really location 12
 recipe main [
   default-space:address:space <- copy 10:literal
-  1:integer <- copy 12:literal
+  1:integer <- copy 23:literal
 ]
-+mem: storing 12 in location 11
++mem: storing 23 in location 12
 
 :(before "End Call Fields")
 size_t default_space;
@@ -24,7 +26,7 @@ reagent absolutize(reagent x) {
 //?   cout << "not raw: " << x.to_string() << '\n'; //? 1
   assert(x.initialized);
   reagent r = x;
-  r.set_value(r.value + Current_routine.calls.top().default_space);
+  r.set_value(address(r.value, Current_routine.calls.top().default_space));
 //?   cout << "after absolutize: " << r.value << '\n'; //? 1
   if (r.properties.empty())
     r.properties.push_back(pair<string, vector<string> >("", vector<string>()));
@@ -33,6 +35,11 @@ reagent absolutize(reagent x) {
   return r;
 }
 
+int address(int offset, int base) {
+  if (base == 0) return offset;  // raw
+  return base+offset+1;
+}
+
 :(after "void write_memory(reagent x, vector<int> data)")
   if (x.name == "default-space") {
     assert(data.size() == 1);