about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/013run2
-rw-r--r--cpp/018record12
-rw-r--r--cpp/019address52
-rw-r--r--cpp/090debug1
4 files changed, 11 insertions, 56 deletions
diff --git a/cpp/013run b/cpp/013run
index e811d96d..180c862e 100644
--- a/cpp/013run
+++ b/cpp/013run
@@ -115,7 +115,6 @@ for (size_t i = 0; i < recipes_added_by_test.size(); ++i) {
 recipes_added_by_test.clear();
 
 :(code)
-//: beware: overridden in later layers
 vector<int> read_memory(reagent x) {
 //?   cout << "read_memory: " << x.to_string() << '\n'; //? 1
   vector<int> result;
@@ -133,7 +132,6 @@ vector<int> read_memory(reagent x) {
   return result;
 }
 
-//: beware: overridden in later layers
 void write_memory(reagent x, vector<int> data) {
   if (is_dummy(x)) return;
   int base = x.value;
diff --git a/cpp/018record b/cpp/018record
index dba43a91..58188813 100644
--- a/cpp/018record
+++ b/cpp/018record
@@ -79,11 +79,11 @@ Recipe_number["get"] = GET;
 assert(Next_recipe_number == GET);
 Next_recipe_number++;
 :(before "End Primitive Recipe Implementations")
-//: beware: overridden in later layers
 case GET: {
   trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
-  int base_address = instructions[pc].ingredients[0].value;
-  int base_type = instructions[pc].ingredients[0].types[0];
+  reagent base = instructions[pc].ingredients[0];
+  int base_address = base.value;
+  int base_type = base.types[0];
   assert(Type[base_type].is_record);
   trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
   assert(isa_literal(instructions[pc].ingredients[1]));
@@ -93,6 +93,7 @@ case GET: {
     src += size_of(Type[base_type].elements[i]);
   }
   trace("run") << "address to copy is " << src;
+  assert(Type[base_type].is_record);
   assert(Type[base_type].elements.size() > offset);
   int src_type = Type[base_type].elements[offset][0];
   trace("run") << "its type is " << src_type;
@@ -136,8 +137,9 @@ Next_recipe_number++;
 :(before "End Primitive Recipe Implementations")
 case GET_ADDRESS: {
   trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
-  int base_address = instructions[pc].ingredients[0].value;
-  int base_type = instructions[pc].ingredients[0].types[0];
+  reagent base = instructions[pc].ingredients[0];
+  int base_address = base.value;
+  int base_type = base.types[0];
   assert(Type[base_type].is_record);
   trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
   assert(isa_literal(instructions[pc].ingredients[1]));
diff --git a/cpp/019address b/cpp/019address
index 13d59465..0b39c71d 100644
--- a/cpp/019address
+++ b/cpp/019address
@@ -98,33 +98,8 @@ recipe main [
 +run: product 0 is 34
 +mem: storing 34 in location 4
 
-:(replace{} "case GET:")
-case GET: {
-  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
-  reagent base = canonize(instructions[pc].ingredients[0]);
-  int base_address = base.value;
-  int base_type = base.types[0];
-  assert(Type[base_type].is_record);
-  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
-  assert(isa_literal(instructions[pc].ingredients[1]));
-  size_t offset = instructions[pc].ingredients[1].value;
-  int src = base_address;
-  for (size_t i = 0; i < offset; ++i) {
-    src += size_of(Type[base_type].elements[i]);
-  }
-  trace("run") << "address to copy is " << src;
-  assert(Type[base_type].is_record);
-  assert(Type[base_type].elements.size() > offset);
-  int src_type = Type[base_type].elements[offset][0];
-  trace("run") << "its type is " << src_type;
-  reagent tmp;
-  tmp.set_value(src);
-  tmp.types.push_back(src_type);
-  vector<int> result(read_memory(tmp));
-  trace("run") << "product 0 is " << result[0];
-  write_memory(instructions[pc].products[0], result);
-  break;
-}
+:(after "reagent base = " following "case GET:")
+base = canonize(base);
 
 :(scenario "get_address_indirect")
 # 'get' can read from record address
@@ -138,24 +113,5 @@ recipe main [
 +run: address to copy is 2
 +run: product 0 is 2
 
-:(replace{} "case GET_ADDRESS:")
-case GET_ADDRESS: {
-  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
-  reagent base = canonize(instructions[pc].ingredients[0]);
-  int base_address = base.value;
-  int base_type = base.types[0];
-  assert(Type[base_type].is_record);
-  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
-  assert(isa_literal(instructions[pc].ingredients[1]));
-  size_t offset = instructions[pc].ingredients[1].value;
-  int src = base_address;
-  for (size_t i = 0; i < offset; ++i) {
-    src += size_of(Type[base_type].elements[i]);
-  }
-  trace("run") << "address to copy is " << src;
-  vector<int> result;
-  result.push_back(src);
-  trace("run") << "product 0 is " << result[0];
-  write_memory(instructions[pc].products[0], result);
-  break;
-}
+:(after "reagent base = " following "case GET_ADDRESS:")
+base = canonize(base);
diff --git a/cpp/090debug b/cpp/090debug
index ca88b86c..70d518ed 100644
--- a/cpp/090debug
+++ b/cpp/090debug
@@ -5,7 +5,6 @@ const int _PRINT = 99;
 Recipe_number["$print"] = _PRINT;
 assert(Next_recipe_number < _PRINT);
 :(before "End Primitive Recipe Implementations")
-//: beware: overridden in later layers
 case _PRINT: {
   vector<int> result(read_memory(instructions[pc].ingredients[0]));
   cout << result[0] << '\n';