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,16 +12,17 @@
/* NC_CLEAR */
case OP_NC_CLEAR: {
#ifdef FUN_WITH_NOTCURSES
if (_fun_nc && _fun_nc_std) {
ncplane_erase(_fun_nc_std);
notcurses_render(_fun_nc);
push_value(vm, make_int(0));
} else {
push_value(vm, make_int(-1));
}
#else
(void)_fun_nc; (void)_fun_nc_std;
if (_fun_nc && _fun_nc_std) {
ncplane_erase(_fun_nc_std);
notcurses_render(_fun_nc);
push_value(vm, make_int(0));
} else {
push_value(vm, make_int(-1));
}
#else
(void)_fun_nc;
(void)_fun_nc_std;
push_value(vm, make_int(-1));
#endif
break;
break;
}

View file

@ -19,5 +19,5 @@ struct notcurses;
struct ncplane;
/* Shared static state within vm.c translation unit (header is included into vm.c at file scope) */
static struct notcurses* _fun_nc = NULL;
static struct ncplane* _fun_nc_std = NULL;
static struct notcurses *_fun_nc = NULL;
static struct ncplane *_fun_nc_std = NULL;

View file

@ -11,29 +11,30 @@
/* NC_DRAW_TEXT */
case OP_NC_DRAW_TEXT: {
Value textv = pop_value(vm);
Value xv = pop_value(vm);
Value yv = pop_value(vm);
int x = (xv.type == VAL_INT ? (int)xv.i : (xv.type == VAL_FLOAT ? (int)xv.d : 0));
int y = (yv.type == VAL_INT ? (int)yv.i : (yv.type == VAL_FLOAT ? (int)yv.d : 0));
char *text = value_to_string_alloc(&textv);
free_value(textv);
free_value(xv);
free_value(yv);
Value textv = pop_value(vm);
Value xv = pop_value(vm);
Value yv = pop_value(vm);
int x = (xv.type == VAL_INT ? (int)xv.i : (xv.type == VAL_FLOAT ? (int)xv.d : 0));
int y = (yv.type == VAL_INT ? (int)yv.i : (yv.type == VAL_FLOAT ? (int)yv.d : 0));
char *text = value_to_string_alloc(&textv);
free_value(textv);
free_value(xv);
free_value(yv);
#ifdef FUN_WITH_NOTCURSES
if (_fun_nc && _fun_nc_std && text) {
ncplane_putstr_yx(_fun_nc_std, y, x, text);
notcurses_render(_fun_nc);
free(text);
push_value(vm, make_int(0));
} else {
if (text) free(text);
push_value(vm, make_int(-1));
}
#else
(void)_fun_nc; (void)_fun_nc_std;
if (_fun_nc && _fun_nc_std && text) {
ncplane_putstr_yx(_fun_nc_std, y, x, text);
notcurses_render(_fun_nc);
free(text);
push_value(vm, make_int(0));
} else {
if (text) free(text);
push_value(vm, make_int(-1));
}
#else
(void)_fun_nc;
(void)_fun_nc_std;
if (text) free(text);
push_value(vm, make_int(-1));
#endif
break;
break;
}

View file

@ -11,33 +11,35 @@
/* NC_GETCH */
case OP_NC_GETCH: {
Value to_ms_v = pop_value(vm);
int timeout_ms = (to_ms_v.type == VAL_INT ? (int)to_ms_v.i : (to_ms_v.type == VAL_FLOAT ? (int)to_ms_v.d : 0));
free_value(to_ms_v);
Value to_ms_v = pop_value(vm);
int timeout_ms = (to_ms_v.type == VAL_INT ? (int)to_ms_v.i : (to_ms_v.type == VAL_FLOAT ? (int)to_ms_v.d : 0));
free_value(to_ms_v);
#ifdef FUN_WITH_NOTCURSES
if (_fun_nc) {
/* For simplicity, use blocking get for now when timeout<=0 */
if (timeout_ms <= 0) {
ncinput ni;
uint32_t id = notcurses_get_blocking(_fun_nc, &ni);
push_value(vm, make_int((int)id));
} else {
/* Polling approximation: render then nonblocking get once */
ncinput ni;
uint32_t id = notcurses_get_nblock(_fun_nc, &ni);
if (id == 0) {
/* no input available now: return -1 to indicate timeout */
push_value(vm, make_int(-1));
} else {
push_value(vm, make_int((int)id));
}
}
if (_fun_nc) {
/* For simplicity, use blocking get for now when timeout<=0 */
if (timeout_ms <= 0) {
ncinput ni;
uint32_t id = notcurses_get_blocking(_fun_nc, &ni);
push_value(vm, make_int((int)id));
} else {
/* Polling approximation: render then nonblocking get once */
ncinput ni;
uint32_t id = notcurses_get_nblock(_fun_nc, &ni);
if (id == 0) {
/* no input available now: return -1 to indicate timeout */
push_value(vm, make_int(-1));
} else {
push_value(vm, make_int((int)id));
}
}
#else
(void)_fun_nc; (void)_fun_nc_std; (void)timeout_ms;
} else {
push_value(vm, make_int(-1));
}
#else
(void)_fun_nc;
(void)_fun_nc_std;
(void)timeout_ms;
push_value(vm, make_int(-1));
#endif
break;
break;
}

View file

@ -12,16 +12,23 @@
/* NC_INIT */
case OP_NC_INIT: {
#ifdef FUN_WITH_NOTCURSES
if (_fun_nc) { push_value(vm, make_int(1)); break; }
struct notcurses_options opts = {0};
_fun_nc = notcurses_core_init(&opts, NULL);
if (!_fun_nc) { push_value(vm, make_int(0)); break; }
_fun_nc_std = notcurses_stdplane(_fun_nc);
if (_fun_nc) {
push_value(vm, make_int(1));
#else
(void)_fun_nc; (void)_fun_nc_std;
fprintf(stderr, "Notcurses support disabled at build time. Reconfigure with -DFUN_WITH_NOTCURSES=ON.\n");
push_value(vm, make_int(0));
#endif
break;
}
struct notcurses_options opts = {0};
_fun_nc = notcurses_core_init(&opts, NULL);
if (!_fun_nc) {
push_value(vm, make_int(0));
break;
}
_fun_nc_std = notcurses_stdplane(_fun_nc);
push_value(vm, make_int(1));
#else
(void)_fun_nc;
(void)_fun_nc_std;
fprintf(stderr, "Notcurses support disabled at build time. Reconfigure with -DFUN_WITH_NOTCURSES=ON.\n");
push_value(vm, make_int(0));
#endif
break;
}

View file

@ -12,14 +12,15 @@
/* NC_SHUTDOWN */
case OP_NC_SHUTDOWN: {
#ifdef FUN_WITH_NOTCURSES
if (_fun_nc) {
notcurses_stop(_fun_nc);
_fun_nc = NULL;
_fun_nc_std = NULL;
}
if (_fun_nc) {
notcurses_stop(_fun_nc);
_fun_nc = NULL;
_fun_nc_std = NULL;
}
#else
(void)_fun_nc; (void)_fun_nc_std;
(void)_fun_nc;
(void)_fun_nc_std;
#endif
push_value(vm, make_int(0));
break;
push_value(vm, make_int(0));
break;
}