Compare commits
1 Commits
antiquated
...
fixing_con
Author | SHA1 | Date | |
---|---|---|---|
|
1e7f5bbd25 |
@ -24,14 +24,14 @@ pub enum Stmt {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
Unit,
|
|
||||||
Lit(Lit),
|
Lit(Lit),
|
||||||
Tuple(Vec<Expr>),
|
|
||||||
Func(Func),
|
Func(Func),
|
||||||
Val(Rc<String>),
|
Tuple(Vec<Expr>),
|
||||||
Constructor {
|
Constructor {
|
||||||
name: Rc<String>,
|
variant: usize,
|
||||||
|
expr: Box<Expr>,
|
||||||
},
|
},
|
||||||
|
Val(Rc<String>),
|
||||||
Call {
|
Call {
|
||||||
f: Box<Expr>,
|
f: Box<Expr>,
|
||||||
args: Vec<Expr>,
|
args: Vec<Expr>,
|
||||||
@ -52,6 +52,10 @@ pub enum Expr {
|
|||||||
UnimplementedSigilValue
|
UnimplementedSigilValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum Pat {
|
||||||
|
Ignored
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Lit {
|
pub enum Lit {
|
||||||
Nat(u64),
|
Nat(u64),
|
||||||
@ -103,10 +107,12 @@ impl Expression {
|
|||||||
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
||||||
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
||||||
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
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) => {
|
Value(name) => {
|
||||||
match symbol_table.values.get(name) {
|
match symbol_table.values.get(name) {
|
||||||
Some(Symbol { spec: SymbolSpec::DataConstructor { type_args, .. }, .. }) => {
|
Some(Symbol { spec: SymbolSpec::DataConstructor { type_args, .. }, .. }) => {
|
||||||
Expr::Constructor { name: name.clone() }
|
Expr::Constructor { type_name: name.clone() }
|
||||||
},
|
},
|
||||||
_ => Expr::Val(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 {
|
impl Declaration {
|
||||||
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
||||||
use self::Declaration::*;
|
use self::Declaration::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user