about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-01 18:14:18 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-01 18:14:18 -0800
commited09f7384ad87e87e1035b948c7f88841570f292 (patch)
tree0a44bd97bca589f596ac6e816722945db8ffc139
parent6d79cc137b045ace341f666a67054bdeddef992e (diff)
downloadmu-ed09f7384ad87e87e1035b948c7f88841570f292.tar.gz
2339 - don't let dump_types modify Type
-rw-r--r--010vm.cc11
-rw-r--r--048check_type_by_name.cc5
2 files changed, 13 insertions, 3 deletions
diff --git a/010vm.cc b/010vm.cc
index bdf4ec17..906a2cd1 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -392,7 +392,7 @@ string dump_types(const reagent& x) {
 void dump_types(type_tree* type, ostream& out) {
   // abbreviate a single-node tree to just its contents
   if (!type->left && !type->right) {
-    out << Type[type->value].name;
+    dump_type_name(type->value, out);
     return;
   }
   dump_types_tree(type, out);
@@ -403,7 +403,7 @@ void dump_types_tree(type_tree* type, ostream& out) {
   if (type->left)
     dump_types_tree(type->left, out);
   else
-    out << Type[type->value].name;
+    dump_type_name(type->value, out);
   out << " : ";
   if (type->right)
     dump_types_tree(type->right, out);
@@ -412,6 +412,13 @@ void dump_types_tree(type_tree* type, ostream& out) {
   out << ">";
 }
 
+void dump_type_name(recipe_ordinal type, ostream& out) {
+  if (Type.find(type) != Type.end())
+    out << Type[type].name;
+  else
+    out << "?";
+}
+
 string instruction::to_string() const {
   if (is_label) return label;
   ostringstream out;
diff --git a/048check_type_by_name.cc b/048check_type_by_name.cc
index fcefbaf6..e526644a 100644
--- a/048check_type_by_name.cc
+++ b/048check_type_by_name.cc
@@ -19,6 +19,7 @@ recipe main [
 
 :(code)
 void check_types_by_name(const recipe_ordinal r) {
+  trace(9991, "transform") << "--- deduce types for recipe " << Recipe[r].name << end();
   map<string, type_tree*> type;
   for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) {
     instruction& inst = Recipe[r].steps.at(i);
@@ -39,8 +40,10 @@ void check_type(map<string, type_tree*>& type, const reagent& x, const recipe_or
   // if you use raw locations you're probably doing something unsafe
   if (is_integer(x.name)) return;
   if (!x.type) return;  // will throw a more precise error elsewhere
-  if (type.find(x.name) == type.end())
+  if (type.find(x.name) == type.end()) {
+    trace(9992, "transform") << x.name << " => " << dump_types(x) << end();
     type[x.name] = x.type;
+  }
   if (!types_match(type[x.name], x.type))
     raise_error << maybe(Recipe[r].name) << x.name << " used with multiple types\n" << end();
 }