about summary refs log tree commit diff stats
path: root/cpp/015jump
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-19 17:28:25 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-19 17:28:25 -0800
commitf2818edc5fba19885f1ba1fa48754af2e5abfceb (patch)
treecfa1995d599ee1663661a4a93bddcaa6f29954d1 /cpp/015jump
parentc7c822b27aac56de1e44555c9c2366ac6bbf13f2 (diff)
downloadmu-f2818edc5fba19885f1ba1fa48754af2e5abfceb.tar.gz
794 - first jump instruction
Diffstat (limited to 'cpp/015jump')
-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