lambda-throw-cat
Lambda calculus with records, prototype chains, ref cells, a tracing garbage collector, and non-local control flow via throw and try/catch. Built on comp-cat-rs.
This is spike 4 of a comp-cat-rs reformulation of a web engine targeting Tauri. Spike 1 (lambda-cat) was the pure interpreter, spike 2 (lambda-ref-cat) added a persistent heap and GC, spike 3 (lambda-obj-cat) added the object model with prototype chains. Spike 4 adds the last runtime feature distinctive to JavaScript-shaped languages before the spec-scale work of boa-cat: throwable exceptions that unwind through every existing reduction form without using mutation, panics, or interior mutability.
Grammar
expr ::= seq_expr
seq_expr ::= right_expr (";" right_expr)*
right_expr ::= lambda | let | fix | extend | throw_expr | try_expr | assign_expr
lambda ::= "\" ident "." expr
let ::= "let" ident "=" expr "in" expr
fix ::= "fix" ident "." expr
extend ::= "extend" atom object_lit
throw_expr ::= "throw" right_expr
try_expr ::= "try" right_expr "catch" ident "." right_expr
assign_expr ::= app_expr (":=" right_expr)?
app_expr ::= atom atom*
atom ::= base_atom ("." ident)*
base_atom ::= ident | "(" expr ")" | "ref" atom | "!" atom | object_lit
object_lit ::= "{" props? "}"
props ::= property ("," property)*
property ::= ident "=" right_expr
ident ::= [a-zA-Z_][a-zA-Z0-9_]*
throw eevaluateseand unwinds with the resulting value.try body catch x. handlerevaluatesbody; if it unwinds, bindsxto the thrown value and evaluateshandler.- An uncaught
throwat the top surfaces asError::UncaughtException. - Heap mutations made before a
throware visible to the catch handler.
Usage
#
How exception flow stays pure
Every reduction step returns Result<Outcome, Error>, where Outcome is Normal { value, heap, fuel } or Thrown { value, heap, fuel }. The threading helper Outcome::and_then propagates a Thrown through every combinator chain without revisiting any state; eval_try_catch is the only site that switches a Thrown back to Normal, by extending the environment with the bound catch parameter and evaluating the handler with the heap and fuel as they were at the moment of the throw.
Building
RUSTFLAGS="-D warnings"
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.