about summary refs log tree commit diff stats
path: root/cpp/010vm
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 /cpp/010vm
parent6eec184e408fdc70497edabd59415cf14e394bcf (diff)
downloadmu-f02842a919823199a1fa41c0a244c3ce3409299d.tar.gz
804 - reagent can have multiple types
Diffstat (limited to 'cpp/010vm')
-rw-r--r--cpp/010vm28
1 files changed, 18 insertions, 10 deletions
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")