summaryrefslogtreecommitdiff
path: root/uscript/vm.h
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-06 17:04:05 -0400
committeriamcheeseman <[email protected]>2026-04-06 17:06:53 -0400
commit957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc (patch)
treef5fc230703791cee8d8e7851fb87eaef07ae63a2 /uscript/vm.h
Initial commit
Diffstat (limited to 'uscript/vm.h')
-rw-r--r--uscript/vm.h44
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__