lang: Add OP_DROP to bytecode

This commit is contained in:
Jookia 2023-05-30 15:13:58 +10:00
parent 44bc2d1f7c
commit 886badc588
2 changed files with 13 additions and 1 deletions

View file

@ -8,10 +8,17 @@
enum opcodes {
OP_RET = 0x00,
OP_NUM = 0x01,
OP_DROP = 0x02,
};
// clang-format off
static const unsigned char bytecode[] = {
OP_NUM, 0xaa, 0xaa, 0xaa, 0xaa,
OP_DROP,
OP_NUM, 0xbb, 0xbb, 0xbb, 0xbb,
OP_DROP,
OP_NUM, 0xcc, 0xcc, 0xcc, 0xcc,
OP_DROP,
OP_NUM, 0xd2, 0x04, 0x00, 0x00,
OP_RET
};
@ -33,6 +40,10 @@ void bytecode_run(struct object **stack) {
*pos_stack++ = number_create(num);
break;
}
case OP_DROP: {
object_drop(--pos_stack);
break;
}
}
}
}

View file

@ -25,7 +25,8 @@ static void test_number(void) {
static void test_func(void) {
struct object *funcA = func_create();
struct object *args[] = {NULL};
// args must have space for a stack
struct object *args[8] = {NULL, NULL};
dispatch_call(funcA, "Call", 0, &args[0]);
printf("funcA is %p\n", (void *)funcA);
object_drop(&funcA);