about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-20 23:46:04 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-20 23:55:34 -0800
commitf02842a919823199a1fa41c0a244c3ce3409299d (patch)
tree2677781aa4d6873230014fbd1ed952c8577f8fe2
parent6eec184e408fdc70497edabd59415cf14e394bcf (diff)
downloadmu-f02842a919823199a1fa41c0a244c3ce3409299d.tar.gz
804 - reagent can have multiple types
-rw-r--r--cpp/.traces/copy_multiple_locations6
-rw-r--r--cpp/.traces/get10
-rw-r--r--cpp/.traces/get_address14
-rw-r--r--cpp/.traces/jump_backward22
-rw-r--r--cpp/.traces/parse_multiple_types5
-rw-r--r--cpp/010vm28
-rw-r--r--cpp/011load10
-rw-r--r--cpp/017record6
8 files changed, 59 insertions, 42 deletions
diff --git a/cpp/.traces/copy_multiple_locations b/cpp/.traces/copy_multiple_locations
index d721dafb..9711636e 100644
--- a/cpp/.traces/copy_multiple_locations
+++ b/cpp/.traces/copy_multiple_locations
@@ -3,10 +3,10 @@ parse/0:   ingredient: {name: "34", type: 0}
 parse/0:   product: {name: "1", type: 1}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", type: 0}
-parse/0:   product: {name: "2", type: 2}
+parse/0:   product: {name: "2", type: 3}
 parse/0: instruction: 1
-parse/0:   ingredient: {name: "1", type: 3}
-parse/0:   product: {name: "3", type: 3}
+parse/0:   ingredient: {name: "1", type: 4}
+parse/0:   product: {name: "3", type: 4}
 run/0: instruction 0
 run/0: ingredient 0 is 34
 mem/0: storing in location 1
diff --git a/cpp/.traces/get b/cpp/.traces/get
index 019070c2..38ec2a4c 100644
--- a/cpp/.traces/get
+++ b/cpp/.traces/get
@@ -3,11 +3,11 @@ parse/0:   ingredient: {name: "34", type: 0}
 parse/0:   product: {name: "12", type: 1}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", type: 0}
-parse/0:   product: {name: "13", type: 2}
+parse/0:   product: {name: "13", type: 3}
 parse/0: instruction: 18
-parse/0:   ingredient: {name: "12", type: 3}
+parse/0:   ingredient: {name: "12", type: 4}
 parse/0:   ingredient: {name: "1", type: 0}
-parse/0:   product: {name: "15", type: 2}
+parse/0:   product: {name: "15", type: 3}
 run/0: instruction 0
 run/0: ingredient 0 is 34
 mem/0: storing in location 12
@@ -17,10 +17,10 @@ mem/0: storing in location 13
 run/0: instruction 2
 run/0: ingredient 0 is 12
 run/0: base address 12
-run/0: base type is 3
+run/0: base type is 4
 run/0: ingredient 1 is 1
 run/0: address to copy is 13
-run/0: its type is 2
+run/0: its type is 3
 mem/0: location 13 is 0
 run/0: product 0 is 0
 mem/0: storing in location 15
diff --git a/cpp/.traces/get_address b/cpp/.traces/get_address
index 359df5d0..2635ebe0 100644
--- a/cpp/.traces/get_address
+++ b/cpp/.traces/get_address
@@ -3,17 +3,11 @@ parse/0:   ingredient: {name: "34", type: 0}
 parse/0:   product: {name: "12", type: 1}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", type: 0}
-parse/0:   product: {name: "13", type: 2}
+parse/0:   product: {name: "13", type: 3}
 parse/0: instruction: 19
-parse/0:   ingredient: {name: "12", type: 3}
+parse/0:   ingredient: {name: "12", type: 4}
 parse/0:   ingredient: {name: "1", type: 0}
-parse/0:   ingredient: {name: "#", type: 0}
-parse/0:   ingredient: {name: "todo", type: 0}
-parse/0:   ingredient: {name: "product", type: 0}
-parse/0:   ingredient: {name: "is", type: 0}
-parse/0:   ingredient: {name: "an", type: 0}
-parse/0:   ingredient: {name: "address", type: 0}
-parse/0:   product: {name: "15", type: 1}
+parse/0:   product: {name: "15", type: 2-1}
 run/0: instruction 0
 run/0: ingredient 0 is 34
 mem/0: storing in location 12
@@ -23,7 +17,7 @@ mem/0: storing in location 13
 run/0: instruction 2
 run/0: ingredient 0 is 12
 run/0: base address 12
-run/0: base type is 3
+run/0: base type is 4
 run/0: ingredient 1 is 1
 run/0: address to copy is 13
 run/0: product 0 is 13
diff --git a/cpp/.traces/jump_backward b/cpp/.traces/jump_backward
index 18a79084..033b1dfd 100644
--- a/cpp/.traces/jump_backward
+++ b/cpp/.traces/jump_backward
@@ -1,20 +1,20 @@
 parse/0: instruction: 10
 parse/0:   ingredient: {name: "1", type: 0}
-parse/0:   ingredient: {name: "//", type: 0}
-parse/0:   ingredient: {name: "0", type: 0}
-parse/0:   ingredient: {name: "-+", type: 0}
+parse/0:   ingredient: {name: "//", type: }
+parse/0:   ingredient: {name: "0", type: }
+parse/0:   ingredient: {name: "-+", type: }
 parse/0: instruction: 10
 parse/0:   ingredient: {name: "1", type: 0}
