Skip to main content

dispatch

Function dispatch 

Source
pub fn dispatch(
    vm: &mut Vm,
    fn_id: u16,
    args: &[Value],
) -> Result<Value, QalaError>
Expand description

dispatch a stdlib CALL to its native implementation.

fn_id is the u16 from the CALL opcode; the VM routes any fn_id at or above STDLIB_FN_BASE here. args are the call’s argument values in source order – args[0] is the leftmost argument (for a method call such as FileHandle.read_all, args[0] is the receiver). the returned Value is what the VM pushes onto the value stack for the instruction after the CALL; a void-returning function returns Value::void.

the match lists the functions in the exact STDLIB_TABLE order: entry i in that table is STDLIB_FN_BASE + i, so print is 40000, read_all is 40014. a fn_id below STDLIB_FN_BASE reaching here is a VM-internal invariant violation (the CALL handler should have routed it to a user frame); an unknown fn_id at or above the base is malformed bytecode. both are a clean QalaError::Runtime, never a panic.