about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-03 12:49:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-03 12:49:34 -0700
commit07d35c4af3275b32f4b2e5d870faea67c1ea6285 (patch)
treedc6262f714753da9c84092df57189e6725f7528c
parent4b79c627c226bc64f271c31531c805cd6875c8ca (diff)
downloadmu-07d35c4af3275b32f4b2e5d870faea67c1ea6285.tar.gz
1010
-rw-r--r--cpp/.traces/index4
-rw-r--r--cpp/.traces/index_address2
-rw-r--r--cpp/.traces/index_direct_offset50
-rw-r--r--cpp/.traces/index_indirect4
-rw-r--r--cpp/.traces/new_string4
-rw-r--r--cpp/020array42
6 files changed, 88 insertions, 18 deletions
diff --git a/cpp/.traces/index b/cpp/.traces/index
index 685ad173..cee3a327 100644
--- a/cpp/.traces/index
+++ b/cpp/.traces/index
@@ -33,8 +33,8 @@ run/0: instruction main/3
 run/0: ingredient 0 is 16
 mem/0: storing 16 in location 4
 run/0: instruction main/4
-run/0: ingredient 0 is 1
-run/0: ingredient 1 is 0
+run/0: ingredient 0 is {name: "1", value: 1, type: 4-1, properties: ["1": "array":"integer"]}
+run/0: ingredient 1 is {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 run/0: address to copy is 2
 run/0: its type is 1
 mem/0: location 2 is 14
diff --git a/cpp/.traces/index_address b/cpp/.traces/index_address
index c6f3ce4a..5310f6c7 100644
--- a/cpp/.traces/index_address
+++ b/cpp/.traces/index_address
@@ -34,7 +34,7 @@ run/0: ingredient 0 is 16
 mem/0: storing 16 in location 4
 run/0: instruction main/4
 run/0: ingredient 0 is 1
-run/0: ingredient 1 is 0
+run/0: ingredient 1 is {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 run/0: address to copy is 2
 run/0: product 0 is 2
 mem/0: storing 2 in location 5
diff --git a/cpp/.traces/index_direct_offset b/cpp/.traces/index_direct_offset
new file mode 100644
index 00000000..27daf63e
--- /dev/null
+++ b/cpp/.traces/index_direct_offset
@@ -0,0 +1,50 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "3", value: 0, type: 0, properties: ["3": "literal"]}
+parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "14", value: 0, type: 0, properties: ["14": "literal"]}
+parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "15", value: 0, type: 0, properties: ["15": "literal"]}
+parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "16", value: 0, type: 0, properties: ["16": "literal"]}
+parse/0:   product: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
+parse/0:   product: {name: "5", value: 0, type: 1, properties: ["5": "integer"]}
+parse/0: instruction: 20
+parse/0:   ingredient: {name: "1", value: 0, type: 4-1, properties: ["1": "array":"integer"]}
+parse/0:   ingredient: {name: "5", value: 0, type: 1, properties: ["5": "integer"]}
+parse/0:   product: {name: "6", value: 0, type: 1, properties: ["6": "integer"]}
+after-brace/0: recipe main
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: index ...
+run/0: instruction main/0
+run/0: ingredient 0 is 3
+mem/0: storing 3 in location 1
+run/0: instruction main/1
+run/0: ingredient 0 is 14
+mem/0: storing 14 in location 2
+run/0: instruction main/2
+run/0: ingredient 0 is 15
+mem/0: storing 15 in location 3
+run/0: instruction main/3
+run/0: ingredient 0 is 16
+mem/0: storing 16 in location 4
+run/0: instruction main/4
+run/0: ingredient 0 is 0
+mem/0: storing 0 in location 5
+run/0: instruction main/5
+run/0: ingredient 0 is {name: "1", value: 1, type: 4-1, properties: ["1": "array":"integer"]}
+run/0: ingredient 1 is {name: "5", value: 5, type: 1, properties: ["5": "integer"]}
+mem/0: location 5 is 0
+run/0: address to copy is 2
+run/0: its type is 1
+mem/0: location 2 is 14
+run/0: product 0 is 14
+mem/0: storing 14 in location 6
diff --git a/cpp/.traces/index_indirect b/cpp/.traces/index_indirect
index 428e3f56..7ae6b2d1 100644
--- a/cpp/.traces/index_indirect
+++ b/cpp/.traces/index_indirect
@@ -40,9 +40,9 @@ run/0: instruction main/4
 run/0: ingredient 0 is 1
 mem/0: storing 1 in location 5
 run/0: instruction main/5
-run/0: ingredient 0 is 5
+run/0: ingredient 0 is {name: "5", value: 5, type: 2-4-1, properties: ["5": "address":"array":"integer", "deref": ]}
 mem/0: location 5 is 1
