Move reduction of values into separate method

This commit is contained in:
greg 2019-11-07 03:28:18 -08:00
parent b967fa1911
commit 040ab11873

View File

@ -164,12 +164,27 @@ 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),
Call { f, arguments } => self.reduce_call_expression(f, arguments),
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| self.expression(e)).collect()),
IfExpression { discriminator, body } => self.reduce_if_expression(deref_optional_box(discriminator), body),
Lambda { params, body, .. } => self.reduce_lambda(params, body),
NamedStruct { name, fields } => self.reduce_named_struct(name, fields),
Index { .. } => Expr::UnimplementedSigilValue,
WhileExpression { .. } => Expr::UnimplementedSigilValue,
ForExpression { .. } => Expr::UnimplementedSigilValue,
ListLiteral { .. } => Expr::UnimplementedSigilValue,
}
}
fn value(&mut self, qualified_name: &QualifiedName) -> Expr {
let symbol_table = self.symbol_table;
let ref id = qualified_name.id; let ref id = qualified_name.id;
let ref sym_name = match symbol_table.get_fqsn_from_id(id) { let ref sym_name = match symbol_table.get_fqsn_from_id(id) {
Some(fqsn) => fqsn, Some(fqsn) => fqsn,
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)), None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
}; };
//TODO this probably needs to change //TODO this probably needs to change
let FullyQualifiedSymbolName(ref v) = sym_name; let FullyQualifiedSymbolName(ref v) = sym_name;
let name = v.last().unwrap().name.clone(); let name = v.last().unwrap().name.clone();
@ -182,17 +197,6 @@ impl<'a> Reducer<'a> {
}, },
_ => Expr::Sym(name.clone()), _ => Expr::Sym(name.clone()),
} }
},
Call { f, arguments } => self.reduce_call_expression(f, arguments),
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| self.expression(e)).collect()),
IfExpression { discriminator, body } => self.reduce_if_expression(deref_optional_box(discriminator), body),
Lambda { params, body, .. } => self.reduce_lambda(params, body),
NamedStruct { name, fields } => self.reduce_named_struct(name, fields),
Index { .. } => Expr::UnimplementedSigilValue,
WhileExpression { .. } => Expr::UnimplementedSigilValue,
ForExpression { .. } => Expr::UnimplementedSigilValue,
ListLiteral { .. } => Expr::UnimplementedSigilValue,
}
} }
fn reduce_lambda(&mut self, params: &Vec<FormalParam>, body: &Block) -> Expr { fn reduce_lambda(&mut self, params: &Vec<FormalParam>, body: &Block) -> Expr {