From 69304de998d991c1d50291923710475581eafbfd Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 14 Oct 2021 06:52:50 -0700 Subject: [PATCH] Various refactors around symbol table --- schala-lang/language/src/schala.rs | 2 +- schala-lang/language/src/symbol_table/mod.rs | 14 +++++++------- .../src/symbol_table/{source_map.rs => tables.rs} | 0 3 files changed, 8 insertions(+), 8 deletions(-) rename schala-lang/language/src/symbol_table/{source_map.rs => tables.rs} (100%) diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index 769925b..fd210a3 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -90,7 +90,7 @@ impl Schala { // Typechecking // TODO typechecking not working let _overall_type = self.type_context.typecheck(&ast) - .map_err(|err| SchalaError::from_type_error(err)); + .map_err(SchalaError::from_type_error); // Reduce AST - TODO this doesn't produce an error yet, but probably should let symbol_table = self.symbol_table.borrow(); diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index d1fc056..09a20d9 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -23,8 +23,8 @@ macro_rules! fqsn { }; } -mod source_map; -use source_map::SourceMap; +mod tables; +use tables::SourceMap; mod symbol_trie; use symbol_trie::SymbolTrie; mod test; @@ -139,7 +139,7 @@ impl SymbolTable { #[allow(dead_code)] #[derive(Debug)] pub struct Symbol { - pub local_name: Rc, //TODO does this need to be pub? + pub local_name: Rc, fully_qualified_name: FullyQualifiedSymbolName, pub spec: SymbolSpec, } @@ -204,12 +204,12 @@ impl SymbolTable { match decl { FuncSig(ref signature) => { - seen_identifiers.try_register(&signature.name, &id, &self.source_map) + seen_identifiers.try_register(&signature.name, id, &self.source_map) .map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?; self.add_function_signature(signature, scope_name_stack)? } FuncDecl(ref signature, ref body) => { - seen_identifiers.try_register(&signature.name, &id, &self.source_map) + seen_identifiers.try_register(&signature.name, id, &self.source_map) .map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?; self.add_function_signature(signature, scope_name_stack)?; scope_name_stack.push(ScopeSegment{ @@ -234,7 +234,7 @@ impl SymbolTable { }, Statement { kind: StatementKind::Module(ModuleSpecifier { name, contents}), id, location } => { self.source_map.add_location(id, *location); - seen_modules.try_register(&name, &id, &self.source_map) + seen_modules.try_register(name, id, &self.source_map) .map_err(|line| format!("Duplicate module definition: {}. It's already defined at {}", name, line))?; scope_name_stack.push(ScopeSegment { name: name.clone() }); let output = self.add_symbols_from_scope(contents, scope_name_stack); @@ -248,7 +248,7 @@ impl SymbolTable { } #[allow(dead_code)] pub fn debug_symbol_table(&self) -> String { - let mut output = format!("Symbol table\n"); + let mut output = "Symbol table\n".to_string(); let mut sorted_symbols: Vec<(&FullyQualifiedSymbolName, &Symbol)> = self.symbol_path_to_symbol.iter().collect(); sorted_symbols.sort_by(|(fqsn, _), (other_fqsn, _)| fqsn.cmp(other_fqsn)); for (name, sym) in sorted_symbols.iter() { diff --git a/schala-lang/language/src/symbol_table/source_map.rs b/schala-lang/language/src/symbol_table/tables.rs similarity index 100% rename from schala-lang/language/src/symbol_table/source_map.rs rename to schala-lang/language/src/symbol_table/tables.rs