1
0
Fork 0
forked from fun/fun

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:
Johannes Findeisen 2026-03-18 20:52:00 +01:00
commit 03b2532474
237 changed files with 17550 additions and 13911 deletions

View file

@ -8,7 +8,7 @@
*/
/**
* @file and.c
* @file and.c
* @brief Implements the OP_AND opcode for logical AND in the VM.
*
* This file handles the OP_AND instruction, which performs a logical AND operation
@ -32,11 +32,11 @@
*/
case OP_AND: {
Value b = pop_value(vm);
Value a = pop_value(vm);
int res = value_is_truthy(&a) && value_is_truthy(&b);
free_value(a);
free_value(b);
push_value(vm, make_bool(res));
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
int res = value_is_truthy(&a) && value_is_truthy(&b);
free_value(a);
free_value(b);
push_value(vm, make_bool(res));
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file eq.c
* @file eq.c
* @brief Implements the OP_EQ opcode for equality comparison in the VM.
*
* This file handles the OP_EQ instruction, which checks if two values are equal.
@ -32,29 +32,42 @@
*/
case OP_EQ: {
Value b = pop_value(vm);
Value a = pop_value(vm);
int eq = 0;
if (a.type == b.type) {
switch (a.type) {
case VAL_INT: eq = (a.i == b.i); break;
case VAL_BOOL: eq = ((a.i != 0) == (b.i != 0)); break;
case VAL_STRING: eq = (a.s && b.s) ? (strcmp(a.s, b.s) == 0) : (a.s == b.s); break;
case VAL_FUNCTION: eq = (a.fn == b.fn); break;
case VAL_NIL: eq = 1; break;
default: eq = 0; 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);
eq = (ai == bi);
} else {
eq = 0;
}
Value b = pop_value(vm);
Value a = pop_value(vm);
int eq = 0;
if (a.type == b.type) {
switch (a.type) {
case VAL_INT:
eq = (a.i == b.i);
break;
case VAL_BOOL:
eq = ((a.i != 0) == (b.i != 0));
break;
case VAL_STRING:
eq = (a.s && b.s) ? (strcmp(a.s, b.s) == 0) : (a.s == b.s);
break;
case VAL_FUNCTION:
eq = (a.fn == b.fn);
break;
case VAL_NIL:
eq = 1;
break;
default:
eq = 0;
break;
}
push_value(vm, make_bool(eq));
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);
eq = (ai == bi);
} else {
eq = 0;
}
}
push_value(vm, make_bool(eq));
free_value(a);
free_value(b);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file gt.c
* @file gt.c
* @brief Implements the OP_GT opcode for greater-than comparison in the VM.
*
* This file handles the OP_GT instruction, which checks if the first value is greater than the second.
@ -33,13 +33,14 @@
*/
case OP_GT: {
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: GT expects ints\n");
exit(1);
}
push_value(vm, make_int(a.i > b.i ? 1 : 0));
free_value(a); free_value(b);
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: GT expects ints\n");
exit(1);
}
push_value(vm, make_int(a.i > b.i ? 1 : 0));
free_value(a);
free_value(b);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file gte.c
* @file gte.c
* @brief Implements the OP_GTE opcode for greater-than-or-equal comparison in the VM.
*
* This file handles the OP_GTE instruction, which checks if the first value is greater than or equal to the second.
@ -32,13 +32,14 @@
*/
case OP_GTE: {
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: GTE expects ints\n");
exit(1);
}
push_value(vm, make_int(a.i >= b.i ? 1 : 0));
free_value(a); free_value(b);
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: GTE expects ints\n");
exit(1);
}
push_value(vm, make_int(a.i >= b.i ? 1 : 0));
free_value(a);
free_value(b);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file lt.c
* @file lt.c
* @brief Implements the OP_LT opcode for less-than comparison in the VM.
*
* This file handles the OP_LT instruction, which checks if the first value is less than the second.
@ -32,16 +32,16 @@
*/
case OP_LT: {
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: LT expects ints, got %s and %s\n",
value_type_name(a.type), value_type_name(b.type));
exit(1);
}
Value res = make_int(a.i < b.i ? 1 : 0);
free_value(a);
free_value(b);
push_value(vm, res);
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: LT expects ints, got %s and %s\n",
value_type_name(a.type), value_type_name(b.type));
exit(1);
}
Value res = make_int(a.i < b.i ? 1 : 0);
free_value(a);
free_value(b);
push_value(vm, res);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file lte.c
* @file lte.c
* @brief Implements the OP_LTE opcode for less-than-or-equal comparison in the VM.
*
* This file handles the OP_LTE instruction, which checks if the first value is less than or equal to the second.
@ -32,15 +32,15 @@
*/
case OP_LTE: {
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: LTE expects ints\n");
exit(1);
}
Value res = make_int(a.i <= b.i ? 1 : 0);
free_value(a);
free_value(b);
push_value(vm, res);
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
if (a.type != VAL_INT || b.type != VAL_INT) {
fprintf(stderr, "Runtime type error: LTE expects ints\n");
exit(1);
}
Value res = make_int(a.i <= b.i ? 1 : 0);
free_value(a);
free_value(b);
push_value(vm, res);
break;
}

View file

@ -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;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file not.c
* @file not.c
* @brief Implements the OP_NOT opcode for logical NOT in the VM.
*
* This file handles the OP_NOT instruction, which performs a logical NOT operation
@ -32,9 +32,9 @@
*/
case OP_NOT: {
Value v = pop_value(vm);
int res = !value_is_truthy(&v);
free_value(v);
push_value(vm, make_bool(res));
break;
Value v = pop_value(vm);
int res = !value_is_truthy(&v);
free_value(v);
push_value(vm, make_bool(res));
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file or.c
* @file or.c
* @brief Implements the OP_OR opcode for logical OR in the VM.
*
* This file handles the OP_OR instruction, which performs a logical OR operation
@ -32,11 +32,11 @@
*/
case OP_OR: {
Value b = pop_value(vm);
Value a = pop_value(vm);
int res = value_is_truthy(&a) || value_is_truthy(&b);
free_value(a);
free_value(b);
push_value(vm, make_bool(res));
break;
Value b = pop_value(vm);
Value a = pop_value(vm);
int res = value_is_truthy(&a) || value_is_truthy(&b);
free_value(a);
free_value(b);
push_value(vm, make_bool(res));
break;
}