lang: Move bytecode to func.c
This commit is contained in:
parent
57cf8a137f
commit
88a6df3ca2
3 changed files with 14 additions and 17 deletions
|
@ -22,19 +22,7 @@ enum opcodes {
|
|||
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
13
lang/func.c
13
lang/func.c
|
@ -21,8 +21,17 @@ static void func_call(VmState state, Object obj) {
|
|||
(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[] = {
|
||||
|
|
Loading…
Add table
Reference in a new issue