about summary refs log tree commit diff stats
path: root/cpp/015jump
blob: bcac4b6c13027d14b19caba862400837cad0213a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
:(before "End Globals")
// Jump ops.
const int JUMP = 10;
:(before "End Primitive Recipe Numbers")
Recipe_number["jump"] = JUMP;
Next_recipe_number++;
:(before "End Primitive Recipe Implementations")
case JUMP: {
  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
  pc += to_int(instructions[pc].ingredients[0].name);
  break;
}

:(scenario "jump_can_skip_instructions")
recipe main [
  jump 1:offset
  1:integer <- copy 1:literal
]
+run: instruction 0
+run: ingredient 0 is 1
-run: instruction 1
-mem: storing in location 1

:(scenario "jump_backward")
recipe main [
  jump 1:offset
  jump 1:offset
  jump -2:offset
]
+run: instruction 0
+run: instruction 2
+run: instruction 1