diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-20 18:43:01 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-20 18:45:35 +0100 |
commit | 9a7d1b1d41f4b3bb3387e7bbe77105d0089803d0 (patch) | |
tree | 984e8648448ee75fe2bed9f9616ba295fc1b81f7 /vm.c | |
parent | 600eaef90f9f0507635fec4cf98f7fa1d1779bd1 (diff) |
globals are now variable
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -56,6 +56,7 @@ void runvm(State *S) { #define PUSH(v) th->stack[th->sp++] = v; #define POP() (th->stack[--th->sp]) +#define PEEK() (th->stack[th->sp-1]) puts("---"); while (1) { @@ -75,7 +76,10 @@ void runvm(State *S) { break; } case OP_PRINT: - println_val(POP()); + println_val(PEEK()); + break; + case OP_DROP: + --th->sp; break; case OP_GETGLOBAL: { @@ -90,6 +94,19 @@ void runvm(State *S) { PUSH(v); break; } + case OP_SETGLOBAL: { + uint8_t cix = RBYTE(); + Val varname = ch->consts.d[cix]; + if (!IS_STRING(varname)) { + printf("global names must be string, not %s\n", + typename_str(varname)); + goto done; + } + Val v = PEEK(); + + ht_put(S, &S->globals, AS_STRING(varname), v); + break; + } #define ARITH_OP(opcode, OP) \ case opcode: { \ |