diff options
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 32 |
1 files changed, 5 insertions, 27 deletions
@@ -28,8 +28,6 @@ int runvm(State *S) { Thread *th = S->th; Chunk *ch = th->ch; - int status = 1; - if (S->do_disasm) { disasm_chunk(ch); puts("---"); @@ -92,11 +90,7 @@ int runvm(State *S) { 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; - } + CHECK(IS_STRING(varname), "global names must be string"); Val v = ht_get(S, &S->globals, AS_STRING(varname)); PUSH(v); if (IS_NIL(v)) { @@ -107,11 +101,7 @@ int runvm(State *S) { 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; - } + CHECK(IS_STRING(varname), "global names must be string"); Val v = PEEK(); ht_put(S, &S->globals, AS_STRING(varname), v); @@ -134,11 +124,7 @@ int runvm(State *S) { case opcode: { \ Val b = POP(); \ Val a = POP(); \ - if (!IS_NUM(a) || !IS_NUM(b)) { \ - printf("can't do arithmetic on %s and %s\n", \ - typename_str(a), typename_str(b)); \ - goto done; \ - } \ + CHECK(IS_NUM(a) && IS_NUM(b), "can only do arithmetic on num"); \ PUSH(RET_TYPE(AS_NUM(a) OP AS_NUM(b))); \ } \ break; @@ -161,11 +147,7 @@ int runvm(State *S) { case OP_MOD: { Val b = POP(); Val a = POP(); - if (!IS_NUM(a) || !IS_NUM(b)) { - printf("can't do arithmetic on %s and %s", - typename_str(a), typename_str(b)); - goto done; - } + CHECK(IS_NUM(a) && IS_NUM(b), "can only do arithmetic on num"); PUSH(VAL_NUM(fmod(AS_NUM(a), AS_NUM(b)))); break; } @@ -257,9 +239,7 @@ int runvm(State *S) { break; } case OP_HALT: - status = 0; - goto done; - break; + return 0; case OP_ARRNEW: { ObjArr *a = objarr_new(S); @@ -288,8 +268,6 @@ int runvm(State *S) { } - done:; - return status; } #undef RBYTE |