From 3b136ffdebf135cc0d285573edd7bdfefb99bb00 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 22 Oct 2021 12:37:37 +0200 Subject: Add unary arithmetic operations for numbers --- src/bytecode/vm.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/bytecode/vm.h') diff --git a/src/bytecode/vm.h b/src/bytecode/vm.h index d9b37a3..cc9f846 100644 --- a/src/bytecode/vm.h +++ b/src/bytecode/vm.h @@ -68,6 +68,31 @@ vm_interpret(VM vm) { Object obj = vm.chunk->constants[constant]; array_push(vm.stack, obj); } break; + case OP_SUM: { + Object a = array_pop(vm.stack); + Object b = array_pop(vm.stack); + array_push(vm.stack, a + b); + } break; + case OP_SUB: { + Object a = array_pop(vm.stack); + Object b = array_pop(vm.stack); + array_push(vm.stack, a - b); + } break; + case OP_MUL: { + Object a = array_pop(vm.stack); + Object b = array_pop(vm.stack); + array_push(vm.stack, a * b); + } break; + case OP_DIV: { + Object a = array_pop(vm.stack); + Object b = array_pop(vm.stack); + array_push(vm.stack, a / b); + } break; + case OP_MOD: { + Object a = array_pop(vm.stack); + Object b = array_pop(vm.stack); + array_push(vm.stack, a % b); + } break; case OP_RETURN: { display(array_pop(vm.stack)); printf("\n"); -- cgit v1.2.1