|
| void | vm_init (VM *vm) |
| | Initialize a VM instance to zero/initial state.
|
| void | vm_clear_output (VM *vm) |
| | Clear the buffered output captured by the VM.
|
| void | vm_print_output (VM *vm) |
| | Print buffered output entries to stdout (debug aid).
|
| void | vm_free (VM *vm) |
| | Free all resources owned by the VM (globals, frames, output buffers). The VM object itself is not freed when allocated on the stack.
|
| void | vm_reset (VM *vm) |
| | Reset VM to initial state, freeing globals/locals/output. The VM object remains valid for reuse after this call.
|
| void | vm_dump_globals (VM *vm) |
| | Print non-nil globals (index and value) to stdout.
|
| void | vm_run (VM *vm, Bytecode *entry) |
| | Execute the provided entry bytecode in the VM. Pushes an initial frame and runs until HALT or an unrecoverable error.
|
| void | vm_raise_error (VM *vm, const char *msg) |
| | 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.
|
| 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).
|
| static int | opcode_is_valid (int op) |
| | Check whether an integer value corresponds to a defined opcode.
|
| 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).
|
| int | fun_op_radd (VM *vm) |
| const char * | fun_rust_get_string (void) |
| int | fun_rust_print_string (const char *msg) |
| char * | fun_rust_echo_string (const char *input) |
| void | fun_rust_string_free (char *ptr) |
| int | fun_op_cpp_add (struct VM *vm) |
| | Add two 64-bit integers from the VM stack and push the sum.
|
| 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) |
| | Get a mutable byte pointer to the VM object. Extremely unsafe; for low-level FFI use only.
|
| 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.
|
| int | fun_op_rget_sp (VM *vm) |
| int | fun_op_rset_exit (VM *vm) |
Core virtual machine data structures and public VM API.
Declares the execution stack/frame layout, global state of the Fun VM, human-readable opcode names for diagnostics, and the public functions for initializing, running, resetting, and debugging the VM. FFI helper declarations for Rust/C++ experiments are also exposed here.
Definition in file vm.h.
| int fun_op_cpp_add |
( |
VM * | vm | ) |
|
Add two 64-bit integers from the VM stack and push the sum.
C++ demo opcode entry point (C ABI).
Pops two values from the VM stack using vm_pop_i64, adds them as 64-bit signed integers, and pushes the result via vm_push_i64.
Stack effect:
- Input: [..., a:int64, b:int64]
- Output: [..., (a+b):int64]
- Parameters
-
| vm | Pointer to the VM instance. Must not be NULL. |
- Returns
- 0 on success. Any stack underflow or conversion errors are handled by the VM helpers; non-zero may be used by future implementations to indicate a runtime error.
Definition at line 47 of file add.cpp.
| void vm_debug_reset |
( |
VM * | vm | ) |
|
Reset debugger state: breakpoints and stepping controls.
Reset debugger state (clear step mode and breakpoints).
Clears all breakpoints, disables stepping modes, and resets counters.
- Parameters
-
| vm | VM instance with debugger state to reset. |
Definition at line 429 of file vm.c.
Free all resources owned by the VM (globals, frames, output buffers). The VM object itself is not freed when allocated on the stack.
- Parameters
-
| vm | VM instance to dispose. |
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.
- Parameters
-
| vm | VM instance to free resources for. |
Definition at line 367 of file vm.c.
Initialize a VM instance to zero/initial state.
- Parameters
-
| vm | Non-NULL pointer to VM storage to initialize. |
Initialize a VM instance to zero/initial state.
Resets stack/frame pointers, output buffers, instruction counters, debugger state and globals. Does not allocate memory.
- Parameters
-
| vm | VM instance to initialize. |
Definition at line 714 of file vm.c.
| void vm_raise_error |
( |
VM * | vm, |
|
|
const char * | msg ) |
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.
- Parameters
-
| vm | VM instance. |
| msg | Null-terminated error message. |
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.
- Parameters
-
| vm | Pointer to the VM instance. |
| msg | Human-readable error message (may be NULL). |
Definition at line 248 of file vm.c.
Reset VM to initial state, freeing globals/locals/output. The VM object remains valid for reuse after this call.
- Parameters
-
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.
- Parameters
-
Definition at line 382 of file vm.c.