summaryrefslogtreecommitdiff
path: root/oryxc/src
diff options
context:
space:
mode:
Diffstat (limited to 'oryxc/src')
-rw-r--r--oryxc/src/compiler.rs17
-rw-r--r--oryxc/src/main.rs1
-rw-r--r--oryxc/src/prelude.rs9
-rw-r--r--oryxc/src/symtab.rs42
4 files changed, 52 insertions, 17 deletions
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<Soa<Token>>,
pub ast: OnceLock<Soa<AstNode>>,
pub extra_data: OnceLock<Vec<u32>>,
- pub scopes: Vec<DashMap<SymbolId, SymbolVal>>,
+ 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<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);
+ }
+}