:(scenario surrounding_space)
recipe main [
10:integer <- copy 5:literal
20:integer <- copy 5:literal
default-space:address:array:location <- copy 10:literal
0:address:array:location/names:dummy <- copy 20:literal
1:integer <- copy 32:literal
1:integer/space:1 <- copy 33:literal
]
+run: instruction main/3
+mem: storing 20 in location 11
+run: instruction main/4
+mem: storing 32 in location 12
+run: instruction main/5
+mem: storing 33 in location 22
:(replace{} "index_t space_base(const reagent& x)")
index_t space_base(const reagent& x) {
return space_base(x, space_index(x), Current_routine->calls.top().default_space);
}
index_t space_base(const reagent& x, index_t space_index, index_t base) {
if (space_index == 0) {
return base;
}
index_t result = space_base(x, space_index-1, Memory[base+1]);
return result;
}
index_t space_index(const reagent& x) {
for (index_t i = 0; i < x.properties.size(); ++i) {
if (x.properties[i].first == "space")
return to_int(x.properties[i].second[0]);
}
return 0;
}