Added tons of AI generated docs and a lot of cleanups. No code changes. (0.41.5)
This commit is contained in:
parent
24c54fba41
commit
4e69a3ce63
151 changed files with 3897 additions and 427 deletions
|
|
@ -1,14 +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-11-30
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file free.c
|
||||
* @brief VM opcode snippet for releasing an INI handle (OP_INI_FREE).
|
||||
*
|
||||
* This file is included into the main VM dispatch switch in vm.c. It is only
|
||||
* compiled when FUN_WITH_INI is enabled and iniparser headers are available.
|
||||
*
|
||||
* Opcode: OP_INI_FREE
|
||||
* Stack: [handle:int] -> [ok:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops an integer handle referring to an INI dictionary previously returned
|
||||
* by OP_INI_LOAD.
|
||||
* - Attempts to close the underlying dictionary and free the registry slot.
|
||||
* - Pushes 1 on success, 0 if the handle was invalid or already freed.
|
||||
*
|
||||
* Errors
|
||||
* - No VM error is thrown for invalid handles; the opcode simply returns 0.
|
||||
*
|
||||
* See also
|
||||
* - ini_alloc_handle(), ini_free_handle() in src/vm/ini/handles.c
|
||||
*/
|
||||
/* OP_INI_FREE: pops handle; pushes 1/0 */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_FREE: {
|
||||
|
|
|
|||
|
|
@ -1,14 +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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file get_bool.c
|
||||
* @brief VM opcode snippet for reading a boolean from an INI dictionary (OP_INI_GET_BOOL).
|
||||
*
|
||||
* Included by vm.c when FUN_WITH_INI is enabled.
|
||||
*
|
||||
* Opcode: OP_INI_GET_BOOL
|
||||
* Stack: [default:int|bool] [key:string] [section:string] [handle:int] -> [out:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops default value (0/1), key, section, and handle.
|
||||
* - Looks up the entry "section:key" in the referenced dictionary. If not found,
|
||||
* also tries a dotted variant "section.key" for compatibility.
|
||||
* - Accepts textual booleans (true/false, yes/no, on/off; case-insensitive) and
|
||||
* numeric values (non-zero => true). Falls back to the provided default when
|
||||
* parsing fails or entry is missing.
|
||||
* - Pushes 1 for true or 0 for false.
|
||||
*
|
||||
* Errors
|
||||
* - Invalid handle or arguments simply yield the default value; no exception.
|
||||
*/
|
||||
/* OP_INI_GET_BOOL */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_BOOL: {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,27 @@
|
|||
/*
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file get_double.c
|
||||
* @brief VM opcode snippet for reading a floating-point value from INI (OP_INI_GET_DOUBLE).
|
||||
*
|
||||
* Opcode: OP_INI_GET_DOUBLE
|
||||
* Stack: [default:float|int] [key:string] [section:string] [handle:int] -> [out:float]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops default, key, section, and handle; looks up "section:key" (and
|
||||
* dotted fallback) and attempts to parse as double using strtod().
|
||||
* - If lookup or parsing fails, pushes the provided default.
|
||||
*
|
||||
* Errors
|
||||
* - Invalid handle/args simply produce the default; no exception raised.
|
||||
*/
|
||||
/* OP_INI_GET_DOUBLE */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_DOUBLE: {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,27 @@
|
|||
/*
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file get_int.c
|
||||
* @brief VM opcode snippet for reading an integer from INI (OP_INI_GET_INT).
|
||||
*
|
||||
* Opcode: OP_INI_GET_INT
|
||||
* Stack: [default:int] [key:string] [section:string] [handle:int] -> [out:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops default, key, section, and handle; looks up "section:key" (and dotted
|
||||
* fallback) and attempts to parse as base-10 integer using strtol().
|
||||
* - If lookup or parsing fails, returns the provided default.
|
||||
*
|
||||
* Errors
|
||||
* - Invalid handle/args produce the default; no VM exception is raised.
|
||||
*/
|
||||
/* OP_INI_GET_INT */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_INT: {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,27 @@
|
|||
/*
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file get_string.c
|
||||
* @brief VM opcode snippet for reading a string from INI (OP_INI_GET_STRING).
|
||||
*
|
||||
* Opcode: OP_INI_GET_STRING
|
||||
* Stack: [default:string] [key:string] [section:string] [handle:int] -> [out:string]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops default string, key, section, and handle; looks up "section:key" and
|
||||
* a dotted fallback. If not found, uses the provided default.
|
||||
* - Pushes the resulting string (copied into a VM Value).
|
||||
*
|
||||
* Errors
|
||||
* - Invalid handle/args result in pushing the default (or empty string).
|
||||
*/
|
||||
/* OP_INI_GET_STRING */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_GET_STRING: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
|
|
@ -7,6 +7,15 @@
|
|||
* https://opensource.org/license/apache-2-0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file handles.c
|
||||
* @brief INI handle registry implementation used by VM INI opcodes.
|
||||
*
|
||||
* Provides a tiny fixed-size registry mapping small integer handles to
|
||||
* iniparser dictionary pointers. Not thread-safe. Handles are positive
|
||||
* integers in range [1, 63].
|
||||
*/
|
||||
|
||||
#ifdef FUN_WITH_INI
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<iniparser/iniparser.h>)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@
|
|||
* 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
|
||||
*/
|
||||
|
||||
/** INI handle registry for iniparser 4.2.6 */
|
||||
/**
|
||||
* @file handles.h
|
||||
* @brief INI handle registry for iniparser 4.2.6 used by INI VM opcodes.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef FUN_WITH_INI
|
||||
|
|
@ -29,19 +30,43 @@
|
|||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @brief One slot in the global INI handle registry.
|
||||
* @details Associates an iniparser dictionary pointer with an in-use flag.
|
||||
*/
|
||||
typedef struct {
|
||||
dictionary *dict;
|
||||
int in_use;
|
||||
} IniSlot;
|
||||
|
||||
/* Single global registry (defined in handles.c) */
|
||||
/** Single global registry (defined in handles.c). */
|
||||
extern IniSlot g_ini[64];
|
||||
|
||||
/* Registry API (implemented in handles.c) */
|
||||
/**
|
||||
* @brief Allocate a registry handle for a newly created dictionary.
|
||||
* @param d Pointer to an iniparser dictionary.
|
||||
* @return Handle id (>0) on success or 0 on failure.
|
||||
*/
|
||||
int ini_alloc_handle(dictionary *d);
|
||||
/**
|
||||
* @brief Look up a dictionary pointer by registry handle.
|
||||
* @param h Handle id previously returned by ini_alloc_handle().
|
||||
* @return Pointer to dictionary or NULL if not found.
|
||||
*/
|
||||
dictionary *ini_get(int h);
|
||||
/**
|
||||
* @brief Free a previously allocated handle and close its dictionary.
|
||||
* @param h Handle id to free.
|
||||
* @return 1 on success, 0 on error (invalid handle or not in use).
|
||||
*/
|
||||
int ini_free_handle(int h);
|
||||
|
||||
/* Helper to build section:key string safely into provided buffer (implemented in handles.c) */
|
||||
/**
|
||||
* @brief Build a fully qualified key "section:key" into a caller-provided buffer.
|
||||
* @param buf Destination buffer.
|
||||
* @param cap Capacity of buf in bytes (including terminator).
|
||||
* @param sec Section name (may be NULL for default section).
|
||||
* @param key Key name (must not be NULL).
|
||||
*/
|
||||
void ini_make_full_key(char *buf, size_t cap, const char *sec, const char *key);
|
||||
#endif /* FUN_WITH_INI */
|
||||
|
|
|
|||
|
|
@ -1,14 +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-11-30
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file load.c
|
||||
* @brief VM opcode snippet for loading an INI file (OP_INI_LOAD).
|
||||
*
|
||||
* Opcode: OP_INI_LOAD
|
||||
* Stack: [path:string] -> [handle:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops a filesystem path and attempts to parse it via iniparser_load().
|
||||
* - On success, registers the resulting dictionary and pushes a positive
|
||||
* handle. On failure, pushes 0.
|
||||
*
|
||||
* Notes
|
||||
* - The returned handle must later be released with OP_INI_FREE to avoid
|
||||
* leaking dictionary objects.
|
||||
*/
|
||||
/* OP_INI_LOAD: pops path string; pushes handle (>0) or 0 */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_LOAD: {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,27 @@
|
|||
/*
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file save.c
|
||||
* @brief VM opcode snippet for saving an INI dictionary to a file (OP_INI_SAVE).
|
||||
*
|
||||
* Opcode: OP_INI_SAVE
|
||||
* Stack: [path:string] [handle:int] -> [ok:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops a path and a handle. If the handle is valid, opens the path for
|
||||
* writing and dumps the dictionary in INI format. Pushes 1 on success,
|
||||
* otherwise 0.
|
||||
*
|
||||
* Errors
|
||||
* - Failing fopen() or invalid handle simply return 0; no exception is thrown.
|
||||
*/
|
||||
/* OP_INI_SAVE */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_SAVE: {
|
||||
|
|
|
|||
|
|
@ -1,14 +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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file set.c
|
||||
* @brief VM opcode snippet for setting an INI value (OP_INI_SET).
|
||||
*
|
||||
* Opcode: OP_INI_SET
|
||||
* Stack: [value:any] [key:string] [section:string] [handle:int] -> [ok:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops value, key, section, and handle. Converts the value to a string using
|
||||
* value_to_string_alloc() and stores it under "section:key" (and a dotted
|
||||
* fallback) via dictionary_set().
|
||||
* - Pushes 1 on success, 0 on failure (invalid args/handle or allocation fail).
|
||||
*
|
||||
* Errors
|
||||
* - No VM exception is thrown; failures return 0.
|
||||
*/
|
||||
/* OP_INI_SET */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_SET: {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
/*
|
||||
* This file provides stub handlers for INI opcodes when FUN_WITH_INI is disabled.
|
||||
* Each opcode reports a clear runtime error and returns a safe default.
|
||||
/**
|
||||
* @file stubs.c
|
||||
* @brief Stub opcode implementations for INI support when FUN_WITH_INI is disabled.
|
||||
*
|
||||
* These cases are compiled into the VM dispatch when the INI feature is not
|
||||
* enabled. Each opcode prints a descriptive runtime error and pushes a safe
|
||||
* default (0, 0.0, or empty string) to keep execution proceeding without
|
||||
* crashing.
|
||||
*/
|
||||
|
||||
/* OP_INI_LOAD: pops path string; pushes 0 (invalid handle) */
|
||||
|
|
|
|||
|
|
@ -1,14 +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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file unset.c
|
||||
* @brief VM opcode snippet for removing an INI entry (OP_INI_UNSET).
|
||||
*
|
||||
* Opcode: OP_INI_UNSET
|
||||
* Stack: [key:string] [section:string] [handle:int] -> [ok:int]
|
||||
*
|
||||
* Behavior
|
||||
* - Pops key, section, and handle. Removes both "section:key" and a dotted
|
||||
* fallback key from the dictionary. Pushes 1 if the operation was attempted
|
||||
* (with a valid handle and arguments), otherwise 0.
|
||||
*
|
||||
* Notes
|
||||
* - iniparser 4.2.6 dictionary_unset() returns void; we assume success when
|
||||
* called with valid parameters.
|
||||
*/
|
||||
/* OP_INI_UNSET */
|
||||
#ifdef FUN_WITH_INI
|
||||
case OP_INI_UNSET: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue