diff options
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: { \ |