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

@ -1,5 +1,5 @@
/**
* This file is part of the Fun programming language.
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
@ -12,19 +12,26 @@
/* JSON_FROM_FILE */
case OP_JSON_FROM_FILE: {
#ifdef FUN_WITH_JSON
Value vpath = pop_value(vm);
char *path = value_to_string_alloc(&vpath);
free_value(vpath);
if (!path) { push_value(vm, make_nil()); break; }
json_object *root = json_object_from_file(path);
free(path);
if (!root) { push_value(vm, make_nil()); break; }
Value v = json_to_fun(root);
push_value(vm, v);
json_object_put(root);
#else
Value vpath = pop_value(vm); free_value(vpath);
Value vpath = pop_value(vm);
char *path = value_to_string_alloc(&vpath);
free_value(vpath);
if (!path) {
push_value(vm, make_nil());
#endif
break;
}
json_object *root = json_object_from_file(path);
free(path);
if (!root) {
push_value(vm, make_nil());
break;
}
Value v = json_to_fun(root);
push_value(vm, v);
json_object_put(root);
#else
Value vpath = pop_value(vm);
free_value(vpath);
push_value(vm, make_nil());
#endif
break;
}

View file

@ -1,5 +1,5 @@
/**
* This file is part of the Fun programming language.
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
@ -12,27 +12,30 @@
/* JSON_PARSE */
case OP_JSON_PARSE: {
#ifdef FUN_WITH_JSON
Value text = pop_value(vm);
char *s = value_to_string_alloc(&text);
free_value(text);
if (!s) { push_value(vm, make_nil()); break; }
struct json_tokener *tok = json_tokener_new();
json_object *root = json_tokener_parse_ex(tok, s, (int)strlen(s));
enum json_tokener_error jerr = json_tokener_get_error(tok);
json_tokener_free(tok);
free(s);
if (jerr != json_tokener_success) {
push_value(vm, make_nil());
} else {
Value v = json_to_fun(root);
push_value(vm, v);
json_object_put(root);
}
#else
/* Fallback when JSON is disabled: consume arg, push Nil */
Value drop = pop_value(vm);
free_value(drop);
Value text = pop_value(vm);
char *s = value_to_string_alloc(&text);
free_value(text);
if (!s) {
push_value(vm, make_nil());
#endif
break;
}
struct json_tokener *tok = json_tokener_new();
json_object *root = json_tokener_parse_ex(tok, s, (int)strlen(s));
enum json_tokener_error jerr = json_tokener_get_error(tok);
json_tokener_free(tok);
free(s);
if (jerr != json_tokener_success) {
push_value(vm, make_nil());
} else {
Value v = json_to_fun(root);
push_value(vm, v);
json_object_put(root);
}
#else
/* Fallback when JSON is disabled: consume arg, push Nil */
Value drop = pop_value(vm);
free_value(drop);
push_value(vm, make_nil());
#endif
break;
}

View file

@ -1,5 +1,5 @@
/**
* This file is part of the Fun programming language.
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
@ -12,21 +12,23 @@
/* JSON_STRINGIFY */
case OP_JSON_STRINGIFY: {
#ifdef FUN_WITH_JSON
Value vpretty = pop_value(vm);
Value any = pop_value(vm);
int pretty = (vpretty.type == VAL_BOOL || vpretty.type == VAL_INT) ? (vpretty.i != 0) : 0;
json_object *j = fun_to_json(&any);
int flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN;
const char *js = json_object_to_json_string_ext(j, flags);
push_value(vm, make_string(js ? js : ""));
json_object_put(j);
free_value(vpretty);
free_value(any);
Value vpretty = pop_value(vm);
Value any = pop_value(vm);
int pretty = (vpretty.type == VAL_BOOL || vpretty.type == VAL_INT) ? (vpretty.i != 0) : 0;
json_object *j = fun_to_json(&any);
int flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN;
const char *js = json_object_to_json_string_ext(j, flags);
push_value(vm, make_string(js ? js : ""));
json_object_put(j);
free_value(vpretty);
free_value(any);
#else
/* Fallback: consume two args, push "null" */
Value vpretty = pop_value(vm); free_value(vpretty);
Value any = pop_value(vm); free_value(any);
push_value(vm, make_string("null"));
/* Fallback: consume two args, push "null" */
Value vpretty = pop_value(vm);
free_value(vpretty);
Value any = pop_value(vm);
free_value(any);
push_value(vm, make_string("null"));
#endif
break;
break;
}

View file

@ -1,5 +1,5 @@
/**
* This file is part of the Fun programming language.
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
@ -12,26 +12,33 @@
/* JSON_TO_FILE */
case OP_JSON_TO_FILE: {
#ifdef FUN_WITH_JSON
Value vpretty = pop_value(vm);
Value any = pop_value(vm);
Value vpath = pop_value(vm);
char *path = value_to_string_alloc(&vpath);
int pretty = (vpretty.type == VAL_BOOL || vpretty.type == VAL_INT) ? (vpretty.i != 0) : 0;
free_value(vpretty);
free_value(vpath);
if (!path) { free_value(any); push_value(vm, make_int(0)); break; }
json_object *j = fun_to_json(&any);
int flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN;
int rc = json_object_to_file_ext(path, j, flags);
json_object_put(j);
free(path);
Value vpretty = pop_value(vm);
Value any = pop_value(vm);
Value vpath = pop_value(vm);
char *path = value_to_string_alloc(&vpath);
int pretty = (vpretty.type == VAL_BOOL || vpretty.type == VAL_INT) ? (vpretty.i != 0) : 0;
free_value(vpretty);
free_value(vpath);
if (!path) {
free_value(any);
push_value(vm, make_int(rc == 0 ? 1 : 0));
#else
Value vpretty = pop_value(vm); free_value(vpretty);
Value any = pop_value(vm); free_value(any);
Value vpath = pop_value(vm); free_value(vpath);
push_value(vm, make_int(0));
#endif
break;
}
json_object *j = fun_to_json(&any);
int flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN;
int rc = json_object_to_file_ext(path, j, flags);
json_object_put(j);
free(path);
free_value(any);
push_value(vm, make_int(rc == 0 ? 1 : 0));
#else
Value vpretty = pop_value(vm);
free_value(vpretty);
Value any = pop_value(vm);
free_value(any);
Value vpath = pop_value(vm);
free_value(vpath);
push_value(vm, make_int(0));
#endif
break;
}