Various refactors around symbol table

This commit is contained in:
Greg Shuflin 2021-10-14 06:52:50 -07:00
parent fd3a641c71
commit 69304de998
3 changed files with 8 additions and 8 deletions

View File

@ -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();

View File

@ -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<String>, //TODO does this need to be pub?
pub local_name: Rc<String>,
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() {