diff options
| author | Thomas Voss <mail@thomasvoss.com> | 2026-03-05 00:42:21 +0100 |
|---|---|---|
| committer | Thomas Voss <mail@thomasvoss.com> | 2026-03-05 00:42:21 +0100 |
| commit | 723fb5031a1f59f8df5d0a0dbf5dc0a54420e15f (patch) | |
| tree | c535b1f7652fe4174e0d27baccf4769602d0515a /oryxc/src/symtab.rs | |
| parent | e951acb92458fbada81dfc7456bc341bbeadb19f (diff) | |
Work on the symbol table
Diffstat (limited to 'oryxc/src/symtab.rs')
| -rw-r--r-- | oryxc/src/symtab.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/oryxc/src/symtab.rs b/oryxc/src/symtab.rs new file mode 100644 index 0000000..b65eee0 --- /dev/null +++ b/oryxc/src/symtab.rs @@ -0,0 +1,42 @@ +#![allow(dead_code)] + +use boxcar; +use dashmap::DashMap; + +use crate::prelude::*; + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub struct ScopeId(pub u32); + +impl ScopeId { + pub const GLOBAL: Self = Self(0); + pub const INVAL: Self = Self(u32::MAX); +} + +#[derive(Clone, Copy, Debug)] +pub struct Scope { + pub parent: ScopeId, +} + +pub struct SymbolVal {} + +pub struct SymbolTable { + scopes: boxcar::Vec<Scope>, + symbols: DashMap<(ScopeId, SymbolId), SymbolVal>, +} + +impl SymbolTable { + pub fn new() -> Self { + return Self { + /* Initialize with the global scope */ + scopes: boxcar::vec![Scope { + parent: ScopeId::INVAL, + }], + symbols: DashMap::new(), + }; + } + + pub fn insert(&self, scope: ScopeId, symbol: SymbolId, value: SymbolVal) { + self.symbols.insert((scope, symbol), value); + } +} |