Fixed the code style in *.c files to two spaces indentation and add a linter named funstx to Fun. (0.39.0)
This commit is contained in:
parent
33001a7ad2
commit
03b2532474
237 changed files with 17550 additions and 13911 deletions
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file neq.c
|
||||
* @file neq.c
|
||||
* @brief Implements the OP_NEQ opcode for inequality comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_NEQ instruction, which checks if two values are not equal.
|
||||
|
|
@ -32,29 +32,42 @@
|
|||
*/
|
||||
|
||||
case OP_NEQ: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
int neq = 1;
|
||||
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 {
|
||||
/* 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;
|
||||
}
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
int neq = 1;
|
||||
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;
|
||||
}
|
||||
push_value(vm, make_bool(neq));
|
||||
free_value(a); free_value(b);
|
||||
break;
|
||||
} else {
|
||||
/* 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_bool(neq));
|
||||
free_value(a);
|
||||
free_value(b);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue