compiler now compiles some things

This commit is contained in:
Lobo 2026-01-19 12:50:54 -03:00
parent 9616fb616e
commit ce345f2440
13 changed files with 425 additions and 74 deletions

View file

@ -10,25 +10,38 @@
enum {
OP_NOP = 0,
OP_CONST, // Push constant to stack
OP_DROP,
OP_DUP,
OP_SWAP,
OP_JUMP, // Relative jump
OP_JUMP_IF_NIL, // Relative jump if top-of-stack is nil
OP_DOWORD,
OP_CALL,
OP_APPLY,
OP_RETURN,
OP_ADD,
};
#define STACK_SIZE 256
typedef struct Fr {
Bc *chunk;
U8 *ip;
} Fr;
typedef struct Vm {
Gc gc;
O stack[256], *sp;
U rstack[256], *rsp;
Fr rstack[256], *rsp;
U8 *ip;
Bc *chunk;
} Vm;
V vm_init(Vm *);
V vm_deinit(Vm *);
V vm_push(Vm *, O);
O vm_pop(Vm *);
O vm_peek(Vm *);
V vm_run(Vm *, Bc *, I);
I vm_run(Vm *, Bc *, I);
#endif