about summary refs log tree commit diff stats
path: root/023jump.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-25 14:19:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-25 17:14:58 -0700
commite46306432ddb75a89f69d92ccc175a23f0b72072 (patch)
tree48ed3828064f29cefaf14e3fe61d7dc02cac0e80 /023jump.cc
parente83602d3917eba137cd8fb37605076fff5a746b1 (diff)
downloadmu-e46306432ddb75a89f69d92ccc175a23f0b72072.tar.gz
1848 - core instructions now check for ingredients
Also standardized warnings.
Diffstat (limited to '023jump.cc')
-rw-r--r--023jump.cc40
1 files changed, 32 insertions, 8 deletions
diff --git a/023jump.cc b/023jump.cc
index edccf207..af713628 100644
--- a/023jump.cc
+++ b/023jump.cc
@@ -16,9 +16,15 @@ JUMP,
 Recipe_ordinal["jump"] = JUMP;
 :(before "End Primitive Recipe Implementations")
 case JUMP: {
+  if (SIZE(ingredients) != 1) {
+    raise << current_recipe_name() << ": 'jump' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(0))) {
+    raise << current_recipe_name() << ": first ingredient of 'jump' should be a label or offset, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
   assert(current_instruction().ingredients.at(0).initialized);
-  assert(SIZE(ingredients) == 1);
-  assert(scalar(ingredients.at(0)));
   current_step_index() += ingredients.at(0).at(0)+1;
   trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
   continue;  // skip rest of this instruction
@@ -45,14 +51,23 @@ JUMP_IF,
 Recipe_ordinal["jump-if"] = JUMP_IF;
 :(before "End Primitive Recipe Implementations")
 case JUMP_IF: {
+  if (SIZE(ingredients) != 2) {
+    raise << current_recipe_name() << ": 'jump-if' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(0))) {
+    raise << current_recipe_name() << ": 'jump-if' requires a boolean for its first ingredient, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(1))) {
+    raise << current_recipe_name() << ": 'jump-if' requires a label or offset for its second ingredient, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
   assert(current_instruction().ingredients.at(1).initialized);
-  assert(SIZE(ingredients) == 2);
-  assert(scalar(ingredients.at(0)));
   if (!ingredients.at(0).at(0)) {
     trace(Primitive_recipe_depth, "run") << "jump-if fell through" << end();
     break;
   }
-  assert(scalar(ingredients.at(1)));
   current_step_index() += ingredients.at(1).at(0)+1;
   trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
   continue;  // skip rest of this instruction
@@ -84,14 +99,23 @@ JUMP_UNLESS,
 Recipe_ordinal["jump-unless"] = JUMP_UNLESS;
 :(before "End Primitive Recipe Implementations")
 case JUMP_UNLESS: {
+  if (SIZE(ingredients) != 2) {
+    raise << current_recipe_name() << ": 'jump-unless' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(0))) {
+    raise << current_recipe_name() << ": 'jump-unless' requires a boolean for its first ingredient, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(1))) {
+    raise << current_recipe_name() << ": 'jump-unless' requires a label or offset for its second ingredient, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
+    break;
+  }
   assert(current_instruction().ingredients.at(1).initialized);
-  assert(SIZE(ingredients) == 2);
-  assert(scalar(ingredients.at(0)));
   if (ingredients.at(0).at(0)) {
     trace(Primitive_recipe_depth, "run") << "jump-unless fell through" << end();
     break;
   }
-  assert(scalar(ingredients.at(1)));
   current_step_index() += ingredients.at(1).at(0)+1;
   trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
   continue;  // skip rest of this instruction