JustBash.Interpreter.State (JustBash v0.3.0)
View SourceInternal interpreter state carried alongside the user-visible JustBash struct.
This struct holds bookkeeping data that the interpreter needs during execution
but that must never be visible to untrusted scripts. By keeping it separate
from bash.env, scripts have no surface to observe or corrupt interpreter
internals — not through $VAR expansion, not through printenv, not through
env.
Fields
stdin— pipeline stdin passed into awhile/untilloop body. Thereadbuiltin consumes it line by line, updating the remainder each iteration.locals— aMapSetof variable names declaredlocalinside the currently executing function. Used byexecute_functionto revert those variables to their caller values when the function returns.assoc_arrays— aMapSetof variable names that have been declared as associative arrays (declare -A). Used during${arr[key]}expansion to decide whether to treat the subscript as a string key or integer index.call_depth— current shell function call depth. Incremented on each function entry, restored to the caller's depth on return. Checked againstbash.max_call_depthto prevent unbounded recursion from consuming all available memory.
Nesting
When a function is called, the interpreter saves the current State and
installs a fresh one with locals: MapSet.new(). On return, the saved state
is restored — but assoc_arrays is merged rather than discarded, since array
declarations in the outer scope must remain visible.
Summary
Types
@type t() :: %JustBash.Interpreter.State{ assoc_arrays: MapSet.t(String.t()), call_depth: non_neg_integer(), exec_depth: non_neg_integer(), halted: boolean(), locals: MapSet.t(String.t()), max_exec_depth: non_neg_integer(), output_bytes: non_neg_integer(), stdin: String.t() | nil, step_count: non_neg_integer() }