about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--030container.cc4
-rw-r--r--056recipe_header.cc11
-rw-r--r--058generic_container.cc19
-rw-r--r--059generic_recipe.cc1
4 files changed, 21 insertions, 14 deletions
diff --git a/030container.cc b/030container.cc
index 72ac7e73..d5527406 100644
--- a/030container.cc
+++ b/030container.cc
@@ -160,7 +160,7 @@ case GET: {
   // Update GET product in Check
   const reagent element = element_type(base, offset_value);
   if (!types_match(product, element)) {
-    raise_error << maybe(get(Recipe, r).name) << "'get' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'get' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << " but is " << debug_string(product.type) << '\n' << end();
     break;
   }
   break;
@@ -240,7 +240,7 @@ recipe main [
   14:number <- copy 36
   15:address:number <- get 12:point-number/raw, 1:offset
 ]
-+error: main: 'get' 1:offset (1) on point-number can't be saved in 15:address:number; type should be number
++error: main: 'get' 1:offset (1) on point-number can't be saved in 15:address:number; type should be number but is <address : <number : <>>>
 
 //:: To write to elements of containers, you need their address.
 
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 85fa1c1e..6c3f3ce8 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -151,13 +151,15 @@ void deduce_types_from_header(const recipe_ordinal r) {
   map<string, const type_tree*> header;
   for (long long int i = 0; i < SIZE(rr.ingredients); ++i) {
     header[rr.ingredients.at(i).name] = rr.ingredients.at(i).type;
+    trace(9993, "transform") << "type of " << rr.ingredients.at(i).name << " is " << debug_string(rr.ingredients.at(i).type) << end();
   }
   for (long long int i = 0; i < SIZE(rr.products); ++i) {
     header[rr.products.at(i).name] = rr.products.at(i).type;
+    trace(9993, "transform") << "type of " << rr.products.at(i).name << " is " << debug_string(rr.products.at(i).type) << end();
   }
   for (long long int i = 0; i < SIZE(rr.steps); ++i) {
     instruction& inst = rr.steps.at(i);
-    trace(9992, "transform") << inst.to_string() << end();
+    trace(9992, "transform") << "instruction: " << inst.to_string() << end();
     for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
       if (inst.ingredients.at(i).type) continue;
       if (header.find(inst.ingredients.at(i).name) == header.end()) {
@@ -168,6 +170,7 @@ void deduce_types_from_header(const recipe_ordinal r) {
       trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << debug_string(inst.ingredients.at(i).type) << end();
     }
     for (long long int i = 0; i < SIZE(inst.products); ++i) {
+      trace(9993, "transform") << "  product: " << debug_string(inst.products.at(i)) << end();
       if (inst.products.at(i).type) continue;
       if (header.find(inst.products.at(i).name) == header.end()) {
         raise << maybe(rr.name) << "unknown variable " << inst.products.at(i).name << " in '" << inst.to_string() << "'\n" << end();
@@ -233,7 +236,7 @@ recipe add2 x:number, y:number -> z:number [
   load-ingredients
   z <- add x, y
 ]
-+transform: reply z:number
++transform: instruction: reply z:number
 +mem: storing 8 in location 1
 
 :(after "Transform.push_back(insert_fragments)")
@@ -265,6 +268,6 @@ recipe add2 x:number, y:number -> z:number [
   z <- add x, y  # no type for z
   reply z
 ]
-+transform: reply z
--transform: reply z:number
++transform: instruction: reply z
+-transform: instruction: reply z:number
 +mem: storing 8 in location 1
diff --git a/058generic_container.cc b/058generic_container.cc
index 68258249..de09e6e7 100644
--- a/058generic_container.cc
+++ b/058generic_container.cc
@@ -145,7 +145,9 @@ recipe main [
 if (contains_type_ingredient(element)) {
   if (!canonized_base.type->right)
     raise_error << "illegal type '" << debug_string(canonized_base.type) << "' seems to be missing a type ingredient or three\n" << end();
-  replace_type_ingredients(element.type, canonized_base.type->right);
+  trace(9999, "transform") << " === before replace: " << debug_string(element.type) << end();
+  replace_type_ingredient(element.type, canonized_base.type->right);
+  trace(9999, "transform") << " === after replace: " << debug_string(element.type) << end();
 }
 
 :(code)
@@ -159,7 +161,7 @@ bool contains_type_ingredient(const type_tree* type) {
   return contains_type_ingredient(type->left) || contains_type_ingredient(type->right);
 }
 
-void replace_type_ingredients(type_tree* element_type, type_tree* callsite_type) {
+void replace_type_ingredient(type_tree* element_type, const type_tree* callsite_type) {
   if (!callsite_type) return;  // error but it's already been raised above
   if (!element_type) return;
   if (element_type->value >= START_TYPE_INGREDIENTS) {
@@ -167,18 +169,21 @@ void replace_type_ingredients(type_tree* element_type, type_tree* callsite_type)
       raise_error << "illegal type '" << debug_string(callsite_type) << "' seems to be missing a type ingredient or three\n" << end();
       return;
     }
-    element_type->value = nth_type(callsite_type, element_type->value-START_TYPE_INGREDIENTS);
+    const type_tree* replacement = nth_type(callsite_type, element_type->value-START_TYPE_INGREDIENTS);
+    element_type->value = replacement->value;
+    element_type->left = replacement->left ? new type_tree(*replacement->left) : NULL;
+    element_type->right = replacement->right ? new type_tree(*replacement->right) : NULL;
   }
-  replace_type_ingredients(element_type->right, callsite_type);
+  replace_type_ingredient(element_type->right, callsite_type);
 }
 
-type_ordinal nth_type(type_tree* base, long long int n) {
+const type_tree* nth_type(const type_tree* base, long long int n) {
   assert(n >= 0);
-  if (n == 0) return base->value;  // todo: base->left
+  if (n == 0) return base;
   return nth_type(base->right, n-1);
 }
 
-bool has_nth_type(type_tree* base, long long int n) {
+bool has_nth_type(const type_tree* base, long long int n) {
   assert(n >= 0);
   if (base == NULL) return false;
   if (n == 0) return true;
diff --git a/059generic_recipe.cc b/059generic_recipe.cc
index afdc960f..7d5f64f1 100644
--- a/059generic_recipe.cc
+++ b/059generic_recipe.cc
@@ -307,7 +307,6 @@ void replace_type_ingredients(string_tree* type, const map<string, const string_
     type->value = replacement->value;
     if (replacement->left) type->left = new string_tree(*replacement->left);
     if (replacement->right) type->right = new string_tree(*replacement->right);
-    trace(9993, "transform") << " ===> " << debug_string(type) << end();
   }
   replace_type_ingredients(type->left, mappings);
   replace_type_ingredients(type->right, mappings);