diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-20 18:11:09 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-20 18:11:09 +0100 |
commit | 600eaef90f9f0507635fec4cf98f7fa1d1779bd1 (patch) | |
tree | d057e694a4b9a6a0109523f61ad788a125a7f479 /vm.c | |
parent | b8d0ee2e105727021f9466790ec07ecbfee8dff6 (diff) |
add readable globals
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(); \ |