about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-26 21:50:54 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-26 21:50:54 -0800
commit1e38eee5db71d551ee2dbddb35d187489e372c8c (patch)
tree307af6dbbcb7c890f162b3102ac71ffad99a4e77
parent947f06fb5569007a5a3c444683794427c72cef52 (diff)
downloadmu-1e38eee5db71d551ee2dbddb35d187489e372c8c.tar.gz
2718 - stop crashing on unknown space
I'm going to stop wasting precious first-line characters on 'bugfix:'.
It's going to be all bugfixes for a while I think.
-rw-r--r--042name.cc18
-rw-r--r--043space.cc1
-rw-r--r--045closure_name.cc14
3 files changed, 29 insertions, 4 deletions
diff --git a/042name.cc b/042name.cc
index e618ac89..f7eba9e0 100644
--- a/042name.cc
+++ b/042name.cc
@@ -51,7 +51,14 @@ void transform_names(const recipe_ordinal r) {
       if (!already_transformed(inst.ingredients.at(in), names)) {
         raise << maybe(caller.name) << "use before set: " << inst.ingredients.at(in).name << '\n' << end();
       }
-      inst.ingredients.at(in).set_value(lookup_name(inst.ingredients.at(in), r));
+      long long int v = lookup_name(inst.ingredients.at(in), r);
+      if (v >= 0) {
+        inst.ingredients.at(in).set_value(v);
+      }
+      else {
+        raise << maybe(caller.name) << "can't find a place to store " << inst.ingredients.at(in).name << '\n' << end();
+        return;
+      }
     }
     for (long long int out = 0; out < SIZE(inst.products); ++out) {
       if (is_disqualified(inst.products.at(out), inst, caller.name)) continue;
@@ -63,7 +70,14 @@ void transform_names(const recipe_ordinal r) {
         names[inst.products.at(out).name] = curr_idx;
         curr_idx += size_of(inst.products.at(out));
       }
-      inst.products.at(out).set_value(lookup_name(inst.products.at(out), r));
+      long long int v = lookup_name(inst.products.at(out), r);
+      if (v >= 0) {
+        inst.products.at(out).set_value(v);
+      }
+      else {
+        raise << maybe(caller.name) << "can't find a place to store " << inst.products.at(out).name << '\n' << end();
+        return;
+      }
     }
   }
   if (names_used && numeric_locations_used)
diff --git a/043space.cc b/043space.cc
index 5bf7b1a4..9ca747b7 100644
--- a/043space.cc
+++ b/043space.cc
@@ -69,6 +69,7 @@ long long int space_base(const reagent& x) {
 }
 
 long long int address(long long int offset, long long int base) {
+  assert(offset >= 0);
   if (base == 0) return offset;  // raw
   long long int size = get_or_insert(Memory, base);
   if (offset >= size) {
diff --git a/045closure_name.cc b/045closure_name.cc
index 2b80e154..368377fd 100644
--- a/045closure_name.cc
+++ b/045closure_name.cc
@@ -101,6 +101,7 @@ long long int lookup_name(const reagent& x, const recipe_ordinal default_recipe)
   long long int n = to_integer(p->value);
   assert(n >= 0);
   recipe_ordinal surrounding_recipe = lookup_surrounding_recipe(default_recipe, n);
+  if (surrounding_recipe == -1) return -1;
   set<recipe_ordinal> done;
   vector<recipe_ordinal> path;
   return lookup_name(x, surrounding_recipe, done, path);
@@ -116,7 +117,7 @@ long long int lookup_name(const reagent& x, const recipe_ordinal r, set<recipe_o
       raise << path.at(i-1) << " requires computing names of " << path.at(i) << '\n' << end();
     }
     raise << path.at(SIZE(path)-1) << " requires computing names of " << r << "..ad infinitum\n" << end();
-    return 0;
+    return -1;
   }
   done.insert(r);
   path.push_back(r);
@@ -129,7 +130,7 @@ recipe_ordinal lookup_surrounding_recipe(const recipe_ordinal r, long long int n
   if (n == 0) return r;
   if (!contains_key(Surrounding_space, r)) {
     raise << "don't know surrounding recipe of " << get(Recipe, r).name << '\n' << end();
-    return 0;
+    return -1;
   }
   assert(contains_key(Surrounding_space, r));
   return lookup_surrounding_recipe(get(Surrounding_space, r), n-1);
@@ -148,3 +149,12 @@ bool already_transformed(const reagent& r, const map<string, long long int>& nam
   }
   return contains_key(names, r.name);
 }
+
+:(scenario missing_surrounding_space)
+% Hide_errors = true;
+recipe f [
+  local-scope
+  x:number/space:1 <- copy 34
+]
++error: don't know surrounding recipe of f
++error: f: can't find a place to store x