about summary refs log tree commit diff stats
path: root/044space_surround.cc
diff options
context:
space:
mode:
Diffstat (limited to '044space_surround.cc')
-rw-r--r--044space_surround.cc30
1 files changed, 19 insertions, 11 deletions
diff --git a/044space_surround.cc b/044space_surround.cc
index d645f1b4..684a69af 100644
--- a/044space_surround.cc
+++ b/044space_surround.cc
@@ -7,21 +7,26 @@
 :(scenario surrounding_space)
 # location 1 in space 1 refers to the space surrounding the default space, here 20.
 recipe main [
-  10:number <- copy 5  # pretend array
-  20:number <- copy 5  # pretend array
+  # pretend shared:array:location; in practice we'll use new
+  10:number <- copy 0  # refcount
+  11:number <- copy 5  # length
+  # pretend shared:array:location; in practice we'll use new
+  20:number <- copy 0  # refcount
+  21:number <- copy 5  # length
+  # actual start of this recipe
   default-space:address:shared:array:location <- copy 10/unsafe
   0:address:shared:array:location/names:dummy <- copy 20/unsafe  # later layers will explain the /names: property
   1:number <- copy 32
   1:number/space:1 <- copy 33
 ]
-recipe dummy [
+recipe dummy [  # just for the /names: property above
 ]
-# chain space
-+mem: storing 20 in location 11
-# store to default-space
-+mem: storing 32 in location 12
-# store to chained space
-+mem: storing 33 in location 22
+# chain space: 10 + /*skip refcount*/1 + /*skip length*/1
++mem: storing 20 in location 12
+# store to default space: 10 + /*skip refcount*/1 + /*skip length*/1 + /*index*/1
++mem: storing 32 in location 13
+# store to chained space: /*contents of location 12*/20 + /*skip refcount*/1 + /*skip length*/1 + /*index*/1
++mem: storing 33 in location 23
 
 //: If you think of a space as a collection of variables with a common
 //: lifetime, surrounding allows managing shorter lifetimes inside a longer
@@ -29,14 +34,17 @@ recipe dummy [
 
 :(replace{} "long long int space_base(const reagent& x)")
 long long int space_base(const reagent& x) {
-  return space_base(x, space_index(x), current_call().default_space);
+  long long int base = current_call().default_space ? (current_call().default_space+/*skip refcount*/1) : 0;
+  return space_base(x, space_index(x), base);
 }
 
 long long int space_base(const reagent& x, long long int space_index, long long int base) {
+//?   trace(9999, "space") << "space-base: " << space_index << " " << base << end();
   if (space_index == 0) {
     return base;
   }
-  long long int result = space_base(x, space_index-1, get_or_insert(Memory, base+1));
+  long long int result = space_base(x, space_index-1, get_or_insert(Memory, base+/*skip length*/1))+/*skip refcount*/1;
+//?   trace(9999, "space") << "space-base: " << space_index << " " << base << " => " << result << end();
   return result;
 }