diff options
Diffstat (limited to 'uscript/vm.h')
| -rw-r--r-- | uscript/vm.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/uscript/vm.h b/uscript/vm.h new file mode 100644 index 0000000..15c21a0 --- /dev/null +++ b/uscript/vm.h @@ -0,0 +1,44 @@ +#ifndef __USCRIPT_VM_H__ +#define __USCRIPT_VM_H__ + +#include "common.h" +#include "val.h" + +#define MAX_CALL_FRAMES (64) +#define STACK_SIZE (MAX_CALL_FRAMES * 256) + +#define vm_pop() (*(--vm.stacktop)) +#define vm_peek() (vm.stacktop[-1]) +#define vm_push(v) (*vm.stacktop++ = (v)) + +enum bytecode { +#define BC(name) BC_##name, +#include "xbytecode.h" +#undef BC +}; + +struct call_frame { + struct us_func *func; + struct us_val *stackbot; +}; + +struct vm { + struct us_val *objs; + + struct call_frame cf_stack[MAX_CALL_FRAMES]; + struct call_frame *cf; + + struct us_val *global_stack; // dyn_arr + struct us_val stack[STACK_SIZE]; + struct us_val *stacktop; + + struct us_upval *open_upvals; +}; + +extern struct vm vm; + +void init_vm(void); +void deinit_vm(void); +void print_func(struct us_proto *proto); + +#endif // __USCRIPT_VM_H__ |
