about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-29 13:01:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-29 13:01:04 -0700
commitdf40cb6e4d9d274b618682c315545d5c55508fa5 (patch)
tree2500f56dae28518c4d2f2cf29b90259d4d21c23f
parent30277d2e370210b17099387abf03e75199340e98 (diff)
downloadmu-df40cb6e4d9d274b618682c315545d5c55508fa5.tar.gz
2316 - preparing for static dispatch
-rw-r--r--010vm.cc5
-rw-r--r--011load.cc29
-rw-r--r--012transform.cc3
-rw-r--r--056recipe_header.cc7
4 files changed, 28 insertions, 16 deletions
diff --git a/010vm.cc b/010vm.cc
index 08da15a3..21dd28d0 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -20,6 +20,7 @@ struct recipe {
   string name;
   vector<instruction> steps;
   // End recipe Fields
+  recipe();
 };
 
 :(before "struct recipe")
@@ -219,6 +220,10 @@ Next_recipe_ordinal = 1000;  // consistent new numbers for each test
 //:: Helpers
 
 :(code)
+recipe::recipe() {
+  // End recipe Constructor
+}
+
 instruction::instruction() :is_label(false), operation(IDLE) {
   // End instruction Constructor
 }
diff --git a/011load.cc b/011load.cc
index 93d30c22..2ac517c5 100644
--- a/011load.cc
+++ b/011load.cc
@@ -41,25 +41,26 @@ vector<recipe_ordinal> load(istream& in) {
 }
 
 long long int slurp_recipe(istream& in) {
-  string recipe_name = next_word(in);
-  if (recipe_name.empty())
-    raise_error << "empty recipe name\n" << end();
-  if (Recipe_ordinal.find(recipe_name) == Recipe_ordinal.end()) {
-    Recipe_ordinal[recipe_name] = Next_recipe_ordinal++;
+  recipe result;
+  result.name = next_word(in);
+  // End recipe Refinements
+  if (result.name.empty())
+    raise_error << "empty result.name\n" << end();
+  trace(9991, "parse") << "--- defining " << result.name << end();
+  if (Recipe_ordinal.find(result.name) == Recipe_ordinal.end()) {
+    Recipe_ordinal[result.name] = Next_recipe_ordinal++;
   }
-  trace(9991, "parse") << "--- defining " << recipe_name << end();
-  if (Recipe.find(Recipe_ordinal[recipe_name]) != Recipe.end()) {
+  if (Recipe.find(Recipe_ordinal[result.name]) != Recipe.end()) {
     trace(9991, "parse") << "already exists" << end();
-    if (warn_on_redefine(recipe_name))
-      raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end();
-    Recipe.erase(Recipe_ordinal[recipe_name]);
+    if (warn_on_redefine(result.name))
+      raise << "redefining recipe " << Recipe[Recipe_ordinal[result.name]].name << "\n" << end();
+    Recipe.erase(Recipe_ordinal[result.name]);
   }
-  recipe& result = Recipe[Recipe_ordinal[recipe_name]];
-  result.name = recipe_name;
   slurp_body(in, result);
+  Recipe[Recipe_ordinal[result.name]] = result;
   // track added recipes because we may need to undo them in tests; see below
-  recently_added_recipes.push_back(Recipe_ordinal[recipe_name]);
-  return Recipe_ordinal[recipe_name];
+  recently_added_recipes.push_back(Recipe_ordinal[result.name]);
+  return Recipe_ordinal[result.name];
 }
 
 void slurp_body(istream& in, recipe& result) {
diff --git a/012transform.cc b/012transform.cc
index 72f0cb0b..4152339c 100644
--- a/012transform.cc
+++ b/012transform.cc
@@ -5,7 +5,8 @@
 
 :(before "End recipe Fields")
 long long int transformed_until;
-  recipe() :transformed_until(-1) {}
+:(before "End recipe Constructor")
+transformed_until = -1;
 
 :(before "End Types")
 typedef void (*transform_fn)(recipe_ordinal);
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 0c09cb75..bba301b1 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -16,10 +16,13 @@ recipe add2 x:number, y:number -> z:number [
 //: When loading recipes save any header.
 
 :(before "End recipe Fields")
+bool has_header;
 vector<reagent> ingredients;
 vector<reagent> products;
+:(before "End recipe Constructor")
+has_header = false;
 
-:(before "slurp_body(in, result);" following "long long int slurp_recipe(istream& in)")
+:(before "End recipe Refinements")
 skip_whitespace(in);
 if (in.peek() != '[') {
   trace(9999, "parse") << "recipe has a header; parsing";
@@ -28,6 +31,7 @@ if (in.peek() != '[') {
 
 :(code)
 void load_recipe_header(istream& in, recipe& result) {
+  result.has_header = true;
   while (in.peek() != '[') {
     string s = next_word(in);
     if (s == "->") break;
@@ -41,6 +45,7 @@ void load_recipe_header(istream& in, recipe& result) {
     trace(9999, "parse") << "header product: " << result.products.back().original_string << end();
     skip_whitespace(in);
   }
+  // End Load Recipe Header(result)
 }
 
 //: Now rewrite 'load-ingredients' to instructions to create all reagents in