about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-13 16:32:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-13 16:32:36 -0700
commit1ad3fe9e6134353362c9a1318b4ba52d3ecc0d75 (patch)
treedf349dea704fca028c8c29c87d6f34f59b706671
parentdae2fa9688ce7b61ee2a46c0b616543ddbecd889 (diff)
downloadmu-1ad3fe9e6134353362c9a1318b4ba52d3ecc0d75.tar.gz
1988 - handle reagents without types
This can happen if 'canonize' fails. Make sure it doesn't kill mu.

Thanks Caleb Couch.
-rw-r--r--030container.cc8
-rw-r--r--031address.cc2
-rw-r--r--032array.cc6
-rw-r--r--033exclusive_container.cc3
-rw-r--r--043new.cc2
5 files changed, 10 insertions, 11 deletions
diff --git a/030container.cc b/030container.cc
index 5bc81a5f..ac198929 100644
--- a/030container.cc
+++ b/030container.cc
@@ -134,11 +134,11 @@ case GET: {
     raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
     break;
   }
-  type_ordinal base_type = base.types.at(0);
-  if (Type[base_type].kind != container) {
+  if (base.types.empty() || Type[base.types.at(0)].kind != container) {
     raise << current_recipe_name () << ": first ingredient of 'get' should be a container, but got " << base.original_string << '\n' << end();
     break;
   }
+  type_ordinal base_type = base.types.at(0);
   if (!is_literal(current_instruction().ingredients.at(1))) {
     raise << current_recipe_name() << ": second ingredient of 'get' should have type 'offset', but got " << current_instruction().ingredients.at(1).original_string << '\n' << end();
     break;
@@ -214,11 +214,11 @@ case GET_ADDRESS: {
     raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
     break;
   }
-  type_ordinal base_type = base.types.at(0);
-  if (Type[base_type].kind != container) {
+  if (base.types.empty() || Type[base.types.at(0)].kind != container) {
     raise << current_recipe_name () << ": first ingredient of 'get-address' should be a container, but got " << base.original_string << '\n' << end();
     break;
   }
+  type_ordinal base_type = base.types.at(0);
   if (!is_literal(current_instruction().ingredients.at(1))) {
     raise << current_recipe_name() << ": second ingredient of 'get-address' should have type 'offset', but got " << current_instruction().ingredients.at(1).original_string << '\n' << end();
     break;
diff --git a/031address.cc b/031address.cc
index 94c23210..f0657b98 100644
--- a/031address.cc
+++ b/031address.cc
@@ -57,7 +57,7 @@ reagent lookup_memory(reagent x) {
 //?   cout << "lookup_memory: " << x.to_string() << "\n"; //? 2
   static const type_ordinal ADDRESS = Type_ordinal["address"];
   reagent result;
-  if (x.types.at(0) != ADDRESS) {
+  if (x.types.empty() || x.types.at(0) != ADDRESS) {
     raise << current_recipe_name() << ": tried to /lookup " << x.original_string << " but it isn't an address\n" << end();
     return result;
   }
diff --git a/032array.cc b/032array.cc
index bf51382d..412f6878 100644
--- a/032array.cc
+++ b/032array.cc
@@ -94,7 +94,7 @@ case INDEX: {
     break;
   }
   reagent base = canonize(current_instruction().ingredients.at(0));
-  if (base.types.at(0) != Type_ordinal["array"]) {
+  if (!is_mu_array(base)) {
     raise << current_recipe_name () << ": 'index' on a non-array " << base.original_string << '\n' << end();
     break;
   }
@@ -189,7 +189,7 @@ case INDEX_ADDRESS: {
     break;
   }
   reagent base = canonize(current_instruction().ingredients.at(0));
-  if (base.types.at(0) != Type_ordinal["array"]) {
+  if (!is_mu_array(base)) {
     raise << current_recipe_name () << ": 'index-address' on a non-array " << base.original_string << '\n' << end();
     break;
   }
@@ -264,7 +264,7 @@ case LENGTH: {
     break;
   }
   reagent x = canonize(current_instruction().ingredients.at(0));
-  if (x.types.at(0) != Type_ordinal["array"]) {
+  if (!is_mu_array(x)) {
     raise << "tried to calculate length of non-array " << x.original_string << '\n' << end();
     break;
   }
diff --git a/033exclusive_container.cc b/033exclusive_container.cc
index e2f520f8..42993231 100644
--- a/033exclusive_container.cc
+++ b/033exclusive_container.cc
@@ -93,8 +93,7 @@ case MAYBE_CONVERT: {
     raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
     break;
   }
-  type_ordinal base_type = base.types.at(0);
-  if (Type[base_type].kind != exclusive_container) {
+  if (base.types.empty() || Type[base.types.at(0)].kind != exclusive_container) {
     raise << current_recipe_name () << ": first ingredient of 'maybe-convert' should be an exclusive-container, but got " << base.original_string << '\n' << end();
     break;
   }
diff --git a/043new.cc b/043new.cc
index 74083660..64f6fb57 100644
--- a/043new.cc
+++ b/043new.cc
@@ -222,7 +222,7 @@ case ABANDON: {
   }
   long long int address = ingredients.at(0).at(0);
   reagent types = canonize(current_instruction().ingredients.at(0));
-  if (types.types.at(0) != Type_ordinal["address"]) {
+  if (types.types.empty() || types.types.at(0) != Type_ordinal["address"]) {
     raise << current_recipe_name() << ": first ingredient of 'abandon' should be an address, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
     break;
   }