diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-24 20:20:06 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-24 20:20:06 +0100 |
commit | e9b99a90510309ac4f5d91d4a5138e7a84904057 (patch) | |
tree | 9d633feb897bcbbd43da6419882df600f9de5595 /vm.c | |
parent | bc47478d855b08023409dbfc8550958991265c14 (diff) |
add local variables and (let) form
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -111,6 +111,12 @@ int runvm(State *S) { break; } + case OP_GETLOCAL: { + uint8_t lidx = RBYTE(); + PUSH(th->stack[lidx]); + break; + } + #define BINARY_OP(opcode, OP, RET_TYPE) \ case opcode: { \ Val b = POP(); \ @@ -148,8 +154,8 @@ int runvm(State *S) { goto done; } PUSH(VAL_NUM(fmod(AS_NUM(a), AS_NUM(b)))); - } break; + } case OP_NIL: PUSH(VAL_NIL); break; @@ -173,8 +179,16 @@ int runvm(State *S) { th->ch = &func->ch; th->ip = 0; + break; + } + + case OP_ENDSCOPE: { + uint8_t nlocals = RBYTE(); + Val retval = POP(); + th->sp -= nlocals; + PUSH(retval); + break; } - break; case OP_RET: { StackFrame *sf = &th->rstack[--th->rsp]; |