Move reduction of values into separate method
This commit is contained in:
parent
b967fa1911
commit
040ab11873
@ -164,25 +164,7 @@ impl<'a> Reducer<'a> {
|
|||||||
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
||||||
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
||||||
PrefixExp(op, arg) => self.prefix(op, arg),
|
PrefixExp(op, arg) => self.prefix(op, arg),
|
||||||
Value(qualified_name) => {
|
Value(qualified_name) => self.value(qualified_name),
|
||||||
let ref id = qualified_name.id;
|
|
||||||
let ref sym_name = match symbol_table.get_fqsn_from_id(id) {
|
|
||||||
Some(fqsn) => fqsn,
|
|
||||||
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
|
|
||||||
};
|
|
||||||
//TODO this probably needs to change
|
|
||||||
let FullyQualifiedSymbolName(ref v) = sym_name;
|
|
||||||
let name = v.last().unwrap().name.clone();
|
|
||||||
match symbol_table.lookup_by_fqsn(&sym_name) {
|
|
||||||
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::Constructor {
|
|
||||||
type_name: type_name.clone(),
|
|
||||||
name: name.clone(),
|
|
||||||
tag: index.clone(),
|
|
||||||
arity: type_args.len(),
|
|
||||||
},
|
|
||||||
_ => Expr::Sym(name.clone()),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Call { f, arguments } => self.reduce_call_expression(f, arguments),
|
Call { f, arguments } => self.reduce_call_expression(f, arguments),
|
||||||
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| self.expression(e)).collect()),
|
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| self.expression(e)).collect()),
|
||||||
IfExpression { discriminator, body } => self.reduce_if_expression(deref_optional_box(discriminator), body),
|
IfExpression { discriminator, body } => self.reduce_if_expression(deref_optional_box(discriminator), body),
|
||||||
@ -195,6 +177,28 @@ impl<'a> Reducer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn value(&mut self, qualified_name: &QualifiedName) -> Expr {
|
||||||
|
let symbol_table = self.symbol_table;
|
||||||
|
let ref id = qualified_name.id;
|
||||||
|
let ref sym_name = match symbol_table.get_fqsn_from_id(id) {
|
||||||
|
Some(fqsn) => fqsn,
|
||||||
|
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
|
||||||
|
};
|
||||||
|
|
||||||
|
//TODO this probably needs to change
|
||||||
|
let FullyQualifiedSymbolName(ref v) = sym_name;
|
||||||
|
let name = v.last().unwrap().name.clone();
|
||||||
|
match symbol_table.lookup_by_fqsn(&sym_name) {
|
||||||
|
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::Constructor {
|
||||||
|
type_name: type_name.clone(),
|
||||||
|
name: name.clone(),
|
||||||
|
tag: index.clone(),
|
||||||
|
arity: type_args.len(),
|
||||||
|
},
|
||||||
|
_ => Expr::Sym(name.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn reduce_lambda(&mut self, params: &Vec<FormalParam>, body: &Block) -> Expr {
|
fn reduce_lambda(&mut self, params: &Vec<FormalParam>, body: &Block) -> Expr {
|
||||||
Expr::Func(Func::UserDefined {
|
Expr::Func(Func::UserDefined {
|
||||||
name: None,
|
name: None,
|
||||||
|
Loading…
Reference in New Issue
Block a user