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§

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)