about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/015jump32
1 files changed, 32 insertions, 0 deletions
diff --git a/cpp/015jump b/cpp/015jump
new file mode 100644
index 00000000..bcac4b6c
--- /dev/null
+++ b/cpp/015jump
@@ -0,0 +1,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