summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-08-08 14:44:48 +0100
committerubq323 <ubq323@ubq323.website>2024-08-08 14:49:05 +0100
commitd046c7d20fd283c90495d3af4bb53d1cfb2a0812 (patch)
treea764b20d45135101b179a4fbdc122ca0c76bd6b6 /vm.c
parenta4e8599e8d0fde881cd4e6e3031e5b52550e878e (diff)
misc
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c32
1 files changed, 5 insertions, 27 deletions
diff --git a/vm.c b/vm.c
index 2131c5a..f3e59c2 100644
--- a/vm.c
+++ b/vm.c
@@ -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