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