-parse/0:   ingredient: {name: "//", type: 0}
-parse/0:   ingredient: {name: "|", type: 0}
-parse/0:   ingredient: {name: "1", type: 0}
-parse/0:   ingredient: {name: "+-+", type: 0}
+parse/0:   ingredient: {name: "//", type: }
+parse/0:   ingredient: {name: "|", type: }
+parse/0:   ingredient: {name: "1", type: }
+parse/0:   ingredient: {name: "+-+", type: }
 parse/0: instruction: 10
 parse/0:   ingredient: {name: "-2", type: 0}
-parse/0:   ingredient: {name: "//", type: 0}
-parse/0:   ingredient: {name: "2", type: 0}
-parse/0:   ingredient: {name: "+-->+", type: 0}
-parse/0:   ingredient: {name: "|", type: 0}
+parse/0:   ingredient: {name: "//", type: }
+parse/0:   ingredient: {name: "2", type: }
+parse/0:   ingredient: {name: "+-->+", type: }
+parse/0:   ingredient: {name: "|", type: }
 run/0: instruction 0
 run/0: ingredient 0 is 1
 run/0: instruction 2
diff --git a/cpp/.traces/parse_multiple_types b/cpp/.traces/parse_multiple_types
new file mode 100644
index 00000000..319aad1f
--- /dev/null
+++ b/cpp/.traces/parse_multiple_types
@@ -0,0 +1,5 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "23", type: 0}
+parse/0:   ingredient: {name: "4", type: 1}
+parse/0:   product: {name: "1", type: 1}
+parse/0:   product: {name: "2", type: 2-1}
diff --git a/cpp/010vm b/cpp/010vm
index 342eeb9a..c5012c93 100644
--- a/cpp/010vm
+++ b/cpp/010vm
@@ -1,6 +1,5 @@
-// A program is a book of 'recipes' (functions)
-
 :(after "Types")
+// A program is a book of 'recipes' (functions)
 typedef int recipe_number;
 :(before "End Globals")
 unordered_map<string, recipe_number> Recipe_number;
@@ -74,9 +73,10 @@ void setup_types() {
   Type_number["literal"] = 0;
   Next_type_number = 1;
   // Mu Types.
-  int integer = Type_number["integer"] = 1;
+  int integer = Type_number["integer"] = Next_type_number++;
   Type[integer].size = 1;
-  Next_type_number++;
+  int address = Type_number["address"] = Next_type_number++;
+  Type[address].size = 1;
   int boolean = Type_number["boolean"] = Next_type_number++;
   Type[boolean].size = 1;
   // End Mu Types.
@@ -132,13 +132,25 @@ void setup_recipes() {
 
   // Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...
   reagent::reagent(string s) {
+//?     cout << s << '\n'; //? 1
     istringstream in(s);
     name = slurp_until(in, ':');
-    types.push_back(Type_number[slurp_until(in, '/')]);  // todo: multiple types
+    istringstream ts(slurp_until(in, '/'));
+    string t;
+    while (!(t = slurp_until(ts, ':')).empty()) {
+      types.push_back(Type_number[t]);
+    }
+//?     cout << types.size() << '\n'; //? 1
+    // todo: properties
   }
   string reagent::to_string() {
     ostringstream out;
-    out << "{name: \"" << name << "\", type: " << types[0] << "}";  // todo: properties
+    out << "{name: \"" << name << "\", type: ";
+    for (size_t i = 0; i < types.size(); ++i) {
+      out << types[i];
+      if (i < types.size()-1) out << "-";
+    }
+    out << "}";  // todo: properties
     return out.str();
   }
 
@@ -153,7 +165,3 @@ string slurp_until(istream& in, char delim) {
   }
   return out.str();
 }
-
-
-
-:(before "End Setup")
diff --git a/cpp/011load b/cpp/011load
index 0193eeac..4c019c1c 100644
--- a/cpp/011load
+++ b/cpp/011load
@@ -154,3 +154,13 @@ recipe main [
 +parse:   ingredient: {name: "4", type: 1}
 +parse:   product: {name: "1", type: 1}
 +parse:   product: {name: "2", type: 1}
+
+:(scenario parse_multiple_types)
+recipe main [
+  1:integer, 2:address:integer <- copy 23:literal, 4:integer
+]
++parse: instruction: 1
++parse:   ingredient: {name: "23", type: 0}
++parse:   ingredient: {name: "4", type: 1}
++parse:   product: {name: "1", type: 1}
++parse:   product: {name: "2", type: 2-1}
diff --git a/cpp/017record b/cpp/017record
index 359fd2bc..0626b7ad 100644
--- a/cpp/017record
+++ b/cpp/017record
@@ -52,7 +52,7 @@ case GET: {
   ostringstream s;
   s << src;
   reagent tmp(s.str());
-  tmp.types[0] = src_type;
+  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);
@@ -70,7 +70,7 @@ recipe main [
 +run: base address 12
 +run: ingredient 1 is 1
 +run: address to copy is 13
-+run: its type is 2
++run: its type is 3
 +mem: location 13 is 0
 +run: product 0 is 0
 +mem: storing in location 15
@@ -105,7 +105,7 @@ case GET_ADDRESS: {
 recipe main [
   12:integer <- copy 34:literal
   13:boolean <- copy 0:literal
-  15:integer <- get-address 12:integer-boolean, 1:offset  # todo: product is an address
+  15:address:integer <- get-address 12:integer-boolean, 1:offset
 ]
 +run: instruction 2
 +run: ingredient 0 is 12