Expand description
Shell executor state for zshrs.
Not a port of Src/exec.c. C zsh runs compiled programs on the native
wordcode VM in Src/exec.c (execlist / execpline / execcmd).
zshrs uses fusevm bytecode instead; the bridge lives in src/fusevm_bridge.rs.
This file holds:
ShellExecutor— the runtime state struct that the VM and every ported builtin/utility threads through- VM-adjacent helpers that read/write that state
- drift extension scaffolding still being moved out
Path-wise this file lives at the crate root (src/exec.rs) rather
than in src/ported/ because nothing here corresponds 1:1 to a
Src/*.c source file. crate::ported::exec is kept as a
re-export alias so existing call-sites continue to compile.
Re-exports§
pub use crate::ported::params::convbase as format_int_in_base;pub use crate::ported::params::convbase_underscore;pub use crate::intercepts::AdviceKind;pub use crate::intercepts::Intercept;pub use crate::compinit_bg::CompInitBgResult;pub use crate::bash_complete::CompSpec;pub use crate::bash_complete::CompMatch;pub use crate::bash_complete::CompGroup;pub use crate::bash_complete::CompState;pub use crate::ported::modules::zutil::zstyle_entry;pub use crate::ported::builtin::AutoloadFlags;pub use crate::fusevm_bridge::*;
Modules§
- zsh_
version ZSH_VERSION/ZSH_PATCHLEVEL/ZSH_VERSION_DATEconsts generated bybuild.rsfromsrc/zsh/Config/version.mk. Usezsh_version::ZSH_VERSIONetc. at call sites so version bumps pick up automatically.
Structs§
- Fork
Flags - Flags for zfork()
- Shell
Executor - Top-level shell executor state.
Port of the file-static globals +
Estatechain Src/exec.c uses —execlist()(line 1349) drives every list, withexecpline()(line 1668),execpline2()(line 1991),execsimple()(line 1290), and the per-WC_*execfuncs[]table (line 268) feeding off it. The Rust port collapses everything into oneShellExecutorso we don’t need thread-local globals. - Subshell
Flags - Flags for entersubsh()
- Subshell
Snapshot - Snapshot of subshell-isolated state. Captured at
(entry, restored at)exit. zsh subshell semantics: assignments inside(…)don’t leak to the outer scope — and that includesexport. zsh forks a child for the subshell so the child’s env::set_var dies with the child; without a fork (zshrs runs subshells in-process for perf), we snapshot+restore the OS env table around the subshell. Otherwise(export y=v)would leakyto the parent shell, breaking every script that uses a subshell to scope an env override. Snapshot of mutable executor state across a subshell boundary. Port of theentersubsh()save/restore Src/exec.c does at line 1084 — captures everything that must be replaced when a(...)group fires.
Enums§
- Builtin
Type - Builtin command type
Builtin classification.
Mirrors the
BINF_*flag set Src/builtin.c uses to classify special vs regular builtins. - Fork
Result - Result of fork operation
fork()outcome (parent / child / error). Mirrors the integer return ofzfork()from Src/exec.c:349. - Loop
Signal - Cross-VM loop-control signal. When
break/continueis hit inside a body that runs on a sub-VM (e.g. select’s body), the inline patches mechanism can’t reach the outer loop — set this flag and the outer-loop builtin drains it after each iteration. Loop control signal from a command body. Mirrors theLF_*set Src/loop.c uses to threadbreak/continue/returnflags up through the executor. - Redir
Mode - Redirection mode
File-redirection mode (
>/>>/</ etc.). Mirrors theREDIR_*enum from Src/zsh.h.
Statics§
- FORKLEVEL
- Port of
int forklevel;fromSrc/exec.c:1052. Records thelocallevelat the most recent fork point (set at c:1221:forklevel = locallevel;insideentersubsh()). Used by: - TRAP_
RETURN - Port of
int trap_return;fromSrc/exec.c:155. Carries the pending exit status from inside a trap; sentinel-2means “running an EXIT/DEBUG-style trap at the current level” (signals.c:1166). Promoted to the user’sreturn Nvalue bybin_returnwhen POSIX-trap semantics apply (builtin.c:5852). - TRAP_
STATE - Port of
int trap_state;fromSrc/exec.c:134. Tracks whether a trap handler is currently being processed and, paired withTRAP_RETURNbelow, whether areturninside the trap should promote toTRAP_STATE_FORCE_RETURNto unwind the trap caller.
Functions§
- getfpfunc
- Port of
getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only)from Src/exec.c:5260. Walks$fpath(or the suppliedspec_pathslice) for a file namednameand writes the resolved directory through*dir_path_out(matching the Cchar **dir_path). ReturnsSome(file_contents_path)on success,Nonewhen not found. - gethere
- Convert a here-document into a here-string. Line-by-line port of
gethere()fromSrc/exec.c:4569-4652. Reads the body from the input stream viahgetc()until the terminator line is matched, returning the collected body as a string.strpis in/out: on entry the raw terminator (possibly with token markers + leading tabs); on return the munged terminator (afterquotesubst+untokenizeand, forREDIR_HEREDOCDASH, leading-tab strip). - getoutput
- Free-function wrapper for
getoutput()fromSrc/exec.c:4712. Runs a command-substitution body in the active executor and returns its captured stdout. The C signature isLinkList getoutput(char *cmd, int qt)but every caller in subst.rs joins the list back into a string, so the Rust port collapses the intermediate. - glob_
match_ static - Static glob match — same logic as glob_match but callable without &self, needed for Rayon parallel iterators that can’t capture &self.
- loadautofn
- Direct port of
Shfunc loadautofn(Shfunc shf, int ks, int test_only, int ignore_loaddir)fromSrc/exec.c:5050. Walks$fpathfor a file namedshf->node.nam, reads it, installs the text body on the correspondingshfunctabentry, and clearsPM_UNDEFINED. - scan_
magic_ assoc_ keys