File syn_wasm.h¶
FileList > src > syntropic > vm > syn_wasm.h
Go to the source code of this file
[EXPERIMENTAL] Zero-heap, 32-bit WebAssembly (Wasm MVP) cooperative interpreter. More...
#include "../common/syn_defs.h"#include "../util/syn_qmath.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_WASM_CallFrame WebAssembly runtime call frame. |
| struct | SYN_WASM_Context_s WebAssembly virtual machine execution context. |
| struct | SYN_WASM_FuncDef WebAssembly function definition metadata. |
| struct | SYN_WASM_Label WebAssembly control flow label stack entry. |
| struct | SYN_WASM_Module Parsed WebAssembly module header and export registry. |
Public Types¶
| Type | Name |
|---|---|
| typedef uint64_t(* | SYN_WASM_HostFunc Host function signature callable from Wasm bytecode. |
| enum | SYN_WASM_Status WebAssembly VM execution status codes and traps. |
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_wasm_call (SYN_WASM_Context * ctx, uint16_t func_index) Prepare context to call a function index. |
| int32_t | syn_wasm_find_export (const SYN_WASM_Module * mod, const char * name) Find exported function index by name. |
| bool | syn_wasm_init (SYN_WASM_Context * ctx, const SYN_WASM_Module * mod, uint8_t * linear_mem, uint32_t mem_size) Initialize execution context for loaded module. |
| bool | syn_wasm_module_load (SYN_WASM_Module * mod, const uint8_t * bytes, uint32_t size) Parse Wasm binary module from flash buffer (zero memory allocation). |
| bool | syn_wasm_register_host (SYN_WASM_Context * ctx, uint16_t import_index, SYN_WASM_HostFunc func) Register C host function for imported Wasm functions. |
| uint64_t | syn_wasm_result (const SYN_WASM_Context * ctx) Read top of evaluation stack result after HALTED. |
| SYN_WASM_Status | syn_wasm_step (SYN_WASM_Context * ctx, uint16_t max_instructions) Execute instruction slice non-blockingly. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_WASM_MAX_CALL_DEPTH 32 |
| define | SYN_WASM_MAX_FUNCTIONS 32 |
| define | SYN_WASM_MAX_GLOBALS 16 |
| define | SYN_WASM_MAX_HOST_FUNCS 16 |
| define | SYN_WASM_MAX_LABELS 16 |
| define | SYN_WASM_MAX_LOCALS 256 |
| define | SYN_WASM_MAX_STACK 64 |
Detailed Description¶
Warning:
EXPERIMENTAL MODULE - API and bytecode execution semantics subject to change.
Implements a 100% zero-malloc, non-blocking 32-bit WebAssembly MVP interpreter designed for embedded microcontrollers. Supports static linear memory arrays, zero-copy parsing from flash, host function registration, and instruction-sliced cooperative execution with protothread (syn_pt) integration.
Recommended C-to-WASM compilation command for user applications: clang target=wasm32-unknown-unknown -O2 -nostdlib \ -mbulk-memory -msign-ext -mmultivalue -mnontrapping-fptoint \ -Wl,no-entry -Wl,export-all -Wl,allow-undefined \ -Wl,-z,stack-size=1024 app.c -o app.wasm
Public Types Documentation¶
typedef SYN_WASM_HostFunc¶
Host function signature callable from Wasm bytecode.
Parameters:
ctxPointer to Wasm execution context.argsArray of 32-bit arguments passed from Wasm stack.argcNumber of arguments.
Returns:
32-bit return value (pushed onto Wasm stack).
enum SYN_WASM_Status¶
WebAssembly VM execution status codes and traps.
enum SYN_WASM_Status {
SYN_WASM_OK = 0,
SYN_WASM_YIELDED,
SYN_WASM_HALTED,
SYN_WASM_TRAP_STACK_OVERFLOW,
SYN_WASM_TRAP_STACK_UNDERFLOW,
SYN_WASM_TRAP_OUT_OF_BOUNDS,
SYN_WASM_TRAP_BAD_OPCODE,
SYN_WASM_TRAP_DIV_ZERO,
SYN_WASM_TRAP_UNREACHABLE,
SYN_WASM_TRAP_CALL_STACK_OVERFLOW,
SYN_WASM_TRAP_TYPE_MISMATCH,
SYN_WASM_TRAP_INVALID_MODULE,
SYN_WASM_TRAP_UNREGISTERED_HOST
};
Public Functions Documentation¶
function syn_wasm_call¶
Prepare context to call a function index.
Parameters:
ctxPointer to context.func_indexFunction index to invoke.
Returns:
true if call frame initialized successfully.
function syn_wasm_find_export¶
Find exported function index by name.
Parameters:
modPointer to loaded module.nameExported function name string.
Returns:
Function index if found, or -1 if not found.
function syn_wasm_init¶
Initialize execution context for loaded module.
bool syn_wasm_init (
SYN_WASM_Context * ctx,
const SYN_WASM_Module * mod,
uint8_t * linear_mem,
uint32_t mem_size
)
Parameters:
ctxPointer to context structure.modPointer to loaded module descriptor.linear_memPointer to statically-allocated linear memory byte array.mem_sizeSize of linear memory buffer in bytes.
Returns:
true if initialized successfully.
function syn_wasm_module_load¶
Parse Wasm binary module from flash buffer (zero memory allocation).
Parameters:
modPointer to module descriptor to populate.bytesPointer to flash buffer containing .wasm binary.sizeLength of wasm binary buffer.
Returns:
true if valid Wasm MVP binary module parsed successfully.
function syn_wasm_register_host¶
Register C host function for imported Wasm functions.
bool syn_wasm_register_host (
SYN_WASM_Context * ctx,
uint16_t import_index,
SYN_WASM_HostFunc func
)
Parameters:
ctxPointer to context.import_indexIndex of import function slot (0 .. import_func_count - 1).funcFunction pointer to host C handler.
Returns:
true if registered successfully.
function syn_wasm_result¶
Read top of evaluation stack result after HALTED.
Parameters:
ctxPointer to context.
Returns:
32-bit return value.
function syn_wasm_step¶
Execute instruction slice non-blockingly.
Parameters:
ctxPointer to context.max_instructionsMaximum opcodes to process before yielding.
Returns:
SYN_WASM_OK (completed), SYN_WASM_YIELDED (time slice expired), SYN_WASM_HALTED (finished), or TRAP.
Macro Definition Documentation¶
define SYN_WASM_MAX_CALL_DEPTH¶
Maximum call frame stack depth
define SYN_WASM_MAX_FUNCTIONS¶
Maximum internal function defs
define SYN_WASM_MAX_GLOBALS¶
Maximum global variables
define SYN_WASM_MAX_HOST_FUNCS¶
Maximum registered host functions
define SYN_WASM_MAX_LABELS¶
Maximum block/loop control labels
define SYN_WASM_MAX_LOCALS¶
Maximum local variable count per frame
define SYN_WASM_MAX_STACK¶
Maximum operand stack depth
The documentation for this class was generated from the following file src/syntropic/vm/syn_wasm.h