From f2818edc5fba19885f1ba1fa48754af2e5abfceb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 19 Feb 2015 17:28:25 -0800 Subject: 794 - first jump instruction --- cpp/015jump | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 cpp/015jump (limited to 'cpp/015jump') 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 -- cgit 1.4.1-2-gfad0