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 has_key.c
* @file has_key.c
* @brief Implements the OP_HAS_KEY opcode for map key checking in the VM.
*
* This file handles the OP_HAS_KEY instruction, which checks if a map contains
@ -26,11 +26,15 @@
*/
case OP_HAS_KEY: {
Value key = pop_value(vm);
Value m = pop_value(vm);
if (m.type != VAL_MAP || key.type != VAL_STRING) { fprintf(stderr, "HAS_KEY expects (map, string)\n"); exit(1); }
int ok = map_has(&m, key.s ? key.s : "");
free_value(m); free_value(key);
push_value(vm, make_int(ok ? 1 : 0));
break;
Value key = pop_value(vm);
Value m = pop_value(vm);
if (m.type != VAL_MAP || key.type != VAL_STRING) {
fprintf(stderr, "HAS_KEY expects (map, string)\n");
exit(1);
}
int ok = map_has(&m, key.s ? key.s : "");
free_value(m);
free_value(key);
push_value(vm, make_int(ok ? 1 : 0));
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file keys.c
* @file keys.c
* @brief Implements the OP_KEYS opcode for retrieving map keys in the VM.
*
* This file handles the OP_KEYS instruction, which retrieves the keys of a map
@ -32,10 +32,13 @@
*/
case OP_KEYS: {
Value m = pop_value(vm);
if (m.type != VAL_MAP) { fprintf(stderr, "KEYS expects map\n"); exit(1); }
Value arr = map_keys_array(&m);
free_value(m);
push_value(vm, arr);
break;
Value m = pop_value(vm);
if (m.type != VAL_MAP) {
fprintf(stderr, "KEYS expects map\n");
exit(1);
}
Value arr = map_keys_array(&m);
free_value(m);
push_value(vm, arr);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file make_map.c
* @file make_map.c
* @brief Implements the OP_MAKE_MAP opcode for creating maps in the VM.
*
* This file handles the OP_MAKE_MAP instruction, which pops `pairs` key-value pairs
@ -33,20 +33,26 @@
* @date 2025-10-16
*/
case OP_MAKE_MAP: {
int pairs = inst.operand;
if (pairs < 0) { fprintf(stderr, "MAKE_MAP invalid pair count\n"); exit(1); }
Value m = make_map_empty();
for (int i = 0; i < pairs; ++i) {
Value val = pop_value(vm);
Value key = pop_value(vm);
if (key.type != VAL_STRING) { fprintf(stderr, "Map literal keys must be strings\n"); exit(1); }
if (!map_set(&m, key.s ? key.s : "", val)) {
fprintf(stderr, "Map literal set failed\n"); exit(1);
}
free_value(key);
int pairs = inst.operand;
if (pairs < 0) {
fprintf(stderr, "MAKE_MAP invalid pair count\n");
exit(1);
}
Value m = make_map_empty();
for (int i = 0; i < pairs; ++i) {
Value val = pop_value(vm);
Value key = pop_value(vm);
if (key.type != VAL_STRING) {
fprintf(stderr, "Map literal keys must be strings\n");
exit(1);
}
push_value(vm, m);
break;
if (!map_set(&m, key.s ? key.s : "", val)) {
fprintf(stderr, "Map literal set failed\n");
exit(1);
}
free_value(key);
}
push_value(vm, m);
break;
}

View file

@ -8,7 +8,7 @@
*/
/**
* @file values.c
* @file values.c
* @brief Implements the OP_VALUES opcode for retrieving map values in the VM.
*
* This file handles the OP_VALUES instruction, which retrieves the values of a map
@ -32,10 +32,13 @@
*/
case OP_VALUES: {
Value m = pop_value(vm);
if (m.type != VAL_MAP) { fprintf(stderr, "VALUES expects map\n"); exit(1); }
Value arr = map_values_array(&m);
free_value(m);
push_value(vm, arr);
break;
Value m = pop_value(vm);
if (m.type != VAL_MAP) {
fprintf(stderr, "VALUES expects map\n");
exit(1);
}
Value arr = map_values_array(&m);
free_value(m);
push_value(vm, arr);
break;
}