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/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/bytecode/main.c') diff --git a/src/bytecode/main.c b/src/bytecode/main.c index 5081d95..66089c0 100644 --- a/src/bytecode/main.c +++ b/src/bytecode/main.c @@ -38,10 +38,16 @@ process_source(const StringView *source) { return; } - // Push some test instructions. - size_t const_idx = add_constant(vm.chunk, 7); + size_t const_a = add_constant(vm.chunk, 7); add_code(vm.chunk, OP_CONSTANT, 1, 1); - add_code(vm.chunk, const_idx, 1, 1); + add_code(vm.chunk, const_a, 1, 1); + size_t const_b = add_constant(vm.chunk, 2); + add_code(vm.chunk, OP_CONSTANT, 1, 2); + add_code(vm.chunk, const_b, 1, 2); + + // Arithmetic. + add_code(vm.chunk, OP_MOD, 1, 3); + add_code(vm.chunk, OP_RETURN, 1, 1); vm_interpret(vm); -- cgit v1.2.1