Expand description
r submodule.
Loop execution for zshrs
Port from zsh/Src/loop.c (802 lines)
§of nested loops we are in // c:33
§of continue levels // c:38
§of break levels // c:43
In C, loop.c contains execfor, execwhile, execif, execcase, execselect, execrepeat, and exectry as separate functions operating on bytecode. In Rust, all of these are implemented as match arms in ShellExecutor::execute_compound() in vm_helper, operating on the typed AST (CompoundCommand::For, While, If, Case, Select, Repeat, Try).
This module provides the loop state management and helper functions that support the executor’s loop implementation.
Statics§
- try_
errflag - Port of
mod_export zlong try_errflagfromSrc/loop.c:719. Initialized to -1 (sentinel: “no try block has fired yet in this scope”); theexectryalways-arm sets it toerrflag & ERRFLAG_ERRORbefore running the always body, then restores.TRY_BLOCK_ERRORparam (IPDEF6 atSrc/params.c:364) reads this global directly. - try_
interrupt - Port of
mod_export zlong try_interruptfromSrc/loop.c:727. Initialized to -1; mirrorstry_errflagfor theERRFLAG_INTbit.TRY_BLOCK_INTERRUPTparam reads this. - try_
tryflag - Port of
mod_export zlong try_tryflagfromSrc/loop.c:731. Depth-counter for activealways {}blocks; bumped at try entry (exectry), decremented at exit.dotrapargs(signals.c:1215) reads it to decide whether a trap’serrflagpropagates.
Functions§
- execcase
- Port of
execcase(Estate state, int do_exec)fromSrc/loop.c:600-733.case word in pat) body ;; ... esacwith;;/;&/;|separators. - execfor
- Port of
execfor(Estate state, int do_exec)fromSrc/loop.c:50-202.for var in args; do body; doneand the C-stylefor ((init;cond;adv))variant. WC_FOR_TYPE distinguishes PPARAM (use $@) / LIST (explicit words) / COND (C-style). - execif
- Port of
execif(Estate state, int do_exec)fromSrc/loop.c:553-598.if cond; then body; elif ...; else ...; fi. - execrepeat
- Port of
execrepeat(Estate state, UNUSED(int do_exec))fromSrc/loop.c:499-551.repeat N; do body; done. - execselect
- Port of
execselect(Estate state, UNUSED(int do_exec))fromSrc/loop.c:217-410.select var in words; do body; doneREPL. - exectry
- Port of
exectry(Estate state, int do_exec)fromSrc/loop.c:735-798.{ try } always { finally }: capture errflag/retflag/breaks/contflag from the try-clause, reset them around the always-clause, then restore if always-clause didn’t override. - execwhile
- Port of
execwhile(Estate state, UNUSED(int do_exec))fromSrc/loop.c:413-498.while/until cond; do body; done. - selectlist
- Select-menu display.
Port of
selectlist(LinkList l, size_t start)from Src/loop.c:347 — formats the numbered menu the C source uses forselect var in words. Picks columns automatically whencolumns == 0, mirroring the C source’s terminal-width auto-detection. WARNING: param names don’t match C — Rust=(items, start) vs C=(l, start)