summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 00ba397..9f6ece6 100644
--- a/vm.c
+++ b/vm.c
@@ -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: { \