Skip to content

Commit

Permalink
Remove scope_level from SymbolRecord
Browse files Browse the repository at this point in the history
This was unused. There was a comment about "awkward" scope numbering,
and indeed some kind of awkward numbering. I removed all of that as
well. We can probably figure it out again quickly if and when needed.
  • Loading branch information
jlapeyre committed Apr 5, 2024
1 parent 28c102f commit 483fd8e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions crates/oq3_semantics/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,16 @@ impl SymbolType for Symbol {
pub struct SymbolRecord<'a> {
symbol: &'a Symbol,
symbol_id: SymbolId,
scope_level: usize,
}

impl SymbolRecord<'_> {
pub fn new(symbol: &Symbol, symbol_id: SymbolId, scope_level: usize) -> SymbolRecord<'_> {
SymbolRecord {
symbol,
symbol_id,
scope_level,
}
pub fn new(symbol: &Symbol, symbol_id: SymbolId) -> SymbolRecord<'_> {
SymbolRecord { symbol, symbol_id }
}

pub fn symbol_id(&self) -> SymbolId {
self.symbol_id.clone()
}

pub fn scope_level(&self) -> usize {
self.scope_level
}
}

// This trait is a bit heavy weight for what it does.
Expand Down Expand Up @@ -401,15 +392,15 @@ impl SymbolTable {
self.current_scope().len()
}

// FIXME: fix awkward scope numbering.
/// Look up `name` in the stack of symbol tables. Return `SymbolRecord`
/// if the symbol is found. Otherwise `Err(SymbolError::MissingBinding)`.
pub fn lookup(&self, name: &str) -> Result<SymbolRecord, SymbolError> {
for (scope_level_rev, table) in self.symbol_table_stack.iter().rev().enumerate() {
for table in self.symbol_table_stack.iter().rev() {
if let Some(symbol_id) = table.get_symbol_id(name) {
let symbol = &self.all_symbols[symbol_id.0];
let scope_level = self.number_of_scopes() - scope_level_rev - 1;
return Ok(SymbolRecord::new(symbol, symbol_id.clone(), scope_level));
return Ok(SymbolRecord::new(
&self.all_symbols[symbol_id.0],
symbol_id.clone(),
));
}
}
Err(SymbolError::MissingBinding) // `name` not found in any scope.
Expand Down

0 comments on commit 483fd8e

Please sign in to comment.