Skip to content

Commit

Permalink
add POP_JUMP_IF_FALSE
Browse files Browse the repository at this point in the history
  • Loading branch information
sergot committed Jun 6, 2018
1 parent 554e9a7 commit 46bd739
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bytecode/interpreter.d
Expand Up @@ -6,6 +6,7 @@ enum Opcode {
ADD_INT,
PRINT,
PRINT_NL,
POP_JUMP_IF_FALSE
};

void interpret(int[] input) {
Expand Down Expand Up @@ -35,6 +36,9 @@ void interpret(int[] input) {
case Opcode.PRINT_NL:
writeln();
break;
case Opcode.POP_JUMP_IF_FALSE:
next_index = stack.back == 0 ? input[i + 1] : i + 3;
break;
default: // Default case is required.
break;
}
Expand All @@ -50,6 +54,11 @@ void main()
cast(int) Opcode.CONST_INT, 41,
cast(int) Opcode.ADD_INT,
cast(int) Opcode.PRINT,
cast(int) Opcode.PRINT_NL,
cast(int) Opcode.CONST_INT, 0,
cast(int) Opcode.POP_JUMP_IF_FALSE, 11,
cast(int) Opcode.CONST_INT, 7,
cast(int) Opcode.PRINT,
cast(int) Opcode.PRINT_NL
];
interpret(input);
Expand Down

0 comments on commit 46bd739

Please sign in to comment.