More work on pattern-matching

I think I need to entirely change the types in the evaluator.
ReducedAST should only care about NewConstructor (which I gotta rename),
and the evaluator is the only place that an implementation of a
primitive constructed type should live (see Peyton-Jones implementing a
functional langauge p. 70)
This commit is contained in:
greg 2018-08-05 19:11:42 -07:00
parent 5f336ec1a9
commit 348a6f7c76

View File

@ -1,6 +1,6 @@
use std::rc::Rc;
use ast::{AST, Statement, Expression, Declaration, Discriminator, IfExpressionBody, Pattern};
use ast::{AST, Statement, Expression, Declaration, Discriminator, IfExpressionBody, Pattern, PatternLiteral};
use symbol_table::{Symbol, SymbolSpec, SymbolTable};
use builtin::{BinOp, PrefixOp};
@ -159,23 +159,28 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
};
/*
let alternatives = match pat {
let first_alt: Alternative = match pat {
Pattern::TupleStruct(name, subpatterns) => {
let symbol = symbol_table.values.get(name).unwrap();
unimplemented!()
let tag = match symbol.spec {
SymbolSpec::DataConstructor { index, .. } => index.clone(),
_ => panic!("Bad symbol"),
};
let bound_vars = subpatterns.iter().flat_map(|p| match p {
Pattern::Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
_ => None,
}).collect();
Alternative {
tag: Some(tag),
bound_vars,
item: then_clause,
}
},
_ => panic!()
};
*/
let alternatives = vec![
Alternative {
tag: Some(0),
bound_vars: vec![],
item: then_clause,
},
first_alt,
Alternative {
tag: None,
bound_vars: vec![],