9afde5a301
This commit introduces support for tuple and map literals in the AST. Tuples are now represented by `UntypedKind::Tuple` and maps by `UntypedKind::Map`. The `Binder` has been updated to correctly handle these new node types and infer their types. The `VM` now also supports evaluating tuple and map literals.
55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
use std::rc::Rc;
|
|
use std::fmt::Debug;
|
|
use crate::ast::types::{Identity, Value};
|
|
|
|
/// A generic AST Node wrapper to preserve identity and metadata
|
|
#[derive(Debug, Clone)]
|
|
pub struct Node<K, T = ()> {
|
|
pub identity: Identity,
|
|
pub kind: K,
|
|
pub ty: T,
|
|
}
|
|
|
|
/// The base for custom node types (extensions)
|
|
pub trait CustomNode: Debug {
|
|
fn display_name(&self) -> &'static str;
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum UntypedKind {
|
|
Nop,
|
|
Constant(Value),
|
|
Identifier(Rc<str>),
|
|
If {
|
|
cond: Box<Node<UntypedKind>>,
|
|
then_br: Box<Node<UntypedKind>>,
|
|
else_br: Option<Box<Node<UntypedKind>>>,
|
|
},
|
|
Def {
|
|
name: Rc<str>,
|
|
value: Box<Node<UntypedKind>>,
|
|
},
|
|
Assign {
|
|
target: Box<Node<UntypedKind>>,
|
|
value: Box<Node<UntypedKind>>,
|
|
},
|
|
Lambda {
|
|
params: Vec<Rc<str>>,
|
|
body: Rc<Node<UntypedKind>>,
|
|
},
|
|
Call {
|
|
callee: Box<Node<UntypedKind>>,
|
|
args: Vec<Node<UntypedKind>>,
|
|
},
|
|
Block {
|
|
exprs: Vec<Node<UntypedKind>>,
|
|
},
|
|
Tuple {
|
|
elements: Vec<Node<UntypedKind>>,
|
|
},
|
|
Map {
|
|
entries: Vec<(Node<UntypedKind>, Node<UntypedKind>)>,
|
|
},
|
|
Extension(Box<dyn CustomNode>),
|
|
}
|