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:
- Token Routing: Uses
glexerto parse input and accurately classify the statement (import, type, function, binding, or raw expression). - Side-Effect Caching: Wraps every variable assignment in an Erlang Process Dictionary
check, ensuring side effects (like
io.println) execute exactly once per session even as the file is continually recompiled. - Cache Collision Prevention: Appends the
prompt_countto module names to guarantee the Erlang VM loads fresh bytecode from disk on every execution.
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