2015-04-17 18:22:59 +00:00
|
|
|
//: Jump primitives.
|
|
|
|
|
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")
|
|
|
|
Recipe_number["jump"] = JUMP;
|
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP: {
|
2015-03-18 07:01:43 +00:00
|
|
|
trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].value;
|
2015-03-17 18:23:29 +00:00
|
|
|
pc += instructions[pc].ingredients[0].value;
|
2015-03-18 07:01:43 +00:00
|
|
|
trace("run") << "pc now " << pc;
|
2015-02-20 01:28:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
:(scenario "jump_can_skip_instructions")
|
|
|
|
recipe main [
|
|
|
|
jump 1:offset
|
|
|
|
1:integer <- copy 1:literal
|
|
|
|
]
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
2015-02-20 01:28:25 +00:00
|
|
|
+run: ingredient 0 is 1
|
2015-02-25 09:24:11 +00:00
|
|
|
-run: instruction main/1
|
2015-03-24 06:59:59 +00:00
|
|
|
-mem: storing 1 in location 1
|
2015-02-20 01:28:25 +00:00
|
|
|
|
|
|
|
:(scenario "jump_backward")
|
|
|
|
recipe main [
|
2015-03-17 05:47:28 +00:00
|
|
|
jump 1:offset # 0 -+
|
|
|
|
jump 1:offset # | +-+ 1
|
|
|
|
# \/ /\ |
|
|
|
|
jump -2:offset # 2 +-->+ |
|
|
|
|
] # \/ 3
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
|
|
|
+run: instruction main/2
|
|
|
|
+run: instruction main/1
|
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")
|
|
|
|
Recipe_number["jump-if"] = JUMP_IF;
|
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP_IF: {
|
|
|
|
vector<int> arg0 = read_memory(instructions[pc].ingredients[0]);
|
|
|
|
assert(arg0.size() == 1);
|
|
|
|
trace("run") << "ingredient 0 is " << arg0[0];
|
|
|
|
if (!arg0[0]) {
|
|
|
|
trace("run") << "jump-if fell through";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
|
2015-03-17 18:23:29 +00:00
|
|
|
pc += instructions[pc].ingredients[1].value;
|
2015-02-20 02:25:25 +00:00
|
|
|
trace("run") << "jumping to instruction " << pc+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
:(scenario "jump_if")
|
|
|
|
recipe main [
|
|
|
|
jump-if 999:literal 1:offset
|
|
|
|
1:integer <- copy 1:literal
|
|
|
|
]
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: ingredient 1 is 1
|
|
|
|
+run: jumping to instruction 2
|
2015-02-25 09:24:11 +00:00
|
|
|
-run: instruction main/1
|
2015-03-24 06:59:59 +00:00
|
|
|
-mem: storing 1 in location 1
|
2015-02-20 02:25:25 +00:00
|
|
|
|
|
|
|
:(scenario "jump_if_fallthrough")
|
|
|
|
recipe main [
|
|
|
|
jump-if 0:literal 1:offset
|
|
|
|
123:integer <- copy 1:literal
|
|
|
|
]
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: jump-if fell through
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/1
|
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")
|
|
|
|
Recipe_number["jump-unless"] = JUMP_UNLESS;
|
|
|
|
:(before "End Primitive Recipe Implementations")
|
|
|
|
case JUMP_UNLESS: {
|
|
|
|
vector<int> arg0 = read_memory(instructions[pc].ingredients[0]);
|
|
|
|
assert(arg0.size() == 1);
|
|
|
|
trace("run") << "ingredient 0 is " << arg0[0];
|
|
|
|
if (arg0[0]) {
|
|
|
|
trace("run") << "jump-unless fell through";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
|
2015-03-17 18:23:29 +00:00
|
|
|
pc += instructions[pc].ingredients[1].value;
|
2015-02-20 02:25:25 +00:00
|
|
|
trace("run") << "jumping to instruction " << pc+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
:(scenario "jump_unless")
|
|
|
|
recipe main [
|
|
|
|
jump-unless 0:literal 1:offset
|
|
|
|
1:integer <- copy 1:literal
|
|
|
|
]
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: ingredient 1 is 1
|
|
|
|
+run: jumping to instruction 2
|
2015-02-25 09:24:11 +00:00
|
|
|
-run: instruction main/1
|
2015-03-24 06:59:59 +00:00
|
|
|
-mem: storing 1 in location 1
|
2015-02-20 02:25:25 +00:00
|
|
|
|
|
|
|
:(scenario "jump_unless_fallthrough")
|
|
|
|
recipe main [
|
|
|
|
jump-unless 999:literal 1:offset
|
|
|
|
123:integer <- copy 1:literal
|
|
|
|
]
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/0
|
2015-02-20 02:25:25 +00:00
|
|
|
+run: ingredient 0 is 999
|
|
|
|
+run: jump-unless fell through
|
2015-02-25 09:24:11 +00:00
|
|
|
+run: instruction main/1
|
2015-03-24 06:59:59 +00:00
|
|
|
+mem: storing 1 in location 123
|