JustBash.Interpreter.State (JustBash v0.4.0)

View Source

Internal 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 a while/until loop body. The read builtin consumes it line by line, updating the remainder each iteration.

  • locals — a MapSet of variable names declared local inside the currently executing function. Used by execute_function to revert those variables to their caller values when the function returns.

  • assoc_arrays — a MapSet of 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.

  • deadline — the JustBash.Limit.Deadline armed by the current top-level JustBash.exec/2, or nil when limits are disabled. Checked by the statement loop so a script that burns wall clock without doing countable work still terminates.

  • call_depth — current shell function call depth. Incremented on each function entry, restored to the caller's depth on return. Checked against bash.max_call_depth to 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

Functions

Arm the wall clock deadline for a new top-level execution.

Returns a fresh interpreter state.

Reset per-exec counters for a new top-level execution.

Types

t()

@type t() :: %JustBash.Interpreter.State{
  assoc_arrays: MapSet.t(String.t()),
  call_depth: non_neg_integer(),
  deadline: JustBash.Limit.Deadline.t() | nil,
  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()
}

Functions

arm_deadline(state, deadline)

@spec arm_deadline(t(), JustBash.Limit.Deadline.t() | nil) :: t()

Arm the wall clock deadline for a new top-level execution.

new()

@spec new() :: t()

Returns a fresh interpreter state.

reset_counters(state)

@spec reset_counters(t()) :: t()

Reset per-exec counters for a new top-level execution.