Split ./src/vm/ini/* opcodes into seperate files. (0.36.3)
This commit is contained in:
parent
3722df654b
commit
ccd03d3bec
11 changed files with 237 additions and 167 deletions
9
src/vm.c
9
src/vm.c
|
|
@ -749,8 +749,13 @@ void vm_run(VM *vm, Bytecode *entry) {
|
|||
#ifdef FUN_WITH_INI
|
||||
#include "vm/ini/load.c"
|
||||
#include "vm/ini/free.c"
|
||||
#include "vm/ini/getters.c"
|
||||
#include "vm/ini/set_unset_save.c"
|
||||
#include "vm/ini/get_string.c"
|
||||
#include "vm/ini/get_int.c"
|
||||
#include "vm/ini/get_double.c"
|
||||
#include "vm/ini/get_bool.c"
|
||||
#include "vm/ini/set.c"
|
||||
#include "vm/ini/unset.c"
|
||||
#include "vm/ini/save.c"
|
||||
#endif
|
||||
|
||||
/* CURL ops */
|
||||
|
|
|
|||
33
src/vm/ini/get_bool.c
Normal file
33
src/vm/ini/get_bool.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from getters.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_GET_BOOL */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_BOOL: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
int def = (vdef.type==VAL_INT||vdef.type==VAL_BOOL) ? (int)vdef.i : 0;
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
int outb = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outb = iniparser_getboolean(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(outb ? 1 : 0));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
33
src/vm/ini/get_double.c
Normal file
33
src/vm/ini/get_double.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from getters.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_GET_DOUBLE */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_DOUBLE: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
double def = (vdef.type==VAL_FLOAT) ? vdef.d : (vdef.type==VAL_INT ? (double)vdef.i : 0.0);
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
double outd = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outd = iniparser_getdouble(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_float(outd));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
33
src/vm/ini/get_int.c
Normal file
33
src/vm/ini/get_int.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from getters.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_GET_INT */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_INT: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
int def = (vdef.type==VAL_INT) ? (int)vdef.i : 0;
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
int outi = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outi = iniparser_getint(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(outi));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
34
src/vm/ini/get_string.c
Normal file
34
src/vm/ini/get_string.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from getters.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_GET_STRING */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_STRING: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
const char *def = (vdef.type==VAL_STRING && vdef.s) ? vdef.s : "";
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
const char *res = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
const char *s = iniparser_getstring(d, full, def);
|
||||
res = s ? s : "";
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_string(res));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-11-30
|
||||
*/
|
||||
|
||||
/* OP_INI_GET_* implementations */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_STRING: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
const char *def = (vdef.type==VAL_STRING && vdef.s) ? vdef.s : "";
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
const char *res = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
const char *s = iniparser_getstring(d, full, def);
|
||||
res = s ? s : "";
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_string(res));
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_INI_GET_INT: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
int def = (vdef.type==VAL_INT) ? (int)vdef.i : 0;
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
int outi = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outi = iniparser_getint(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(outi));
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_INI_GET_DOUBLE: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
double def = (vdef.type==VAL_FLOAT) ? vdef.d : (vdef.type==VAL_INT ? (double)vdef.i : 0.0);
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
double outd = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outd = iniparser_getdouble(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_float(outd));
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_INI_GET_BOOL: {
|
||||
Value vdef = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
int def = (vdef.type==VAL_INT||vdef.type==VAL_BOOL) ? (int)vdef.i : 0;
|
||||
const char *key = (vkey.type==VAL_STRING) ? vkey.s : NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING) ? vsec.s : NULL;
|
||||
int h = (vh.type==VAL_INT) ? (int)vh.i : 0;
|
||||
dictionary *d = ini_get(h);
|
||||
int outb = def;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; ini_make_full_key(full, sizeof(full), sec, key);
|
||||
outb = iniparser_getboolean(d, full, def);
|
||||
}
|
||||
free_value(vdef); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(outb ? 1 : 0));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
28
src/vm/ini/save.c
Normal file
28
src/vm/ini/save.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from set_unset_save.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_SAVE */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_SAVE: {
|
||||
Value vpath = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
const char *path = (vpath.type==VAL_STRING)?vpath.s:NULL;
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
int ok = 0;
|
||||
if (d && path) {
|
||||
FILE *f = fopen(path, "w");
|
||||
if (f) { iniparser_dump_ini(d, f); fclose(f); ok = 1; }
|
||||
}
|
||||
free_value(vpath); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
36
src/vm/ini/set.c
Normal file
36
src/vm/ini/set.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from set_unset_save.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_SET */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_SET: {
|
||||
Value vval = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
|
||||
int ok = 0;
|
||||
if (d && sec && key) {
|
||||
char *valstr = value_to_string_alloc(&vval);
|
||||
if (valstr) {
|
||||
char full[1024]; snprintf(full, sizeof(full), "%s:%s", sec, key);
|
||||
/* iniparser 4.x does not expose iniparser_set; use dictionary_set */
|
||||
if (dictionary_set(d, full, valstr) == 0) ok = 1; /* 0 means success */
|
||||
free(valstr);
|
||||
}
|
||||
}
|
||||
free_value(vval); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-11-30
|
||||
*/
|
||||
|
||||
/* OP_INI_SET / OP_INI_UNSET / OP_INI_SAVE */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_SET: {
|
||||
Value vval = pop_value(vm);
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
|
||||
int ok = 0;
|
||||
if (d && sec && key) {
|
||||
char *valstr = value_to_string_alloc(&vval);
|
||||
if (valstr) {
|
||||
char full[1024]; snprintf(full, sizeof(full), "%s:%s", sec, key);
|
||||
/* iniparser 4.x does not expose iniparser_set; use dictionary_set */
|
||||
if (dictionary_set(d, full, valstr) == 0) ok = 1; /* 0 means success */
|
||||
free(valstr);
|
||||
}
|
||||
}
|
||||
free_value(vval); free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_INI_UNSET: {
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
|
||||
int ok = 0;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; snprintf(full, sizeof(full), "%s:%s", sec, key);
|
||||
/* iniparser 4.2.6 dictionary_unset returns void; assume success if inputs are valid */
|
||||
dictionary_unset(d, full);
|
||||
ok = 1;
|
||||
}
|
||||
free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_INI_SAVE: {
|
||||
Value vpath = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
const char *path = (vpath.type==VAL_STRING)?vpath.s:NULL;
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
int ok = 0;
|
||||
if (d && path) {
|
||||
FILE *f = fopen(path, "w");
|
||||
if (f) { iniparser_dump_ini(d, f); fclose(f); ok = 1; }
|
||||
}
|
||||
free_value(vpath); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
32
src/vm/ini/unset.c
Normal file
32
src/vm/ini/unset.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-10 (split from set_unset_save.c)
|
||||
*/
|
||||
|
||||
/* OP_INI_UNSET */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_UNSET: {
|
||||
Value vkey = pop_value(vm);
|
||||
Value vsec = pop_value(vm);
|
||||
Value vh = pop_value(vm);
|
||||
dictionary *d = ini_get((vh.type==VAL_INT)?(int)vh.i:0);
|
||||
const char *key = (vkey.type==VAL_STRING)?vkey.s:NULL;
|
||||
const char *sec = (vsec.type==VAL_STRING)?vsec.s:NULL;
|
||||
int ok = 0;
|
||||
if (d && sec && key) {
|
||||
char full[1024]; snprintf(full, sizeof(full), "%s:%s", sec, key);
|
||||
/* iniparser 4.2.6 dictionary_unset returns void; assume success if inputs are valid */
|
||||
dictionary_unset(d, full);
|
||||
ok = 1;
|
||||
}
|
||||
free_value(vkey); free_value(vsec); free_value(vh);
|
||||
push_value(vm, make_int(ok));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue