diff options
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -65,7 +65,7 @@ void runvm(State *S) { printf("done!\n"); goto done; break; - case OP_LOADK:; + case OP_LOADK: { uint8_t cix = RBYTE(); Val v = ch->consts.d[cix]; PUSH(v); @@ -73,10 +73,24 @@ void runvm(State *S) { // print_val(v); // printf(")\n"); break; + } case OP_PRINT: println_val(POP()); break; + case OP_GETGLOBAL: { + 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 = ht_get(S, &S->globals, AS_STRING(varname)); + PUSH(v); + break; + } + #define ARITH_OP(opcode, OP) \ case opcode: { \ Val b = POP(); \ |