Skip to main content

Module supplement

Module supplement 

Source
Expand description

Ordered chain of flow supplements in front of an owner.

install_supplement_door adds a door function to a Program. The host spawns it with the owner Cap in r0. The door registers registry_name and then serves three Asks:

TagPayloadEffect
TAG_SUPP_ATTACHrecord [index: Int, cap: Cap]Insert that Cap at index (index == len appends).
TAG_SUPP_DETACHInt indexRemove that slot.
TAG_SUPP_ENTERany valueWalk the chain, then deliver what remains to the owner.

Each supplement receives TAG_SUPP_JUDGE and answers TAG_SUPP_FOLLOW (keep the value), TAG_SUPP_REJECT (stop; the owner is not asked), or TAG_SUPP_REPLACE (continue with the reply payload). A supplement that exits first is TAG_SUPP_REJECT: the door does not skip a dead step. The owner is asked with TAG_SUPP_DELIVER and uses the same three answers. The door’s reply to the caller is TAG_SUPP_FOLLOW with the final value, or TAG_SUPP_REJECT.

The chain is eight Cap registers inside the door. Tables cannot store a Cap, and list_get takes a constant index, so the walk is unrolled. Nothing in this module hooks mailbox delivery: the door is an ordinary flow, and the caller chooses it by Cap.

§Addressing

Ask needs CapRights::ASK. Bytecode Fn::whereis mints only CapRights::SEND. The name the door registers stores an CapRights::ADDRESSING token whose holder is the door. Pass that token from Runtime::whereis as a spawn argument; the runtime reissues it to the caller with ASK.

The door calls make_msg, msg_tag, msg_payload, msg_request_id, and msg_reply_cap. Start the runtime with std_native_table.

When the door exits, the scheduler revokes every Cap the door holds and sweeps the registry name. Caps the host still holds stay valid.

use byteflow::{install_supplement_door, Program};

fn main() -> Result<(), byteflow::SupplementError> {
    let mut program = Program::new("chain");
    let _door = install_supplement_door(&mut program, "front")?;
    let _chunk = program.build();
    Ok(())
}

Enums§

SupplementError
Why a door could not be added to the program.

Constants§

SUPPLEMENT_SLOTS
Slots in one door. Index 0 is asked first.
TAG_SUPP_ATTACH
Caller → door: insert a Cap. Payload is record [index, cap].
TAG_SUPP_DELIVER
Door → owner: the value the chain allowed through.
TAG_SUPP_DETACH
Caller → door: drop the slot at this Int index.
TAG_SUPP_ENTER
Caller → door: judge payload, then deliver what the chain left.
TAG_SUPP_FOLLOW
Keep the value and continue.
TAG_SUPP_JUDGE
Door → supplement: judge this value.
TAG_SUPP_REJECT
Stop the chain. The owner is not asked.
TAG_SUPP_REPLACE
Continue with the reply payload in place of the current value.

Functions§

install_supplement_door
Add the door and its judge helper to program.
supplement_attach
Ask the door to insert cap at index (Int). index == len appends. A successful reply’s payload is the new length.
supplement_detach
Ask the door to drop the slot at index (Int). A successful reply’s payload is the new length.
supplement_enter
Ask the door to judge payload. The reply hop is TAG_SUPP_FOLLOW or TAG_SUPP_REJECT.