![]() | Fun 0.41.5 The programming language that makes You have fun |
Core virtual machine implementation and opcode dispatch for Fun. More...
#include <math.h>#include <stdarg.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "iter.c"#include "map.c"#include "string.c"#include "value.h"#include "vm.h"#include "extensions/curl.c"#include "extensions/ini.c"#include "extensions/json.c"#include "extensions/openssl.c"#include "extensions/pcre2.c"#include "extensions/pcsc.c"#include "extensions/sqlite.c"#include "extensions/xml2.c"#include "vm/os/thread_common.c"#include <setjmp.h>#include "vm/arithmetic/add.c"#include "vm/arithmetic/div.c"#include "vm/arithmetic/mul.c"#include "vm/arithmetic/sub.c"#include "vm/arrays/apop.c"#include "vm/arrays/clear.c"#include "vm/arrays/contains.c"#include "vm/arrays/enumerate.c"#include "vm/arrays/index_get.c"#include "vm/arrays/index_of.c"#include "vm/arrays/index_set.c"#include "vm/arrays/insert.c"#include "vm/arrays/join.c"#include "vm/arrays/make_array.c"#include "vm/arrays/push.c"#include "vm/arrays/remove.c"#include "vm/arrays/set.c"#include "vm/arrays/slice.c"#include "vm/arrays/zip.c"#include "vm/bitwise/band.c"#include "vm/bitwise/bnot.c"#include "vm/bitwise/bor.c"#include "vm/bitwise/bxor.c"#include "vm/bitwise/rol.c"#include "vm/bitwise/ror.c"#include "vm/bitwise/shl.c"#include "vm/bitwise/shr.c"#include "vm/core/call.c"#include "vm/core/dup.c"#include "vm/core/exit.c"#include "vm/core/halt.c"#include "vm/core/jump.c"#include "vm/core/jump_if_false.c"#include "vm/core/load_const.c"#include "vm/core/load_global.c"#include "vm/core/load_local.c"#include "vm/core/nop.c"#include "vm/core/pop.c"#include "vm/core/return.c"#include "vm/core/store_global.c"#include "vm/core/store_local.c"#include "vm/core/swap.c"#include "vm/core/throw.c"#include "vm/core/try_pop.c"#include "vm/core/try_push.c"#include "vm/io/input_line.c"#include "vm/io/read_file.c"#include "vm/io/write_file.c"#include "vm/logic/and.c"#include "vm/logic/eq.c"#include "vm/logic/gt.c"Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
| #define | _XOPEN_SOURCE 700 |
| #define | fprintf fun_vm_fprintf |
| #define | exit(code) |
Functions | |
| char * | preprocess_includes (const char *src) |
| Public wrapper to preprocess includes without a current path. | |
| int | map_expanded_line_to_include_path (const char *path, int line, char *out_path, size_t out_path_cap, int *out_line) |
| Map a line number in expanded source back to original include path/line. | |
| void | vm_raise_error (VM *vm, const char *msg) |
| Raise a runtime error inside the VM, honoring try/catch/finally. | |
| void | vm_clear_output (VM *vm) |
| Clear the VM's buffered output values and partial flags. | |
| void | vm_free (VM *vm) |
| Free resources owned directly by the VM structure. | |
| void | vm_reset (VM *vm) |
| Reset the VM to a clean state. | |
| void | vm_dump_globals (VM *vm) |
| Print all non-nil global variables to stdout for debugging. | |
| void | vm_debug_reset (VM *vm) |
| Reset debugger state: breakpoints and stepping controls. | |
| int | vm_debug_add_breakpoint (VM *vm, const char *file, int line) |
| Add a source breakpoint. | |
| int | vm_debug_delete_breakpoint (VM *vm, int id) |
| Delete a breakpoint by id. | |
| void | vm_debug_clear_breakpoints (VM *vm) |
| Remove all breakpoints from the VM. | |
| void | vm_debug_list_breakpoints (VM *vm) |
| Print active breakpoints to stdout. | |
| void | vm_debug_request_step (VM *vm) |
| Request single-step execution (stop after next instruction). | |
| void | vm_debug_request_next (VM *vm) |
| Request step-over (stop after next instruction in current frame). | |
| void | vm_debug_request_finish (VM *vm) |
| Request finish (run until the current frame returns). | |
| void | vm_debug_request_continue (VM *vm) |
| Resume normal execution (clear stepping state and stop flag). | |
| int64_t | vm_pop_i64 (VM *vm) |
| Pop a numeric Value and convert it to a 64-bit integer (C ABI helper). | |
| void | vm_push_i64 (VM *vm, int64_t v) |
| Push a 64-bit integer as a VM int Value (C ABI helper). | |
| size_t | vm_sizeof (void) |
| Return sizeof(VM) for external FFI consumers. | |
| size_t | vm_value_sizeof (void) |
| Return sizeof(Value) for external FFI consumers. | |
| void * | vm_as_mut_ptr (VM *vm) |
| Cast the VM pointer to an opaque mutable void* (unsafe FFI helper). | |
| size_t | vm_offset_of_exit_code (void) |
| Obtain offsetof(VM, exit_code) for FFI struct field access. | |
| size_t | vm_offset_of_sp (void) |
| Obtain offsetof(VM, sp) for FFI struct field access. | |
| size_t | vm_offset_of_stack (void) |
| Obtain offsetof(VM, stack) for FFI struct field access. | |
| size_t | vm_offset_of_globals (void) |
| Obtain offsetof(VM, globals) for FFI struct field access. | |
| void | vm_init (VM *vm) |
| Initialize a VM instance to its default state. | |
| void | vm_print_output (VM *vm) |
| Print the VM's buffered output values to stdout. | |
Core virtual machine implementation and opcode dispatch for Fun.
Defines the VM state, stack helpers, debugger/stepping support, built-in opcode handlers (included as amalgamated C files), platform I/O helpers, and the main interpreter loop that executes bytecode produced by the Fun compiler. This file is the central runtime of the language.
Definition in file vm.c.
| extern |
Map a line number in expanded source back to original include path/line.
Scans the expanded text for the nearest preceding __include_begin__ marker and computes the corresponding inner line number.
| path | Path to the original top-level file that was expanded. |
| line | 1-based line number in the expanded text. |
| out_path | Output buffer for the resolved file path. |
| out_path_cap | Capacity of out_path. |
| out_line | Receives 1-based line number within resolved file. |
Definition at line 996 of file parser_utils.c.

