2015-04-18 14:50:51 +00:00
|
|
|
//: Jump primitives
|
2015-04-17 18:22:59 +00:00
|
|
|
|
2015-05-17 07:52:23 +00:00
|
|
|
:(scenario jump_can_skip_instructions)
|
2015-06-04 01:00:11 +00:00
|
|
|
#? % Trace_stream->dump_layer = "all"; #? 1
|
2015-05-17 07:52:23 +00:00
|
|
|
recipe main [
|
|
|
|
jump 1:offset
|
|
|
|
1:number <- copy 1:literal
|
|
|
|
]
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump 1:offset
|
|
|
|
-run: 1:number <- copy 1:literal
|
2015-05-17 07:52:23 +00:00
|
|
|
-mem: storing 1 in location 1
|
|
|
|
|
2015-04-17 17:31:17 +00:00
|
|
|
:(before "End Primitive Recipe Declarations")
|
|
|
|
JUMP,
|
2015-02-20 01:28:25 +00:00
|
|
|
:(before "End Primitive Recipe Numbers")
|
2015-07-04 16:40:50 +00:00
|
|
|
Recipe_ordinal["jump"] = JUMP;
|
2015-02-20 01:28:25 +00:00
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP: {
|
2015-05-10 15:34:12 +00:00
|
|
|
assert(current_instruction().ingredients.at(0).initialized);
|
2015-05-17 09:22:41 +00:00
|
|
|
assert(SIZE(ingredients) == 1);
|
|
|
|
assert(scalar(ingredients.at(0)));
|
2015-06-04 01:00:11 +00:00
|
|
|
current_step_index() += ingredients.at(0).at(0)+1;
|
2015-07-25 07:02:20 +00:00
|
|
|
trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
|
2015-06-04 01:00:11 +00:00
|
|
|
continue; // skip rest of this instruction
|
2015-02-20 01:28:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 07:52:23 +00:00
|
|
|
//: special type to designate jump targets
|
|
|
|
:(before "End Mu Types Initialization")
|
2015-07-04 16:40:50 +00:00
|
|
|
Type_ordinal["offset"] = 0;
|
2015-02-20 01:28:25 +00:00
|
|
|
|
2015-04-24 17:19:03 +00:00
|
|
|
:(scenario jump_backward)
|
2015-02-20 01:28:25 +00:00
|
|
|
recipe main [
|
2015-03-17 05:47:28 +00:00
|
|
|
jump 1:offset # 0 -+
|
2015-05-21 19:36:59 +00:00
|
|
|
jump 3:offset # | +-+ 1
|
2015-03-17 05:47:28 +00:00
|
|
|
# \/ /\ |
|
|
|
|
jump -2:offset # 2 +-->+ |
|
|
|
|
] # \/ 3
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump 1:offset
|
|
|
|
+run: jump -2:offset
|
|
|
|
+run: jump 3:offset
|
2015-02-20 02:25:25 +00:00
|
|
|
|
2015-04-17 17:31:17 +00:00
|
|
|
:(before "End Primitive Recipe Declarations")
|
|
|
|
JUMP_IF,
|
2015-02-20 02:25:25 +00:00
|
|
|
:(before "End Primitive Recipe Numbers")
|
2015-07-04 16:40:50 +00:00
|
|
|
Recipe_ordinal["jump-if"] = JUMP_IF;
|
2015-02-20 02:25:25 +00:00
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP_IF: {
|
2015-05-10 15:34:12 +00:00
|
|
|
assert(current_instruction().ingredients.at(1).initialized);
|
2015-05-17 09:22:41 +00:00
|
|
|
assert(SIZE(ingredients) == 2);
|
|
|
|
assert(scalar(ingredients.at(0)));
|
2015-05-07 22:06:53 +00:00
|
|
|
if (!ingredients.at(0).at(0)) {
|
2015-07-25 07:02:20 +00:00
|
|
|
trace(Primitive_recipe_depth, "run") << "jump-if fell through" << end();
|
2015-02-20 02:25:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-05-17 09:22:41 +00:00
|
|
|
assert(scalar(ingredients.at(1)));
|
2015-06-04 01:00:11 +00:00
|
|
|
current_step_index() += ingredients.at(1).at(0)+1;
|
2015-07-25 07:02:20 +00:00
|
|
|
trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
|
2015-06-04 01:00:11 +00:00
|
|
|
continue; // skip rest of this instruction
|
2015-02-20 02:25:25 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:19:03 +00:00
|
|
|
:(scenario jump_if)
|
2015-02-20 02:25:25 +00:00
|
|
|
recipe main [
|
2015-05-13 16:09:22 +00:00
|
|
|
jump-if 999:literal, 1:offset
|
2015-05-21 19:36:59 +00:00
|
|
|
123:number <- copy 1:literal
|
2015-02-20 02:25:25 +00:00
|
|
|
]
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump-if 999:literal, 1:offset
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: jumping to instruction 2
|
2015-05-21 19:36:59 +00:00
|
|
|
-run: 1:number <- copy 1:literal
|
|
|
|
-mem: storing 1 in location 123
|
2015-02-20 02:25:25 +00:00
|
|
|
|
2015-04-24 17:19:03 +00:00
|
|
|
:(scenario jump_if_fallthrough)
|
2015-02-20 02:25:25 +00:00
|
|
|
recipe main [
|
2015-05-13 16:09:22 +00:00
|
|
|
jump-if 0:literal, 1:offset
|
2015-05-13 17:03:26 +00:00
|
|
|
123:number <- copy 1:literal
|
2015-02-20 02:25:25 +00:00
|
|
|
]
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump-if 0:literal, 1:offset
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: jump-if fell through
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: 123:number <- copy 1:literal
|
2015-03-24 06:59:59 +00:00
|
|
|
+mem: storing 1 in location 123
|
2015-02-20 02:25:25 +00:00
|
|
|
|
2015-04-17 17:31:17 +00:00
|
|
|
:(before "End Primitive Recipe Declarations")
|
|
|
|
JUMP_UNLESS,
|
2015-02-20 02:25:25 +00:00
|
|
|
:(before "End Primitive Recipe Numbers")
|
2015-07-04 16:40:50 +00:00
|
|
|
Recipe_ordinal["jump-unless"] = JUMP_UNLESS;
|
2015-02-20 02:25:25 +00:00
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP_UNLESS: {
|
2015-05-10 15:34:12 +00:00
|
|
|
assert(current_instruction().ingredients.at(1).initialized);
|
2015-05-17 09:22:41 +00:00
|
|
|
assert(SIZE(ingredients) == 2);
|
|
|
|
assert(scalar(ingredients.at(0)));
|
2015-05-07 22:06:53 +00:00
|
|
|
if (ingredients.at(0).at(0)) {
|
2015-07-25 07:02:20 +00:00
|
|
|
trace(Primitive_recipe_depth, "run") << "jump-unless fell through" << end();
|
2015-02-20 02:25:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-05-17 09:22:41 +00:00
|
|
|
assert(scalar(ingredients.at(1)));
|
2015-06-04 01:00:11 +00:00
|
|
|
current_step_index() += ingredients.at(1).at(0)+1;
|
2015-07-25 07:02:20 +00:00
|
|
|
trace(Primitive_recipe_depth, "run") << "jumping to instruction " << current_step_index() << end();
|
2015-06-04 01:00:11 +00:00
|
|
|
continue; // skip rest of this instruction
|
2015-02-20 02:25:25 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:19:03 +00:00
|
|
|
:(scenario jump_unless)
|
2015-02-20 02:25:25 +00:00
|
|
|
recipe main [
|
2015-05-13 16:09:22 +00:00
|
|
|
jump-unless 0:literal, 1:offset
|
2015-05-21 19:36:59 +00:00
|
|
|
123:number <- copy 1:literal
|
2015-02-20 02:25:25 +00:00
|
|
|
]
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump-unless 0:literal, 1:offset
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: jumping to instruction 2
|
2015-05-21 19:36:59 +00:00
|
|
|
-run: 123:number <- copy 1:literal
|
|
|
|
-mem: storing 1 in location 123
|
2015-02-20 02:25:25 +00:00
|
|
|
|
2015-04-24 17:19:03 +00:00
|
|
|
:(scenario jump_unless_fallthrough)
|
2015-02-20 02:25:25 +00:00
|
|
|
recipe main [
|
2015-05-13 16:09:22 +00:00
|
|
|
jump-unless 999:literal, 1:offset
|
2015-05-13 17:03:26 +00:00
|
|
|
123:number <- copy 1:literal
|
2015-02-20 02:25:25 +00:00
|
|
|
]
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: jump-unless 999:literal, 1:offset
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: jump-unless fell through
|
2015-05-21 19:36:59 +00:00
|
|
|
+run: 123:number <- copy 1:literal
|
2015-03-24 06:59:59 +00:00
|
|
|
+mem: storing 1 in location 123
|