Skip to main content

Module natives

Module natives 

Source
Expand description

Standard native (FFI) table shipped with the facade.

§Why Message make/unpack lives here (not as new opcodes)

crate::Value::Message is already a first-class wire/register value (ABI v2). Building and tearing it apart in bytecode could be ISA ops (MakeMessage, MsgSender, …), but that would burn opcode space and force every embedder that never does request-reply to carry the dispatch cost. Natives keep the envelope generic in the core while the std table opts into the helpers — same pattern as print / now_ms (design notes §30-31): host Rust owns the operation, bytecode only picks a slot.

§Stable indices are an embed contract

Flash / separately-built .bf modules hard-code CallNative indices. Renumbering an existing slot is a breaking change. Keep std_native_map and std_native_table in lockstep; append only.

IndexNameRole
0printhost stdout log line (flow-visible)
1now_mswall-clock millis as Value::Int
2make_msgbuild crate::Message from four scalars (untrusted sender)
3msg_senderextract senderValue::Pid (authenticated after delivery)
4msg_request_idextract request_idValue::Int
5msg_tagextract tagValue::Int
6msg_payloadextract payloadValue::Int
7msg_reply_capextract reply_capValue::Cap (SEND grant)

§CallNative argument layout

CallNative ra, fb, nc takes args from r[a .. a+nc] and writes the result back into r[a] — so a call destroys the first argument register. Samples that need to keep a Message while unpacking must Move it into the dest register first (see crate::samples::atomic_request_reply).

Functions§

std_native_map
Name → CallNative index for documentation / host-side lookups.
std_native_table
Default FFI table: print, clock, and Message make/unpack.
std_natives
Build the default native table and its matching name map together.