This runtime layer provides semantics helpers for native codegen while preserving current interpreter behavior.
src/native_runtime/ops.rs- numeric/logical/comparison helpers (
add_int,sub_int,mul_int,div_int,cmp_int) - truthiness/logical helpers (
strict_not,truthy_bang) - string/list/range helpers (
concat,in_operator,list_concat,list_subtract,range)
- numeric/logical/comparison helpers (
src/native_runtime/collections.rs- constructors and mutation helpers for tuple/list/map/keyword values
src/native_runtime/pattern.rsmatch_patternandselect_case_branchforcase/match primitive checks
src/native_runtime/interop.rs- host interop adapter helpers (
host_call,protocol_dispatch) and ABI version constant
- host interop adapter helpers (
src/native_runtime/boundary.rs- ABI-callable exported helper entrypoints
Each helper is callable with the stable Task 03 ABI boundary:
extern "C" fn(TCallContext) -> TCallResultExported symbols:
tonic_rt_add_inttonic_rt_cmp_int_eqtonic_rt_map_puttonic_rt_host_calltonic_rt_protocol_dispatch
All entrypoints route through native_abi::invoke_runtime_boundary, so they inherit:
- ABI version checking
TValuedecoding/validation- panic containment
- deterministic error return (
TCallStatus::Err+ error payload)
Helpers return deterministic messages that mirror existing runtime semantics, including
source offset attachment when provided by caller (e.g. "division by zero at offset 44",
"badarg at offset <n>", map key/update contract errors).
Native lowering reserves runtime helper symbols for closure semantics:
tn_runtime_make_closure(i64 descriptor_hash, i64 arity, i64 capture_count)tn_runtime_call_closure(i64 closure_value, i64 argc, ...)
These symbols preserve deterministic compile-time contracts for anonymous function creation, lexical capture metadata, and function-value invocation in the native backend.
Native lowering reserves host interop helper symbols for native backend calls:
tn_runtime_host_call(i64 argc, ...)tn_runtime_protocol_dispatch(i64 value)
host_call preserves existing atom-key validation and deterministic host-registry error
messages through the runtime interop adapter. protocol_dispatch preserves tuple/map
implementation mapping behavior used by interpreter mode.
Host interop ABI policy constant:
TONIC_HOST_INTEROP_ABI_VERSION = 1
For runtime memory strategy research and implementation scaffolding, see:
docs/memory-management-roadmap.mddocs/runtime-memory-task-scaffold.md
Task 01 observability additions:
- Generated C runtime supports opt-in memory diagnostics with
TONIC_MEMORY_STATS=1. - Diagnostics emit one deterministic line on stderr:
memory.stats c_runtime .... - Baseline harness:
scripts/memory-baseline.sh - Stress fixtures:
examples/memory/*.tn
Task 03 RC prototype additions:
- RC mode is opt-in via
TONIC_MEMORY_MODE=rc(at this stage default was append-only; superseded by Task 05 which selects trace as the new default). - Stats include
memory_mode,reclaims_total,heap_live_slots, andcycle_collection=off(cycle caveat is explicit in RC mode). - RC ownership contract across call-return boundaries: callees always
return with
refcount=1(a single terminator-retain before the callee's own root-frame pop). The call site balances this with oneroot_register(+1) followed by onerelease(−1), leaving the result registered exactly once in the outer frame atrefcount=1. No extra retain is inserted at call sites or insidetn_runtime_call_closure_varargs. This applies uniformly to named function calls, closure calls, and nested combinations thereof.
Task 04 tracing GC prototype additions:
- Tracing mode is available via
TONIC_MEMORY_MODE=trace. - Tracing collector is non-moving mark/sweep over boxed heap objects.
- Root traversal includes runtime root stack plus bool/nil singletons.
- Main entrypoint always calls
tn_runtime_gc_finalize()before exit when trace mode is active — independent ofTONIC_MEMORY_STATS. This decouples collection (which reclaims cyclic garbage) from stats printing (which is gated byTONIC_MEMORY_STATS=1). The GC runs at process end regardless of whether stats output is requested. - Stats include
cycle_collection=mark_sweepandgc_collections_totalin trace mode.
Task 05 bakeoff/default-selection additions:
- Default mode: tracing mark/sweep (
TONIC_MEMORY_MODEunset resolves to trace). - Rollback mode:
TONIC_MEMORY_MODE=append_onlyrestores pre-collector behavior. - Alternative experiment mode remains available via
TONIC_MEMORY_MODE=rc. - Reproducible bakeoff harness + CI guardrails:
scripts/memory-bakeoff.shscripts/memory-bakeoff.sh --ci
- Baseline-vs-RC-vs-trace report is tracked in
docs/runtime-memory-bakeoff.md.