From 723fb5031a1f59f8df5d0a0dbf5dc0a54420e15f Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 5 Mar 2026 00:42:21 +0100 Subject: Work on the symbol table --- oryxc/src/symtab.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 oryxc/src/symtab.rs (limited to 'oryxc/src/symtab.rs') 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, + 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); + } +} -- cgit v1.2.3