From 2609dd404a8dc6fe9c719aa3e5ef646aa634ad2b Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 18 Oct 2021 23:10:50 -0700 Subject: [PATCH] Tighten up reduced_ast code a bit --- schala-lang/language/src/reduced_ast.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index b3a9a6c..481ec9a 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -178,9 +178,8 @@ 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) { + let ref sym_name = match self.symbol_table.get_fqsn_from_id(id) { Some(fqsn) => fqsn, None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)), }; @@ -189,7 +188,7 @@ impl<'a> Reducer<'a> { let FullyQualifiedSymbolName(ref v) = sym_name; let name = v.last().unwrap().name.clone(); - let Symbol { local_name, spec, .. } = match symbol_table.lookup_by_fqsn(&sym_name) { + let Symbol { local_name, spec, .. } = match self.symbol_table.lookup_by_fqsn(&sym_name) { Some(s) => s, //None => return Expr::ReductionError(format!("Symbol {:?} not found", sym_name)), None => return Expr::Sym(name.clone()) @@ -218,15 +217,14 @@ impl<'a> Reducer<'a> { } fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc, Expression)>) -> Expr { - let symbol_table = self.symbol_table; - let ref sym_name = match symbol_table.get_fqsn_from_id(&name.id) { + let ref sym_name = match self.symbol_table.get_fqsn_from_id(&name.id) { Some(fqsn) => fqsn, None => return Expr::ReductionError(format!("FQSN lookup for name {:?} failed", name)), }; let FullyQualifiedSymbolName(ref v) = sym_name; let ref name = v.last().unwrap().name; - let (type_name, index, members_from_table) = match symbol_table.lookup_by_fqsn(&sym_name) { + let (type_name, index, members_from_table) = match self.symbol_table.lookup_by_fqsn(&sym_name) { Some(Symbol { spec: SymbolSpec::RecordConstructor { members, type_name, index }, .. }) => (type_name.clone(), index, members), _ => return Expr::ReductionError("Not a record constructor".to_string()), }; @@ -254,7 +252,6 @@ impl<'a> Reducer<'a> { } fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr { - let symbol_table = self.symbol_table; let cond = Box::new(match discriminator { Some(expr) => self.expression(expr), None => return Expr::ReductionError(format!("blank cond if-expr not supported")), @@ -277,7 +274,7 @@ impl<'a> Reducer<'a> { }; let alternatives = vec![ - pattern.to_alternative(then_clause, symbol_table), + pattern.to_alternative(then_clause, self.symbol_table), Alternative { matchable: Subpattern { tag: None, @@ -303,7 +300,7 @@ impl<'a> Reducer<'a> { }, Condition::Pattern(ref p) => { let item = self.block(&arm.body); - let alt = p.to_alternative(item, symbol_table); + let alt = p.to_alternative(item, self.symbol_table); alternatives.push(alt); }, Condition::TruncatedOp(_, _) => {