From 040ab11873e104388b9d125564355d4965cc7d02 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 7 Nov 2019 03:28:18 -0800 Subject: [PATCH] Move reduction of values into separate method --- schala-lang/language/src/reduced_ast.rs | 42 ++++++++++++++----------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 3e0cf65..f90347c 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -164,25 +164,7 @@ impl<'a> Reducer<'a> { BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)), BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs), PrefixExp(op, arg) => self.prefix(op, arg), - 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()), - } - }, + 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), @@ -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, body: &Block) -> Expr { Expr::Func(Func::UserDefined { name: None,