From d855b0a0a5012c583a35dee57d03b66de895e164 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 30 Sep 2015 02:18:05 -0700 Subject: 2223 --- 021check_instruction.cc | 2 +- 024jump.cc | 50 ++++++++++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/021check_instruction.cc b/021check_instruction.cc index a9ed55b2..8f12b7ca 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -109,7 +109,7 @@ bool is_mu_number(reagent r) { bool is_mu_scalar(reagent r) { if (is_literal(r)) - return r.properties.at(0).second.at(0) != "literal-string"; + return r.properties.at(0).second.empty() || r.properties.at(0).second.at(0) != "literal-string"; if (is_mu_array(r)) return false; return size_of(r) == 1; } diff --git a/024jump.cc b/024jump.cc index 925906de..dabe33bb 100644 --- a/024jump.cc +++ b/024jump.cc @@ -13,16 +13,20 @@ recipe main [ JUMP, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump"] = JUMP; -:(before "End Primitive Recipe Implementations") +:(before "End Primitive Recipe Checks") case JUMP: { - if (SIZE(ingredients) != 1) { - raise << current_recipe_name() << ": 'jump' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); + if (SIZE(inst.ingredients) != 1) { + raise << Recipe[r].name << ": 'jump' requires exactly one ingredient, but got " << inst.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(); + if (!is_mu_scalar(inst.ingredients.at(0))) { + raise << Recipe[r].name << ": first ingredient of 'jump' should be a label or offset, but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case JUMP: { assert(current_instruction().ingredients.at(0).initialized); current_step_index() += ingredients.at(0).at(0)+1; trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end(); @@ -48,20 +52,24 @@ recipe main [ JUMP_IF, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump-if"] = JUMP_IF; -:(before "End Primitive Recipe Implementations") +:(before "End Primitive Recipe Checks") 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(); + if (SIZE(inst.ingredients) != 2) { + raise << Recipe[r].name << ": 'jump-if' requires exactly two ingredients, but got " << inst.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(); + if (!is_mu_scalar(inst.ingredients.at(0))) { + raise << Recipe[r].name << ": 'jump-if' requires a boolean for its first ingredient, but got " << inst.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(); + if (!is_mu_scalar(inst.ingredients.at(1))) { + raise << Recipe[r].name << ": 'jump-if' requires a label or offset for its second ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case JUMP_IF: { assert(current_instruction().ingredients.at(1).initialized); if (!ingredients.at(0).at(0)) { trace(Primitive_recipe_depth, "run") << "jump-if fell through" << end(); @@ -96,20 +104,24 @@ recipe main [ JUMP_UNLESS, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump-unless"] = JUMP_UNLESS; -:(before "End Primitive Recipe Implementations") +:(before "End Primitive Recipe Checks") 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(); + if (SIZE(inst.ingredients) != 2) { + raise << Recipe[r].name << ": 'jump-unless' requires exactly two ingredients, but got " << inst.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(); + if (!is_mu_scalar(inst.ingredients.at(0))) { + raise << Recipe[r].name << ": 'jump-unless' requires a boolean for its first ingredient, but got " << inst.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(); + if (!is_mu_scalar(inst.ingredients.at(1))) { + raise << Recipe[r].name << ": 'jump-unless' requires a label or offset for its second ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case JUMP_UNLESS: { assert(current_instruction().ingredients.at(1).initialized); if (ingredients.at(0).at(0)) { trace(Primitive_recipe_depth, "run") << "jump-unless fell through" << end(); -- cgit 1.4.1-2-gfad0