about summary refs log tree commit diff stats
path: root/cpp/literate/010vm
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-18 10:49:46 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-18 10:49:46 -0800
commit36594a43e0503bef1a894320deb3182af74902dc (patch)
treefcbfe2e5fb8182f84f3f012a3a21ee1872586f95 /cpp/literate/010vm
parent5574fbaf794df7557fb6049e3721c4291556f3c1 (diff)
downloadmu-36594a43e0503bef1a894320deb3182af74902dc.tar.gz
779 - first scenario tested in literate C++ version
Diffstat (limited to 'cpp/literate/010vm')
-rw-r--r--cpp/literate/010vm34
1 files changed, 32 insertions, 2 deletions
diff --git a/cpp/literate/010vm b/cpp/literate/010vm
index 8d427c43..4ae5c16a 100644
--- a/cpp/literate/010vm
+++ b/cpp/literate/010vm
@@ -14,8 +14,6 @@ struct recipe {
   vector<instruction> step;
 };
 
-const int idle = 0;  // always the first entry in the recipe book
-
 :(before "struct recipe")
 // Each instruction is either of the form:
 //   product1, product2, product3, ... <- operation ingredient1, ingredient2, ingredient3, ...
@@ -53,6 +51,8 @@ struct property {
 :(before "End Globals")
 // Locations refer to a common 'memory'. Each location can store a number.
 unordered_map<int, int> Memory;
+:(before "End Setup")
+  Memory.clear();
 
 :(after "Types")
 // Types encode how the numbers stored in different parts of memory are
@@ -68,6 +68,16 @@ typedef int type_number;
 unordered_map<string, type_number> Type_number;
 unordered_map<type_number, type_info> Type;
 int Next_type_number = 1;
+:(code)
+void setup_types() {
+  Type.clear();  Type_number.clear();
+  Type_number["literal"] = 0;
+  Next_type_number = 1;
+  int integer = Type_number["integer"] = Next_type_number++;
+  Type[integer].size = 1;
+}
+:(before "End Setup")
+  setup_types();
 
 :(before "End Types")
 // You can construct arbitrary new types. Types are either 'records', containing
@@ -83,6 +93,22 @@ struct type_info {
   type_info() :size(0) {}
 };
 
+:(code)
+// It's all very well to construct recipes out of other recipes, but we need
+// to know how to do *something* out of the box. For the following
+// recipes there are only codes, no entries in the book, because mu just knows
+// what to do for them.
+void setup_recipes() {
+  Recipe.clear();  Recipe_number.clear();
+  Recipe_number["idle"] = 0;
+  Next_recipe_number = 1;
+  Recipe_number["copy"] = Next_recipe_number++;
+}
+:(before "End Types")
+const int idle = 0;  // always the first entry in the recipe book
+:(before "End Setup")
+  setup_recipes();
+
 
 
 :(code)
@@ -113,3 +139,7 @@ string slurp_until(istream& in, char delim) {
   }
   return out.str();
 }
+
+
+
+:(before "End Setup")