WIP
This commit is contained in:
parent
7548bdbb78
commit
1e7f5bbd25
@ -24,14 +24,14 @@ pub enum Stmt {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Expr {
|
||||
Unit,
|
||||
Lit(Lit),
|
||||
Tuple(Vec<Expr>),
|
||||
Func(Func),
|
||||
Val(Rc<String>),
|
||||
Tuple(Vec<Expr>),
|
||||
Constructor {
|
||||
name: Rc<String>,
|
||||
variant: usize,
|
||||
expr: Box<Expr>,
|
||||
},
|
||||
Val(Rc<String>),
|
||||
Call {
|
||||
f: Box<Expr>,
|
||||
args: Vec<Expr>,
|
||||
@ -52,6 +52,10 @@ pub enum Expr {
|
||||
UnimplementedSigilValue
|
||||
}
|
||||
|
||||
pub enum Pat {
|
||||
Ignored
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Lit {
|
||||
Nat(u64),
|
||||
@ -83,7 +87,7 @@ impl AST {
|
||||
}
|
||||
|
||||
impl Statement {
|
||||
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
||||
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
||||
use ast::Statement::*;
|
||||
match self {
|
||||
ExpressionStatement(expr) => Stmt::Expr(expr.reduce(symbol_table)),
|
||||
@ -103,10 +107,12 @@ impl Expression {
|
||||
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
||||
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
||||
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
||||
//remember Some(5) is a CallExpr
|
||||
// => ast: Ok(AST([ExpressionStatement(Expression(Call { f: Expression(Value("Some"), None), arguments: [Expression(NatLiteral(5), None)] }, None))]))
|
||||
Value(name) => {
|
||||
match symbol_table.values.get(name) {
|
||||
Some(Symbol { spec: SymbolSpec::DataConstructor { type_args, .. }, .. }) => {
|
||||
Expr::Constructor { name: name.clone() }
|
||||
Expr::Constructor { type_name: name.clone() }
|
||||
},
|
||||
_ => Expr::Val(name.clone()),
|
||||
}
|
||||
@ -154,6 +160,18 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
||||
}
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
fn reduce(&self, symbol_table: &SymbolTable) -> Pat {
|
||||
match self {
|
||||
Pattern::Ignored => Pat::Ignored,
|
||||
Pattern::TuplePattern(_) => panic!(),
|
||||
Pattern::Literal(_) => panic!(),
|
||||
Pattern::TupleStruct(_, _) => panic!(),
|
||||
Pattern::Record(_, _) => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Declaration {
|
||||
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
||||
use self::Declaration::*;
|
||||
|
Loading…
Reference in New Issue
Block a user