Expand description
The native runtime bridge: the typed helper-call algebra, the exact 32
bamts_* C-ABI helper exports, the panic- and nesting-safe thread-local
NativeOps dispatch seam, and the feature-gated JIT and AOT linkage
surfaces.
§Where the unsafe lives
Generated CLIF (JIT) and linked object code (AOT) own control flow but call back into this crate for every value/heap/host operation. This module is the only place raw pointers from that generated code are turned into safe Rust:
- The exported
bamts_*wrappers (bamts_load_constant…) receive raw*mut ShadowFrame/*mut Completionfrom CLIF, validate them into a safeNativeFrame, and dispatch to the currentNativeOps. They never unwind across the C boundary: any panic, missing dispatcher, or invalid frame is turned into aCompletionTag::FatalTrap. - [
JitEntry] (featurejit-entry) wraps a finalizedcranelift-jitentry-point pointer, bound to itsJITModulelifetime. - [
linked_program] (featureaot-image) reads the generated externalbamts_program_descriptorimage.
The helper table below (variant order, symbols, and operand types) is the
export contract shared verbatim with bamts_codegen::Helper
(crates/bamts-codegen/src/lib.rs, enum Helper / symbol /
external_index / param_types). Any drift breaks linkage, so a
self-consistent parity test pins it (bamts-codegen depends on this crate
under host-jit, so a direct comparison would be a dependency cycle).
Structs§
- Helper
Result - The outcome of a completion helper: the ABI tag plus the completion value its tag interprets (return value, thrown/yielded handle, or trap id).
- Linked
Program - A validated, borrow-checked view of a linked AOT image. The bytecode is carried opaquely (native code never decodes it); reconstruction/verification is the runtime’s job.
- Native
Frame - A validated safe view of a
ShadowFrameand its register (handle) array. Constructed only inside thebamts_*wrappers, which reject a null, misaligned, or malformed frame before dispatching. - Program
Descriptor - The C-layout header of a linked AOT program image, exported by generated
code as the external symbol
bamts_program_descriptor. - Unit
Descriptor - One compiled function in a linked AOT image.
Enums§
- AbiError
- A typed AOT/entry-linkage failure.
- Helper
Call - A typed helper invocation. Runtime
Values carry theirValuetype; operator selectors, string-constant ids, function/register indices, and protocol kinds are the raw ABIu32selectors codegen passes (never - Native
Helper - A runtime helper, identified by its stable ABI index. The variant order is
the canonical
external_indexorder (0..31) and is byte-identical tobamts_codegen::Helper;NativeHelper::symbolreturns the exact linker symbol generated code resolves against.
Constants§
- AOT_
ABI_ VERSION - The supported AOT image ABI version.
- AOT_
MAGIC - The little-endian image magic,
b"BMTSAOT1". - HELPER_
COUNT - The number of runtime helpers,
0..HELPER_COUNT. - TRAP_
INVALID_ COMPLETION_ TAG out.valueid written when a native entry returns an unrecognized completion tag.- TRAP_
INVALID_ FRAME out.valueid written when a wrapper receives an invalid frame pointer.- TRAP_
INVALID_ REGISTER out.valueid written when a helper receives an out-of-range register index.- TRAP_
MISSING_ NATIVE_ OPS out.valueid written when a wrapper runs with no installedNativeOps.- TRAP_
PANIC out.valueid written when the dispatcher panics (caught at the boundary).
Traits§
- Native
Entry Table - A non-self-referential seam for invoking a compiled native entry by its
(module_id, function_id)identity. A JIT backend implements this over itsJITModule; a linked AOT image (LinkedProgram) implements it over its unit table. The runtime engine stores&dyn NativeEntryTableand routes nestedCreateClosurere-entry through it. - Native
Ops - The runtime semantic engine the exported helpers dispatch into. Implemented
by
bamts_runtime’s native engine; installed for the current thread withwith_native_ops.
Functions§
- bamts_
array_ ⚠extend - Safety
- bamts_
array_ ⚠push - Safety
- bamts_
binary ⚠ - Safety
- bamts_
call ⚠ - Safety
- bamts_
construct ⚠ - Safety
- bamts_
consume_ ⚠fuel - Safety
- bamts_
create_ ⚠array - Safety
- bamts_
create_ ⚠cell - Safety
- bamts_
create_ ⚠closure - Safety
- bamts_
create_ ⚠object - Safety
- bamts_
create_ ⚠private_ name - Safety
- bamts_
create_ ⚠regexp - Safety
- bamts_
define_ ⚠accessor - Safety
- bamts_
delete_ ⚠property - Safety
- bamts_
export ⚠ - Safety
- bamts_
get_ ⚠iterator - Safety
- bamts_
get_ ⚠property - Safety
- bamts_
import ⚠ - Safety
- bamts_
iterator_ ⚠next - Safety
- bamts_
load_ ⚠arguments - Safety
- bamts_
load_ ⚠constant - Safety
- bamts_
load_ ⚠global - Safety
- bamts_
load_ ⚠new_ target - Safety
- bamts_
load_ ⚠this - Safety
- bamts_
object_ ⚠spread - Safety
- bamts_
resume_ ⚠value - Safety
- bamts_
set_ ⚠property - Safety
- bamts_
set_ ⚠prototype - Safety
- bamts_
store_ ⚠global - Safety
- bamts_
truthy ⚠ - Safety
- bamts_
typeof_ ⚠global - Safety
- bamts_
unary ⚠ - Safety
- with_
native_ ops - Installs
opsas the current thread’s dispatcher for the duration ofbody, then restores the previous dispatcher.
Type Aliases§
- Native
Entry Fn - A finalized native entry point:
extern "C" fn(frame, out) -> tag.