-run/0: ingredient 1 is 1
+run/0: ingredient 1 is {name: "1", value: 1, type: 0, properties: ["1": "literal"]}
 run/0: address to copy is 3
 run/0: its type is 1
 mem/0: location 3 is 15
diff --git a/cpp/.traces/new_string b/cpp/.traces/new_string
index d9d75df4..1c87c169 100644
--- a/cpp/.traces/new_string
+++ b/cpp/.traces/new_string
@@ -12,9 +12,9 @@ after-brace/0: index ...
 run/0: instruction main/0
 mem/0: storing 1000 in location 1
 run/0: instruction main/1
-run/0: ingredient 0 is 1
+run/0: ingredient 0 is {name: "1", value: 1, type: 2-4-7, properties: ["1": "address":"array":"character", "deref": ]}
 mem/0: location 1 is 1000
-run/0: ingredient 1 is 5
+run/0: ingredient 1 is {name: "5", value: 5, type: 0, properties: ["5": "literal"]}
 run/0: address to copy is 1006
 run/0: its type is 7
 mem/0: location 1006 is 101
diff --git a/cpp/020array b/cpp/020array
index c310aff4..4a84af10 100644
--- a/cpp/020array
+++ b/cpp/020array
@@ -41,14 +41,29 @@ recipe main [
   5:integer <- index 1:array:integer, 0:literal
 ]
 +run: instruction main/4
-+run: ingredient 0 is 1
-+run: ingredient 1 is 0
 +run: address to copy is 2
 +run: its type is 1
 +mem: location 2 is 14
 +run: product 0 is 14
 +mem: storing 14 in location 5
 
+//: array elements are accessed using 'index'
+:(scenario "index_direct_offset")
+recipe main [
+  1:integer <- copy 3:literal
+  2:integer <- copy 14:literal
+  3:integer <- copy 15:literal
+  4:integer <- copy 16:literal
+  5:integer <- copy 0:literal
+  6:integer <- index 1:array:integer, 5:integer
+]
++run: instruction main/5
++run: address to copy is 2
++run: its type is 1
++mem: location 2 is 14
++run: product 0 is 14
++mem: storing 14 in location 6
+
 :(before "End Globals")
 // Operator to look at elements of arrays.
 const int INDEX = 20;
@@ -59,22 +74,28 @@ Next_recipe_number++;
 :(before "End Primitive Recipe Implementations")
 case INDEX: {
   static const int ARRAY = Type_number["array"];
-  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
+//?   if (Trace_stream) Trace_stream->dump_layer = "run"; //? 1
+  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].to_string();
   reagent base = canonize(instructions[pc].ingredients[0]);
+//?   trace("run") << "ingredient 0 after canonize: " << instructions[pc].ingredients[0].to_string(); //? 1
   int base_address = base.value;
   assert(base.types[0] == ARRAY);
-  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
-  size_t offset = instructions[pc].ingredients[1].value;
+  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].to_string();
+  reagent offset = canonize(instructions[pc].ingredients[1]);
+  vector<int> offset_val(read_memory(offset));
   vector<type_number> element_type = array_element(base.types);
-  int src = base_address + 1 + offset*size_of(element_type);
+  int src = base_address + 1 + offset_val[0]*size_of(element_type);
   trace("run") << "address to copy is " << src;
   trace("run") << "its type is " << element_type[0];
   reagent tmp;
   tmp.set_value(src);
   copy(element_type.begin(), element_type.end(), inserter(tmp.types, tmp.types.begin()));
+  tmp.properties.push_back(pair<string, vector<string> >("raw", vector<string>()));
+//?   cout << "AAA: " << tmp.to_string() << '\n'; //? 2
   vector<int> result(read_memory(tmp));
   trace("run") << "product 0 is " << result[0];
   write_memory(instructions[pc].products[0], result);
+//?   if (Trace_stream) Trace_stream->dump_layer = ""; //? 1
   break;
 }
 
@@ -92,8 +113,6 @@ recipe main [
   5:integer <- index-address 1:array:integer, 0:literal
 ]
 +run: instruction main/4
-+run: ingredient 0 is 1
-+run: ingredient 1 is 0
 +run: address to copy is 2
 +mem: storing 2 in location 5
 
@@ -111,10 +130,11 @@ case INDEX_ADDRESS: {
   reagent base = canonize(instructions[pc].ingredients[0]);
   int base_address = base.value;
   assert(base.types[0] == ARRAY);
-  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
-  size_t offset = instructions[pc].ingredients[1].value;
+  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].to_string();
+  reagent offset = canonize(instructions[pc].ingredients[1]);
+  vector<int> offset_val(read_memory(offset));
   vector<type_number> element_type = array_element(base.types);
-  int src = base_address + 1 + offset*size_of(element_type);
+  int src = base_address + 1 + offset_val[0]*size_of(element_type);
   trace("run") << "address to copy is " << src;
   vector<int> result;
   result.push_back(src);