aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/vm.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-22 12:37:37 +0200
committerBad Diode <bd@badd10de.dev>2021-10-22 12:37:37 +0200
commit3b136ffdebf135cc0d285573edd7bdfefb99bb00 (patch)
treeb66f9cf7410c43c6967b69002e0998d87f880f97 /src/bytecode/vm.h
parent9286c148f601072dded92233a328a8867ff7ab0c (diff)
downloadbdl-3b136ffdebf135cc0d285573edd7bdfefb99bb00.tar.gz
bdl-3b136ffdebf135cc0d285573edd7bdfefb99bb00.zip
Add unary arithmetic operations for numbers
Diffstat (limited to 'src/bytecode/vm.h')
-rw-r--r--src/bytecode/vm.h25
1 files changed, 25 insertions, 0 deletions
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) {
68 Object obj = vm.chunk->constants[constant]; 68 Object obj = vm.chunk->constants[constant];
69 array_push(vm.stack, obj); 69 array_push(vm.stack, obj);
70 } break; 70 } break;
71 case OP_SUM: {
72 Object a = array_pop(vm.stack);
73 Object b = array_pop(vm.stack);
74 array_push(vm.stack, a + b);
75 } break;
76 case OP_SUB: {
77 Object a = array_pop(vm.stack);
78 Object b = array_pop(vm.stack);
79 array_push(vm.stack, a - b);
80 } break;
81 case OP_MUL: {
82 Object a = array_pop(vm.stack);
83 Object b = array_pop(vm.stack);
84 array_push(vm.stack, a * b);
85 } break;
86 case OP_DIV: {
87 Object a = array_pop(vm.stack);
88 Object b = array_pop(vm.stack);
89 array_push(vm.stack, a / b);
90 } break;
91 case OP_MOD: {
92 Object a = array_pop(vm.stack);
93 Object b = array_pop(vm.stack);
94 array_push(vm.stack, a % b);
95 } break;
71 case OP_RETURN: { 96 case OP_RETURN: {
72 display(array_pop(vm.stack)); 97 display(array_pop(vm.stack));
73 printf("\n"); 98 printf("\n");