Skip to main content

doshfunc

Function doshfunc 

Source
pub fn doshfunc(
    shfunc: &mut shfunc,
    doshargs: Vec<String>,
    noreturnval: bool,
    body_runner: impl FnMut() -> i32,
) -> i32
Expand description

Port of int doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) from Src/exec.c:5823-6158.

C body’s scope-management sequence ported here. The C source’s body-execution call (runshfunc(prog, wrappers, name) at c:6042) is replaced by body_runner — zshrs runs function bodies through fusevm bytecode rather than zsh’s wordcode walker (per PORT.md “zshrs replaces zsh’s tree-walking interpreter” rule), so the callback hands the live executor back to the caller (typically the fusevm bridge) for the actual body run. Every line of scope save/restore around the body call mirrors C exactly.

RUST-ONLY ADAPTATION: the extra body_runner parameter is not in C. C calls runshfunc(prog, wrappers, name) directly at c:6042; zshrs delegates to a closure because the body-execution pipeline (fusevm) differs from C’s (wordcode). The closure fully replaces the runshfunc call and returns the body’s exit status (which doshfunc reads as lastval for the noreturnval path).