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:
parent
5f336ec1a9
commit
348a6f7c76
@ -1,6 +1,6 @@
|
|||||||
use std::rc::Rc;
|
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 symbol_table::{Symbol, SymbolSpec, SymbolTable};
|
||||||
use builtin::{BinOp, PrefixOp};
|
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(),
|
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
let first_alt: Alternative = match pat {
|
||||||
let alternatives = match pat {
|
|
||||||
Pattern::TupleStruct(name, subpatterns) => {
|
Pattern::TupleStruct(name, subpatterns) => {
|
||||||
let symbol = symbol_table.values.get(name).unwrap();
|
let symbol = symbol_table.values.get(name).unwrap();
|
||||||
|
let tag = match symbol.spec {
|
||||||
unimplemented!()
|
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!()
|
_ => panic!()
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
let alternatives = vec![
|
let alternatives = vec![
|
||||||
Alternative {
|
first_alt,
|
||||||
tag: Some(0),
|
|
||||||
bound_vars: vec![],
|
|
||||||
item: then_clause,
|
|
||||||
},
|
|
||||||
Alternative {
|
Alternative {
|
||||||
tag: None,
|
tag: None,
|
||||||
bound_vars: vec![],
|
bound_vars: vec![],
|
||||||
|
Loading…
Reference in New Issue
Block a user