Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
load.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
10/**
11 * @file load.c
12 * @brief VM opcode snippet for loading an INI file (OP_INI_LOAD).
13 *
14 * Opcode: OP_INI_LOAD
15 * Stack: [path:string] -> [handle:int]
16 *
17 * Behavior
18 * - Pops a filesystem path and attempts to parse it via iniparser_load().
19 * - On success, registers the resulting dictionary and pushes a positive
20 * handle. On failure, pushes 0.
21 *
22 * Notes
23 * - The returned handle must later be released with OP_INI_FREE to avoid
24 * leaking dictionary objects.
25 */
26
27/* OP_INI_LOAD: pops path string; pushes handle (>0) or 0 */
28#ifdef FUN_WITH_INI
30 Value vpath = pop_value(vm);
31 const char *path = (vpath.type == VAL_STRING && vpath.s) ? vpath.s : NULL;
32 int h = 0;
33 if (path) {
34 dictionary *d = iniparser_load(path);
35 if (d) {
37 if (!h) {
38 iniparser_freedict(d);
39 }
40 }
41 }
44 break;
45}
46#endif
@ OP_INI_LOAD
Definition bytecode.h:203
CURL * h
Definition download.c:59
char * path
Definition download.c:43
dictionary * d
Definition get_bool.c:43
int ini_alloc_handle(dictionary *d)
Allocate a registry handle for a newly created dictionary.
Definition handles.c:43
free_value(vpath)
push_value(vm, make_int(h))
Tagged union representing a Fun value.
Definition value.h:68
void vpath
Definition stubs.c:23
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_STRING
Definition value.h:53
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580