From 1e38eee5db71d551ee2dbddb35d187489e372c8c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 26 Feb 2016 21:50:54 -0800 Subject: 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. --- 042name.cc | 18 ++++++++++++++++-- 043space.cc | 1 + 045closure_name.cc | 14 ++++++++++++-- 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 done; vector 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& 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 -- cgit 1.4.1-2-gfad0