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/compiler.rs | 17 +++++++++-------- oryxc/src/main.rs | 1 + oryxc/src/prelude.rs | 9 --------- oryxc/src/symtab.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 oryxc/src/symtab.rs (limited to 'oryxc') diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs index d8bdfa2..f1f25fc 100644 --- a/oryxc/src/compiler.rs +++ b/oryxc/src/compiler.rs @@ -25,13 +25,13 @@ use crossbeam_deque::{ Stealer, Worker, }; -use dashmap::DashMap; use soa_rs::Soa; use crate::errors::OryxError; use crate::lexer::Token; use crate::parser::AstNode; use crate::prelude::*; +use crate::symtab::*; use crate::{ Flags, err, @@ -39,13 +39,14 @@ use crate::{ parser, }; +#[allow(dead_code)] pub struct FileData { pub name: OsString, pub buffer: String, pub tokens: OnceLock>, pub ast: OnceLock>, pub extra_data: OnceLock>, - pub scopes: Vec>, + pub symtab: SymbolTable, } impl FileData { @@ -67,7 +68,7 @@ impl FileData { tokens: OnceLock::new(), ast: OnceLock::new(), extra_data: OnceLock::new(), - scopes: Vec::new(), + symtab: SymbolTable::new(), }) } } @@ -264,12 +265,12 @@ fn worker_loop( } }, Job::ResolveDef { - file, - fdata, - scope, - node, + file: _, + fdata: _, + scope: _, + node: _, } => { - eprintln!("Resolving def at node index {node:?}"); + todo!(); }, } diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs index 9b44828..c118ac5 100644 --- a/oryxc/src/main.rs +++ b/oryxc/src/main.rs @@ -7,6 +7,7 @@ mod lexer; mod parser; mod prelude; mod size; +mod symtab; mod unicode; use std::ffi::OsString; diff --git a/oryxc/src/prelude.rs b/oryxc/src/prelude.rs index b7e80c2..9c91116 100644 --- a/oryxc/src/prelude.rs +++ b/oryxc/src/prelude.rs @@ -7,19 +7,10 @@ use std::fmt::{ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct FileId(pub usize); -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct ScopeId(pub usize); - -impl ScopeId { - pub const GLOBAL: Self = Self(0); -} - #[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct SymbolId(pub u32); -pub struct SymbolVal {} - #[derive(Clone, Copy)] pub struct SubNodes(pub u32, pub u32); 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