gsh/evaluator/evaluator

The evaluator module is the core module of the GSH REPL.

Because Gleam is statically typed and compiled, we cannot evaluate raw AST dynamically like Elixir’s IEx. Instead, this module acts as a synthetic runtime, taking the user’s input, injecting historical state (imports, bindings, types, functions), and generating a unique gsh_eval_X.gleam file for execution.

Key Capabilities:

Values

pub fn evaluate(
  input: String,
  bindings: List(binding.Binding),
  imports: List(String),
  types: List(String),
  functions: List(String),
  debug: Bool,
  prompt_count: Int,
) -> result.Evaluation

The primary orchestration engine for REPL input execution.

Execution Pipeline:

  1. Lexical Analysis: Scans the raw string to intercept syntax errors (e.g., open strings) and strips whitespace/comments to correctly route the syntax tree.
  2. Code Generation: Passes the tokens to the appropriate source builder and recursively injects the historical ShellState variables to maintain lexical scope.
  3. Compilation: Writes the generated code to a unique file in test/ and triggers the runner for background compilation and VM execution.
  4. Cleanup & State: Deletes the temporary file, calculates execution latency for debug logs, and returns the extracted definitions so the REPL can update its active state.
Search Document