| extern |
Public wrapper to preprocess includes without a current path.
Definition at line 965 of file parser_utils.c.

| void * vm_as_mut_ptr | ( | VM * | vm | ) |
| void vm_clear_output | ( | VM * | vm | ) |
Clear the VM's buffered output values and partial flags.
Clear the buffered output captured by the VM.
Frees any dynamic storage held by buffered output Values and resets the output counters and partial line indicators.
| vm | VM instance whose output buffer should be cleared. |
Definition at line 349 of file vm.c.


| int vm_debug_add_breakpoint | ( | VM * | vm, |
| const char * | file, | ||
| int | line ) |
| void vm_debug_clear_breakpoints | ( | VM * | vm | ) |
| int vm_debug_delete_breakpoint | ( | VM * | vm, |
| int | id ) |
| void vm_debug_list_breakpoints | ( | VM * | vm | ) |
| void vm_debug_request_continue | ( | VM * | vm | ) |
| void vm_debug_request_finish | ( | VM * | vm | ) |
| void vm_debug_request_next | ( | VM * | vm | ) |
| void vm_debug_request_step | ( | VM * | vm | ) |
| void vm_debug_reset | ( | VM * | vm | ) |
| void vm_dump_globals | ( | VM * | vm | ) |
| void vm_free | ( | VM * | vm | ) |
Free resources owned directly by the VM structure.
Free all resources owned by the VM (globals, frames, output buffers). The VM object itself is not freed when allocated on the stack.
Currently a no-op because the VM does not allocate persistent internal resources outside frames, globals and outputs, which are managed elsewhere.
| vm | VM instance to free resources for. |
Definition at line 367 of file vm.c.

| void vm_init | ( | VM * | vm | ) |
Initialize a VM instance to its default state.
Initialize a VM instance to zero/initial state.
Resets stack/frame pointers, output buffers, instruction counters, debugger state and globals. Does not allocate memory.
| vm | VM instance to initialize. |
Definition at line 714 of file vm.c.


| size_t vm_offset_of_exit_code | ( | void | ) |
| size_t vm_offset_of_globals | ( | void | ) |
| size_t vm_offset_of_sp | ( | void | ) |
| size_t vm_offset_of_stack | ( | void | ) |
| int64_t vm_pop_i64 | ( | VM * | vm | ) |
Pop a numeric Value and convert it to a 64-bit integer (C ABI helper).
Accepts int or float Values on the stack. Other types raise a runtime type error. The popped Value is freed.
| vm | VM instance. |
Definition at line 598 of file vm.c.


| void vm_print_output | ( | VM * | vm | ) |
Print the VM's buffered output values to stdout.
Print buffered output entries to stdout (debug aid).
Emits a newline after each value unless the corresponding partial flag is set.
| vm | VM instance whose output should be printed. |
Definition at line 797 of file vm.c.


| void vm_push_i64 | ( | VM * | vm, |
| int64_t | v ) |
| void vm_raise_error | ( | VM * | vm, |
| const char * | msg ) |
Raise a runtime error inside the VM, honoring try/catch/finally.
Raise a runtime error honoring active try/catch/finally handlers. If a try handler is active in the current frame, control jumps to it with an error string pushed on the stack. Otherwise, prints the error (with location) and terminates execution.
If the current frame has a pending try handler, control is transferred to that handler and the error message is pushed onto the stack for the catch clause. If no handler exists, the error is printed and the VM is stopped.
| vm | Pointer to the VM instance. |
| msg | Human-readable error message (may be NULL). |
Definition at line 248 of file vm.c.


| void vm_reset | ( | VM * | vm | ) |
Reset the VM to a clean state.
Reset VM to initial state, freeing globals/locals/output. The VM object remains valid for reuse after this call.
Pops all frames (releasing local variables), clears the operand stack and globals, resets the output buffer and debugger state, and zeros the exit code.
| vm | VM instance to reset. |
Definition at line 382 of file vm.c.

| size_t vm_sizeof | ( | void | ) |