Skip to main content

Module loop

Module loop 

Source
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_errflag from Src/loop.c:719. Initialized to -1 (sentinel: “no try block has fired yet in this scope”); the exectry always-arm sets it to errflag & ERRFLAG_ERROR before running the always body, then restores. TRY_BLOCK_ERROR param (IPDEF6 at Src/params.c:364) reads this global directly.
try_interrupt
Port of mod_export zlong try_interrupt from Src/loop.c:727. Initialized to -1; mirrors try_errflag for the ERRFLAG_INT bit. TRY_BLOCK_INTERRUPT param reads this.
try_tryflag
Port of mod_export zlong try_tryflag from Src/loop.c:731. Depth-counter for active always {} blocks; bumped at try entry (exectry), decremented at exit. dotrapargs (signals.c:1215) reads it to decide whether a trap’s errflag propagates.

Functions§

execcase
Port of execcase(Estate state, int do_exec) from Src/loop.c:600-733. case word in pat) body ;; ... esac with ;;/;&/;| separators.
execfor
Port of execfor(Estate state, int do_exec) from Src/loop.c:50-202. for var in args; do body; done and the C-style for ((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) from Src/loop.c:553-598. if cond; then body; elif ...; else ...; fi.
execrepeat
Port of execrepeat(Estate state, UNUSED(int do_exec)) from Src/loop.c:499-551. repeat N; do body; done.
execselect
Port of execselect(Estate state, UNUSED(int do_exec)) from Src/loop.c:217-410. select var in words; do body; done REPL.
exectry
Port of exectry(Estate state, int do_exec) from Src/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)) from Src/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 for select var in words. Picks columns automatically when columns == 0, mirroring the C source’s terminal-width auto-detection. WARNING: param names don’t match C — Rust=(items, start) vs C=(l, start)