Make code more concise

This commit is contained in:
greg 2018-08-07 17:09:53 -07:00
parent 5ead1e5d44
commit f9c2fc3f9d

View File

@ -116,8 +116,7 @@ impl Expression {
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)), BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs), BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
PrefixExp(op, arg) => op.reduce(symbol_table, arg), PrefixExp(op, arg) => op.reduce(symbol_table, arg),
Value(name) => { Value(name) => match symbol_table.lookup_by_name(name) {
match symbol_table.lookup_by_name(name) {
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::Constructor { Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::Constructor {
type_name: type_name.clone(), type_name: type_name.clone(),
name: name.clone(), name: name.clone(),
@ -125,7 +124,6 @@ impl Expression {
arity: type_args.len(), arity: type_args.len(),
}, },
_ => Expr::Val(name.clone()), _ => Expr::Val(name.clone()),
}
}, },
Call { f, arguments } => Expr::Call { Call { f, arguments } => Expr::Call {
f: Box::new(f.reduce(symbol_table)), f: Box::new(f.reduce(symbol_table)),