Add guard to Alternative

The semantics are:
    -if tag is Some(_), assume the condition is a constructor,
    and compare tags
    - if guard is Some(_), evaluate true/false *after* having
    applied any bound variables

With this, I can technically get rid of bare conditionals now, since
they are the same as an Alternative with a None tag
This commit is contained in:
greg 2018-08-27 12:45:08 -07:00
parent 065bdd6bda
commit 1abbe2e448
1 changed files with 3 additions and 0 deletions

View File

@ -58,6 +58,7 @@ pub enum Expr {
#[derive(Debug, Clone)]
pub struct Alternative {
pub tag: Option<usize>,
pub guard: Option<Expr>,
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
pub item: Vec<Stmt>,
}
@ -159,6 +160,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
pat.to_alternative(then_clause, symbol_table),
Alternative {
tag: None,
guard: None,
bound_vars: vec![],
item: else_clause,
},
@ -201,6 +203,7 @@ impl Pattern {
}).collect();
Alternative {
tag: Some(tag),
guard: None,
bound_vars,
item,
}