summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index e969692..1dc40e0 100644
--- a/vm.c
+++ b/vm.c
@@ -27,11 +27,15 @@ size_t chunk_wbc(State *S, Chunk *ch, uint8_t byte) {
return ix;
}
size_t chunk_wconst(State *S, Chunk *ch, Val v) {
+ for (int i = 0; i < ch->consts.len; i ++)
+ if (val_equal(v, ch->consts.d[i])) return i;
+
if (ch->consts.len == ch->consts.cap) {
size_t newsz = (ch->consts.cap == 0 ? 8 : ch->consts.cap *2);
ch->consts.d = RENEW_ARR(S, ch->consts.d, Val, ch->consts.cap, newsz);
ch->consts.cap = newsz;
}
+
size_t ix = ch->consts.len;
ch->consts.d[ix] = v;
ch->consts.len ++;
@@ -149,11 +153,16 @@ int runvm(State *S) {
ARITH_OP(OP_SUB, -)
ARITH_OP(OP_MUL, *)
ARITH_OP(OP_DIV, /)
- BOOL_OP(OP_EQU, ==)
BOOL_OP(OP_CMP, <)
#undef BINARY_OP
#undef ARITH_OP
#undef BOOL_OP
+ case OP_EQU: {
+ Val b = POP();
+ Val a = POP();
+ PUSH(VAL_BOOL(val_equal(a,b)));
+ break;
+ }
case OP_MOD: {
Val b = POP();
Val a = POP();