Start implementing constructors/matches
as per Implementing Functional Programming Languages by Peyton-Jones
This commit is contained in:
parent
42d0aba21c
commit
c637a922a9
@ -29,6 +29,11 @@ pub enum Expr {
|
|||||||
Tuple(Vec<Expr>),
|
Tuple(Vec<Expr>),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
Val(Rc<String>),
|
Val(Rc<String>),
|
||||||
|
NewConstructor {
|
||||||
|
type_name: Rc<String>,
|
||||||
|
tag: usize,
|
||||||
|
arg: Box<Expression>,
|
||||||
|
},
|
||||||
Constructor {
|
Constructor {
|
||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
},
|
},
|
||||||
@ -47,11 +52,18 @@ pub enum Expr {
|
|||||||
},
|
},
|
||||||
Match {
|
Match {
|
||||||
cond: Box<Expr>,
|
cond: Box<Expr>,
|
||||||
arms: Vec<(Pattern, Vec<Stmt>)>
|
alternatives: Vec<Alternative>
|
||||||
},
|
},
|
||||||
UnimplementedSigilValue
|
UnimplementedSigilValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Alternative {
|
||||||
|
tag: usize,
|
||||||
|
bound_vars: (),
|
||||||
|
item: Vec<Stmt>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Lit {
|
pub enum Lit {
|
||||||
Nat(u64),
|
Nat(u64),
|
||||||
@ -142,11 +154,19 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
|||||||
None => vec![],
|
None => vec![],
|
||||||
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
||||||
};
|
};
|
||||||
Expr::Match {
|
Expr::Match { //TODO this still doesn't work right
|
||||||
cond,
|
cond,
|
||||||
arms: vec![
|
alternatives: vec![
|
||||||
(pat.clone(), then_clause),
|
Alternative {
|
||||||
(Pattern::Ignored, else_clause)
|
tag: 0,
|
||||||
|
bound_vars: (),
|
||||||
|
item: then_clause,
|
||||||
|
},
|
||||||
|
Alternative {
|
||||||
|
tag: 1,
|
||||||
|
bound_vars: (),
|
||||||
|
item: else_clause,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user