pub enum Expr {
Show 13 variants
Var(VarName),
Lam {
param: VarName,
body: Box<Expr>,
},
App {
func: Box<Expr>,
arg: Box<Expr>,
},
Let {
name: VarName,
value: Box<Expr>,
body: Box<Expr>,
},
Fix {
name: VarName,
body: Box<Expr>,
},
Ref {
inner: Box<Expr>,
},
Deref {
inner: Box<Expr>,
},
Assign {
target: Box<Expr>,
value: Box<Expr>,
},
Seq {
first: Box<Expr>,
second: Box<Expr>,
},
Object {
entries: Vec<(VarName, Expr)>,
prototype: Option<Box<Expr>>,
},
Field {
object: Box<Expr>,
name: VarName,
},
Throw {
inner: Box<Expr>,
},
TryCatch {
body: Box<Expr>,
catch_param: VarName,
handler: Box<Expr>,
},
}Expand description
The abstract syntax tree.
Variants§
Var(VarName)
Variable reference.
Lam
Lambda abstraction.
App
Function application (left-associative at the surface).
Let
Let-binding.
Fields
Fix
Fixed-point binding.
Fields
Ref
Allocate a fresh cell initialised with the value of inner.
Deref
Dereference the cell pointed to by inner.
Fields
inner: Box<Expr>The expression that must evaluate to a Value::Ref.
Assign
Assign value into the cell or property pointed to by target.
When target is a Expr::Field the assignment is to an own
property of the referenced object; otherwise it is to a cell.
Fields
Seq
Sequence: evaluate first (discarding its value), then evaluate
second and return its value.
Fields
Object
Object literal with optional prototype. Evaluating an Expr::Object
allocates a fresh object on the heap and returns a reference to it.
Fields
Field
Field access on an object. Walks the prototype chain on miss.
Throw
Throw an exception carrying the value of inner. Unwinds the
current evaluation until caught by an enclosing Expr::TryCatch.
TryCatch
Catch an exception thrown by body, binding the thrown value to
catch_param while evaluating handler.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn bind(name: impl Into<VarName>, value: Self, body: Self) -> Self
pub fn bind(name: impl Into<VarName>, value: Self, body: Self) -> Self
Build a let-binding. Named bind because let is a keyword.
Sourcepub fn object(entries: Vec<(VarName, Self)>) -> Self
pub fn object(entries: Vec<(VarName, Self)>) -> Self
Build an object literal with no prototype.
Sourcepub fn object_with_proto(entries: Vec<(VarName, Self)>, prototype: Self) -> Self
pub fn object_with_proto(entries: Vec<(VarName, Self)>, prototype: Self) -> Self
Build an object literal with a prototype expression.