lang::core_value

lang/src/core_value.mo

typeEnv#
pub type Env {
    env_nil,
    env_cons (v : Value) (rest : Env),
    /// A match arm's constructor fields, in declaration order, sharing the
    /// scrutinee's own `args` list. `count` is its length; `local 0` is the
    /// LAST declared field, matching the old one-`env_cons`-per-field push
    /// order. One node replaces `count` cons cells.
    env_frame (count : I64) (vals : List Value) (rest : Env),
}

A persistent (immutable, shared-tail) cons-list environment, indexed the same way CoreIr.local/Term.var are: 0 = innermost (most recently bound). A plain cons-list, not a BTreeMap/HashMap — deliberately: see AGENTS.md's "Known Type Checker Issues" #4, which measured BTreeMap as ~25x slower than List+linear-scan for the small collection sizes typical of this self-hosted interpreter's own code. An environment stack is exactly that shape.

typeValue#
pub type Value {
    /// Scalar literals reuse `core_ir.IrLit` directly.
    v_lit (l : IrLit),
    /// What a `lam` evaluates to: the still-unevaluated body plus the
    /// environment it closes over.
    v_closure (body : CoreIr) (env : Env),
    /// A fully- or partially-applied constructor. `args`'s length is
    /// `<= arity` (arity itself lives on the `con`/`GlobalDef` node that
    /// produced this, not duplicated here); application appends to `args`
    /// left-to-right.
    v_con (tag : I64) (args : List Value),
    /// A native/builtin call with some but not all of its arguments
    /// supplied yet.
    v_partial_ntv (native_id : I64) (args : List Value),
}

A runtime value. Distinct from CoreIr (the compiled syntax it's reduced from) on purpose — a value here is always already in normal form, never a still-to-be-reduced expression.

typeGlobalTable#
pub type GlobalTable {
    global_table (globals : List GlobalDef),
}
defglobal_table_len#
pub def global_table_len (table : GlobalTable) : I64
defglobal_cache_new#
pub def global_cache_new (len : I64) : GlobalCache
defglobal_cache_new_fueled#
pub def global_cache_new_fueled (len : I64) (fuel : I64) (depth_limit : I64) : GlobalCache

The same cache with a finite step budget and a nesting limit (see GlobalCache's own notes on fuel and depth_limit). lang/core_eval.mo's eval_fueled is the entry point.

defglobal_cache_fuel#
pub def global_cache_fuel (cache : GlobalCache) : I64
defglobal_cache_with_fuel#
pub def global_cache_with_fuel (cache : GlobalCache) (fuel : I64) : GlobalCache
defglobal_cache_depth#
pub def global_cache_depth (cache : GlobalCache) : I64

The interpreter's current call depth (lang/core_eval.mo's apply). The fuel budget bounds steps, not frames, so this is the only thing that can turn a would-be wasm stack trap into a clean error.

defglobal_cache_depth_limit#
pub def global_cache_depth_limit (cache : GlobalCache) : I64

The call-depth cap, or -1 for unlimited (every caller but the browser REPL). See GlobalCache's note on depth_limit.

defglobal_cache_with_depth#
pub def global_cache_with_depth (cache : GlobalCache) (depth : I64) : GlobalCache