diff --git a/lang/bytecode.c b/lang/bytecode.c index 3a9decc..624b6dd 100644 --- a/lang/bytecode.c +++ b/lang/bytecode.c @@ -22,19 +22,7 @@ OP_DEPTH_CHECK = 0x09, }; -// Auto-generated by compile.py -// clang-format off -static const unsigned char bytecode[] = { -0x09, 0x01, 0x05, 0x05, 0x05, 0x01, 0x6a, 0x02, 0x00, 0x00, -0x07, 0x01, 0x05, 0x06, 0x01, 0x06, 0x01, 0x04, 0x02, 0x41, -0x64, 0x64, 0x00, 0x09, 0x05, 0x07, 0x02, 0x05, 0x01, 0x02, -0x00, 0x00, 0x00, 0x06, 0x02, 0x04, 0x02, 0x4d, 0x69, 0x6e, -0x75, 0x73, 0x00, 0x09, 0x05, 0x07, 0x03, 0x06, 0x03, 0x07, -0x00, 0x08, 0x03, 0x03, -}; -// clang-format on - -void bytecode_run(VmState state) { +void bytecode_run(VmState state, const unsigned char *bytecode) { const unsigned char *pos_code = &bytecode[0]; unsigned char op = OP_RET; while ((op = *pos_code++) != OP_RET) { diff --git a/lang/bytecode.h b/lang/bytecode.h index 952a9ab..170e0b7 100644 --- a/lang/bytecode.h +++ b/lang/bytecode.h @@ -6,7 +6,7 @@ #include "types.h" -// Runs bytecode on a stack -void bytecode_run(VmState state); +// Runs bytecode +void bytecode_run(VmState state, const unsigned char *bytecode); #endif diff --git a/lang/func.c b/lang/func.c index 395d51e..ac89cc5 100644 --- a/lang/func.c +++ b/lang/func.c @@ -21,8 +21,17 @@ (void)obj; int arg_count = vm_stack_depth(state); abort_if(arg_count != 1, "func_add called with more than 1 argument"); - // For now just call bytecode_run - bytecode_run(state); + // clang-format off + static const unsigned char bytecode[] = { + 0x09, 0x01, 0x05, 0x05, 0x05, 0x01, 0x6a, 0x02, 0x00, 0x00, + 0x07, 0x01, 0x05, 0x06, 0x01, 0x06, 0x01, 0x04, 0x02, 0x41, + 0x64, 0x64, 0x00, 0x09, 0x05, 0x07, 0x02, 0x05, 0x01, 0x02, + 0x00, 0x00, 0x00, 0x06, 0x02, 0x04, 0x02, 0x4d, 0x69, 0x6e, + 0x75, 0x73, 0x00, 0x09, 0x05, 0x07, 0x03, 0x06, 0x03, 0x07, + 0x00, 0x08, 0x03, 0x03, + }; + // clang-format on + bytecode_run(state, bytecode); } static struct object_call calls[] = {