Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
free.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 free.c
12 * @brief VM opcode snippet for releasing an INI handle (OP_INI_FREE).
13 *
14 * This file is included into the main VM dispatch switch in vm.c. It is only
15 * compiled when FUN_WITH_INI is enabled and iniparser headers are available.
16 *
17 * Opcode: OP_INI_FREE
18 * Stack: [handle:int] -> [ok:int]
19 *
20 * Behavior
21 * - Pops an integer handle referring to an INI dictionary previously returned
22 * by OP_INI_LOAD.
23 * - Attempts to close the underlying dictionary and free the registry slot.
24 * - Pushes 1 on success, 0 if the handle was invalid or already freed.
25 *
26 * Errors
27 * - No VM error is thrown for invalid handles; the opcode simply returns 0.
28 *
29 * See also
30 * - ini_alloc_handle(), ini_free_handle() in src/vm/ini/handles.c
31 */
32
33/* OP_INI_FREE: pops handle; pushes 1/0 */
34#ifdef FUN_WITH_INI
36 Value vh = pop_value(vm);
37 int h = (vh.type == VAL_INT) ? (int)vh.i : 0;
41 break;
42}
43#endif
@ OP_INI_FREE
Definition bytecode.h:204
int ok
Definition contains.c:38
CURL * h
Definition download.c:59
free_value(vh)
push_value(vm, make_int(ok))
Value vh
Definition get_bool.c:38
int ini_free_handle(int h)
Free a previously allocated handle and close its dictionary.
Definition handles.c:60
Tagged union representing a Fun value.
Definition value.h:68
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_INT
Definition value.h:51
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580