lang::core_eval
lang/src/core_eval.mo
pub type CoreEvalError {
/// A `local i` with no matching environment frame -- an internal
/// lowering bug, not a normal runtime condition.
ce_unbound_local (idx : I64),
/// A `global i` past the end of `GlobalTable` -- also an internal
/// lowering bug.
ce_unknown_global (idx : I64),
/// A `global` slot recorded as `gd_unresolved` (a known,
/// already-diagnosed gap) was actually forced at runtime.
ce_unresolved_global (path : ModulePath),
/// Applied a `Value` that isn't a function, constructor, or native --
/// only `v_lit` can reach this.
ce_not_a_function (v : Value) (arg : Value),
/// A `match_` scrutinee reduced to something other than `v_con`.
ce_not_a_constructor (v : Value),
/// A `match_`'s scrutinee tag has no corresponding arm -- an internal
/// lowering bug (`match_` should have one arm per constructor of the
/// scrutinee's inductive).
ce_case_index_out_of_bounds (tag : I64),
/// A matched constructor's field count didn't match its arm's declared
/// `bind_count` -- another internal-invariant violation.
ce_arity_mismatch (expected : I64) (got : I64),
/// Forcing a global re-entered its own still-in-progress slot -- a
/// genuine reference cycle.
ce_cycle (idx : I64),
/// A `ntv`/`v_partial_ntv` referenced a `native_id` with no entry in
/// `NativeTable` -- an internal lowering bug.
ce_unknown_native (id : I64),
/// The evaluator's step budget (`eval_fueled`) ran out. Not an internal
/// bug: the browser REPL uses it to stop a runaway program without
/// freezing the page.
ce_out_of_fuel,
/// More than `max_call_depth` nested user calls, on a cache that carries
/// that limit (only `eval_fueled` does). The wasm stack would trap a few
/// hundred frames later, so this reports cleanly first.
ce_recursion_too_deep,
/// A native fired with the wrong number or shape of arguments.
ce_native_arg_error (msg : String),
/// A `match` with no wildcard, and no case for `ctor` either, actually
/// produced a value of `ctor` at runtime.
ce_non_exhaustive_match (inductive : ModulePath) (ctor : Identifier),
}pub def eval
(ir : CoreIr) (env : Env) (globals : GlobalTable) (natives : NativeTable)
(cache : GlobalCache)
: Pair (Result CoreEvalError Value) GlobalCacheThe public entry point: same behavior as before the outcome-type
refactor, with the Pair/Result built once at the top.
pub def eval_fueled
(fuel : I64) (ir : CoreIr) (globals : GlobalTable) (natives : NativeTable)
: Pair (Result CoreEvalError Value) GlobalCacheEvaluate with an explicit step budget. fuel < 0 is unlimited; any
other value burns one step per IR node and fails with
ce_out_of_fuel when it reaches zero. The browser REPL's engine is the
only finite caller; monad eval and the meta-evaluator use eval.
The budget comes with a nesting cap: a finite caller has a fixed stack
(the web profile's 32 MiB) that fuel does not bound, so the cache
carries max_call_depth as well. Plain eval leaves that cap off --
the compiler's own meta-evaluator runs well past it.
pub def max_call_depth : I64The most nested user calls eval_fueled allows. Measured on the web
profile: ~120 KiB of wasm stack per user call (the self-hosted codegen
gives eval a large frame), and 32 MiB holds about 250 sum-shaped
calls. The stack trap is not catchable, so this counter stops at 200 --
comfortably below the measured ceiling -- and reports cleanly instead of
trapping. Only the browser REPL's cache carries this limit; the plain
eval entry points do not (see eval_fueled).
pub def basic_native_table : NativeTableThe native table every lowering/interpretation path builds. Ids are
positions in native_specs; lang/lower_core_ir.mo uses
native_id_for_name directly, so a new native is added in ONE place.
pub def native_id_for_name (name : Identifier) : Option I64