about summary refs log tree commit diff stats
path: root/011load.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-21 20:30:02 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-21 20:40:06 -0800
commitc4e143d6ea0635cdb164cec1c62afd7461e605ad (patch)
tree06fbb672ce95f1d5152c113cdb40685148b57d0c /011load.cc
parentf22250a174d5ad5abf8bf99ad140ced52563aee2 (diff)
downloadmu-c4e143d6ea0635cdb164cec1c62afd7461e605ad.tar.gz
2681 - drop reagent types from reagent properties
All my attempts at staging this change failed with this humongous commit
that took all day and involved debugging three monstrous bugs. Two of
the bugs had to do with forgetting to check the type name in the
implementation of shape-shifting recipes. Bug #2 in particular would
cause core tests in layer 59 to fail -- only when I loaded up edit/! It
got me to just hack directly on mu.cc until I figured out the cause
(snapshot saved in mu.cc.modified). The problem turned out to be that I
accidentally saved a type ingredient in the Type table during
specialization. Now I know that that can be very bad.

I've checked the traces for any stray type numbers (rather than names).

I also found what might be a bug from last November (labeled TODO), but
we'll verify after this commit.
Diffstat (limited to '011load.cc')
-rw-r--r--011load.cc77
1 files changed, 35 insertions, 42 deletions
diff --git a/011load.cc b/011load.cc
index 532eb417..f3fb8793 100644
--- a/011load.cc
+++ b/011load.cc
@@ -6,8 +6,8 @@ recipe main [
   1:number <- copy 23
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 
 :(code)
 vector<recipe_ordinal> load(string form) {
@@ -49,9 +49,8 @@ long long int slurp_recipe(istream& in) {
   if (result.name.empty())
     raise_error << "empty result.name\n" << end();
   trace(9991, "parse") << "--- defining " << result.name << end();
-  if (!contains_key(Recipe_ordinal, result.name)) {
+  if (!contains_key(Recipe_ordinal, result.name))
     put(Recipe_ordinal, result.name, Next_recipe_ordinal++);
-  }
   if (Recipe.find(get(Recipe_ordinal, result.name)) != Recipe.end()) {
     trace(9991, "parse") << "already exists" << end();
     if (warn_on_redefine(result.name))
@@ -103,9 +102,8 @@ bool next_instruction(istream& in, instruction* curr) {
     skip_whitespace_but_not_newline(in);
   }
   skip_whitespace_and_comments(in);
-  if (SIZE(words) == 1 && words.at(0) == "]") {
+  if (SIZE(words) == 1 && words.at(0) == "]")
     return false;  // end of recipe
-  }
 
   if (SIZE(words) == 1 && !isalnum(words.at(0).at(0)) && words.at(0).at(0) != '$') {
     curr->is_label = true;
@@ -120,9 +118,8 @@ bool next_instruction(istream& in, instruction* curr) {
 
   vector<string>::iterator p = words.begin();
   if (find(words.begin(), words.end(), "<-") != words.end()) {
-    for (; *p != "<-"; ++p) {
+    for (; *p != "<-"; ++p)
       curr->products.push_back(reagent(*p));
-    }
     ++p;  // skip <-
   }
 
@@ -133,18 +130,15 @@ bool next_instruction(istream& in, instruction* curr) {
   curr->old_name = curr->name = *p;  p++;
   // curr->operation will be set in a later layer
 
-  for (; p != words.end(); ++p) {
+  for (; p != words.end(); ++p)
     curr->ingredients.push_back(reagent(*p));
-  }
 
   trace(9993, "parse") << "instruction: " << curr->name << end();
   trace(9993, "parse") << "  number of ingredients: " << SIZE(curr->ingredients) << end();
-  for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p) {
+  for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p)
     trace(9993, "parse") << "  ingredient: " << to_string(*p) << end();
-  }
-  for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p) {
+  for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p)
     trace(9993, "parse") << "  product: " << to_string(*p) << end();
-  }
   if (!has_data(in)) {
     raise_error << "9: unbalanced '[' for recipe\n" << end();
     return false;
@@ -228,9 +222,8 @@ bool warn_on_redefine(const string& recipe_name) {
 void show_rest_of_stream(istream& in) {
   cerr << '^';
   char c;
-  while (in >> c) {
+  while (in >> c)
     cerr << c;
-  }
   cerr << "$\n";
   exit(0);
 }
@@ -261,8 +254,8 @@ recipe main [
   1:number <- copy 23
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 
 :(scenario parse_comment_amongst_instruction)
 recipe main [
@@ -270,8 +263,8 @@ recipe main [
   1:number <- copy 23
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 
 :(scenario parse_comment_amongst_instruction_2)
 recipe main [
@@ -280,8 +273,8 @@ recipe main [
   # comment
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 
 :(scenario parse_comment_amongst_instruction_3)
 recipe main [
@@ -290,19 +283,19 @@ recipe main [
   2:number <- copy 23
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"2": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 2: "number"
 
 :(scenario parse_comment_after_instruction)
 recipe main [
   1:number <- copy 23  # comment
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
 
 :(scenario parse_label)
 recipe main [
@@ -321,43 +314,43 @@ recipe main [
   1:number <- copy 23/foo:bar:baz
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal", "foo": ("bar" "baz")}
-+parse:   product: {"1": "number"}
++parse:   ingredient: 23: "literal", {"foo": ("bar" "baz")}
++parse:   product: 1: "number"
 
 :(scenario parse_multiple_products)
 recipe main [
   1:number, 2:number <- copy 23
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   product: {"1": "number"}
-+parse:   product: {"2": "number"}
++parse:   ingredient: 23: "literal"
++parse:   product: 1: "number"
++parse:   product: 2: "number"
 
 :(scenario parse_multiple_ingredients)
 recipe main [
   1:number, 2:number <- copy 23, 4:number
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   ingredient: {"4": "number"}
-+parse:   product: {"1": "number"}
-+parse:   product: {"2": "number"}
++parse:   ingredient: 23: "literal"
++parse:   ingredient: 4: "number"
++parse:   product: 1: "number"
++parse:   product: 2: "number"
 
 :(scenario parse_multiple_types)
 recipe main [
   1:number, 2:address:number <- copy 23, 4:number
 ]
 +parse: instruction: copy
-+parse:   ingredient: {"23": "literal"}
-+parse:   ingredient: {"4": "number"}
-+parse:   product: {"1": "number"}
-+parse:   product: {"2": ("address" "number")}
++parse:   ingredient: 23: "literal"
++parse:   ingredient: 4: "number"
++parse:   product: 1: "number"
++parse:   product: 2: ("address" "number")
 
 :(scenario parse_properties)
 recipe main [
   1:address:number/lookup <- copy 23
 ]
-+parse:   product: {"1": ("address" "number"), "lookup": ()}
++parse:   product: 1: ("address" "number"), {"lookup": ()}
 
 //: this test we can't represent with a scenario
 :(code)