From 9542bb112419d575190a72baf7f964c3e32df223 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 25 Jul 2015 22:15:51 -0700 Subject: 1853 --- html/023jump.cc.html | 72 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 23 deletions(-) (limited to 'html/023jump.cc.html') diff --git a/html/023jump.cc.html b/html/023jump.cc.html index b72a1341..16a89563 100644 --- a/html/023jump.cc.html +++ b/html/023jump.cc.html @@ -13,14 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceContains { color: #008000; } -.Constant { color: #00a0a0; } .traceAbsent { color: #c00000; } +.Constant { color: #00a0a0; } +.cSpecial { color: #008000; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.Special { color: #ff6060; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } -.Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } +.traceContains { color: #008000; } --> @@ -49,12 +51,18 @@ JUMP, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump"] = JUMP; :(before "End Primitive Recipe Implementations") -case JUMP: { +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(); + trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end(); continue; // skip rest of this instruction } @@ -78,23 +86,32 @@ JUMP_IF, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump-if"] = JUMP_IF; :(before "End Primitive Recipe Implementations") -case JUMP_IF: { +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"; + 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(); + trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end(); continue; // skip rest of this instruction } :(scenario jump_if) recipe main [ - jump-if 999:literal, 1:offset + jump-if 999:literal, 1:offset 123:number <- copy 1:literal ] +run: jump-if 999:literal, 1:offset @@ -104,7 +121,7 @@ recipe main [ :(scenario jump_if_fallthrough) recipe main [ - jump-if 0:literal, 1:offset + jump-if 0:literal, 1:offset 123:number <- copy 1:literal ] +run: jump-if 0:literal, 1:offset @@ -117,17 +134,26 @@ JUMP_UNLESS, :(before "End Primitive Recipe Numbers") Recipe_ordinal["jump-unless"] = JUMP_UNLESS; :(before "End Primitive Recipe Implementations") -case JUMP_UNLESS: { +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"; + 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(); + trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end(); continue; // skip rest of this instruction } -- cgit 1.4.1-2-gfad0