diff options
| author | iamcheeseman <[email protected]> | 2026-04-14 12:44:25 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-04-14 12:44:25 -0400 |
| commit | ca004156cbb1c525900f444994112fc17b71d63d (patch) | |
| tree | 8d19ad7199044e4b11fde6725eb758917f317b4e /uscript/vm.h | |
| parent | 752d7967f3cccb4f43e1df7fd99d4944884fc977 (diff) | |
microscript: add globals
Diffstat (limited to 'uscript/vm.h')
| -rw-r--r-- | uscript/vm.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/uscript/vm.h b/uscript/vm.h index 15c21a0..2911d01 100644 --- a/uscript/vm.h +++ b/uscript/vm.h @@ -11,6 +11,8 @@ #define vm_peek() (vm.stacktop[-1]) #define vm_push(v) (*vm.stacktop++ = (v)) +#define set_global(idx, v) (vm.gstack[idx].val = (v)) + enum bytecode { #define BC(name) BC_##name, #include "xbytecode.h" @@ -22,16 +24,23 @@ struct call_frame { struct us_val *stackbot; }; +struct global { + struct us_str *name; + struct us_val val; +}; + 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 global *gstack; // dynarr + struct global *gstacktop; + struct us_upval *open_upvals; }; @@ -41,4 +50,6 @@ void init_vm(void); void deinit_vm(void); void print_func(struct us_proto *proto); +int declare_global(struct us_str *name); + #endif // __USCRIPT_VM_H__ |
