1
0
Fork 0
forked from fun/fun

Made Booleans a first-class type. (0.23.0)

This commit is contained in:
Johannes Findeisen 2025-10-04 17:34:23 +02:00
commit 95eba1eb12
12 changed files with 131 additions and 18 deletions

View file

@ -38,15 +38,23 @@ case OP_NEQ: {
if (a.type == b.type) {
switch (a.type) {
case VAL_INT: neq = (a.i != b.i); break;
case VAL_BOOL: neq = ((a.i != 0) != (b.i != 0)); break;
case VAL_STRING: neq = (a.s && b.s) ? (strcmp(a.s, b.s) != 0) : (a.s != b.s); break;
case VAL_FUNCTION: neq = (a.fn != b.fn); break;
case VAL_NIL: neq = 0; break;
default: neq = 1; break;
}
} else {
neq = 1;
/* interop: bool vs int (0/1) */
if ((a.type == VAL_BOOL && b.type == VAL_INT) || (a.type == VAL_INT && b.type == VAL_BOOL)) {
int ai = (a.type == VAL_BOOL) ? (a.i != 0) : (a.i != 0);
int bi = (b.type == VAL_BOOL) ? (b.i != 0) : (b.i != 0);
neq = (ai != bi);
} else {
neq = 1;
}
}
push_value(vm, make_int(neq ? 1 : 0));
push_value(vm, make_bool(neq));
free_value(a); free_value(b);
break;
}