Extract SymbolTable to separate file

This commit is contained in:
pjht 2022-10-20 11:29:06 -05:00
parent 41106f4c3a
commit 4665d11279
2 changed files with 32 additions and 27 deletions

View File

@ -11,6 +11,7 @@ mod ram;
mod rom;
mod storage;
mod symbol;
mod symbol_table;
mod term;
use crate::{
backplane::Backplane,
@ -38,33 +39,7 @@ use std::{
path::Path,
process,
};
#[derive(Debug)]
pub struct SymbolTable {
symbols: HashMap<String, Symbol>,
breakpoints: IndexSet<String>,
active: bool,
}
impl SymbolTable {
fn new(symbols: HashMap<String, Symbol>) -> Self {
Self {
symbols,
breakpoints: IndexSet::new(),
active: true,
}
}
fn update_symbols(&mut self, symbols: HashMap<String, Symbol>) {
self.breakpoints = self
.breakpoints
.iter()
.cloned()
.filter(|sym| symbols.contains_key(sym))
.collect::<IndexSet<_>>();
self.symbols = symbols;
}
}
use symbol_table::SymbolTable;
pub type SymbolTables = IndexMap<String, SymbolTable>;

30
src/symbol_table.rs Normal file
View File

@ -0,0 +1,30 @@
use crate::symbol::Symbol;
use indexmap::IndexSet;
use std::collections::HashMap;
#[derive(Debug)]
pub struct SymbolTable {
pub symbols: HashMap<String, Symbol>,
pub breakpoints: IndexSet<String>,
pub active: bool,
}
impl SymbolTable {
pub fn new(symbols: HashMap<String, Symbol>) -> Self {
Self {
symbols,
breakpoints: IndexSet::new(),
active: true,
}
}
pub fn update_symbols(&mut self, symbols: HashMap<String, Symbol>) {
self.breakpoints = self
.breakpoints
.iter()
.cloned()
.filter(|sym| symbols.contains_key(sym))
.collect::<IndexSet<_>>();
self.symbols = symbols;
}
}