Skip to main content

Module samples

Module samples 

Source
Expand description

Built-in demo chunks assembled with crate::Program.

Use these as runnable specs of the messaging contract (and as regression tests). Prefer copying a sample over inventing hop register layouts from scratch.

SampleShows
add_forty_twoScalar VM path (no natives)
ping_pongCap spawn + Atomic Hop round-trip
atomic_request_replyTagged REQ/REP + print
selective_receiveReceiveMatch FIFO skip
ask_replyAsk RPC hop
ask_timeout_expiresAskTimeout writes Unit when the server stays silent
ask_target_exitsAsk dest is TAG_SYS_EXIT when the server dies first
server_loopBEAM-style receive → handle → reply loop
forged_sender_send / forged_sender_askS1: forged make_msg sender dies
boomImmediate trap (supervisor demos)
monitor_downMonitor → crate::TAG_SYS_DOWN on child exit
waiting_sendWAITING_SEND: second hop parks until the first is received

Hop samples require crate::std_native_table.

Constants§

TAG_JUNK
Decoy hop for selective_receive — must be skipped by ReceiveMatch.
TAG_PING
TAG_PONG
TAG_REP
TAG_REQ
Protocol tags for Atomic Hop samples.

Functions§

add_forty_two
41 + 1; return — the 60-second sanity chunk.
ask_reply
Atomic request/reply via Ask (RPC hop).
ask_target_exits
Server takes the request and exits; client Ask must not hang.
ask_timeout_expires
AskTimeout against a server that never replies → Unit.
atomic_request_reply
Atomic request-reply with crate::Value::Message (one envelope per hop).
boom
Immediate Trap — used to show crate::Supervisor restart.
forged_sender_ask
Same security property as forged_sender_send, via Ask.
forged_sender_send
Security regression: forged make_msg sender must not survive Send.
monitor_down
Child sleeps then exits; parent monitors and returns the DOWN reason (0 = normal).
ping_pong
Two flows, one Atomic Hop round-trip: main sends a Message to pong, pong replies with payload+1 via msg_reply_cap, main returns that payload (2).
selective_receive
Selective Atomic Hop: server waits for TAG_REQ while a TAG_JUNK hop sits ahead in the mailbox (FIFO skip, not drop).
server_loop
BEAM-style server loop: receive_match → handle → send_reply → repeat.
waiting_send
Client arity 1 (r0 = server Cap) sends two hops; server drains both. With mailbox capacity 1 the second send parks (WAITING_SEND).