summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-24 20:20:06 +0100
committerubq323 <ubq323@ubq323.website>2024-06-24 20:20:06 +0100
commite9b99a90510309ac4f5d91d4a5138e7a84904057 (patch)
tree9d633feb897bcbbd43da6419882df600f9de5595 /vm.c
parentbc47478d855b08023409dbfc8550958991265c14 (diff)
add local variables and (let) form
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/vm.c b/vm.c
index 4e412c1..b5b66d3 100644
--- a/vm.c
+++ b/vm.c
@@ -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];