summaryrefslogtreecommitdiff
path: root/oryxc
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-03-12 20:13:16 +0100
committerThomas Voss <mail@thomasvoss.com> 2026-03-12 20:13:16 +0100
commit9263d4114f449421f57dbc9c597684a2ce7fcaed (patch)
tree4345a8d644d87ef83a11663a70225d4334dae5c9 /oryxc
parentc77b9644712f93f529309751e06d59e22dbb5090 (diff)
Create a macro for generating ID types
Diffstat (limited to 'oryxc')
-rw-r--r--oryxc/src/compiler.rs18
-rw-r--r--oryxc/src/prelude.rs25
2 files changed, 25 insertions, 18 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs
index 3bfe6c1..e81da63 100644
--- a/oryxc/src/compiler.rs
+++ b/oryxc/src/compiler.rs
@@ -5,7 +5,8 @@ use std::io::{
Write,
};
use std::sync::atomic::{
- AtomicUsize,
+ AtomicU32,
+ AtomicUsize,
Ordering,
};
use std::sync::{
@@ -105,7 +106,7 @@ pub enum JobType {
}
pub struct Job {
- id: usize,
+ id: u32,
kind: JobType,
}
@@ -123,7 +124,7 @@ struct CompilerState<'a> {
interner: Interner<'a>,
files: Vec<Arc<FileData>>,
deps: DashMap<usize, boxcar::Vec<Job>>,
- next_id: AtomicUsize,
+ next_id: AtomicU32,
types: boxcar::Vec<OryxType>,
}
@@ -139,7 +140,7 @@ impl<'a> CompilerState<'a> {
/// Generate a new ID for a job, scope, etc.
#[inline(always)]
- fn genid(&self) -> usize {
+ fn genid(&self) -> u32 {
return self.next_id.fetch_add(1, Ordering::Relaxed);
}
@@ -177,7 +178,7 @@ where
let mut initial_jobs = Vec::new();
for (i, path) in paths.into_iter().enumerate() {
- let id = FileId(i);
+ let id = FileId(i as u32);
// Take ownership of the OsString so we can store it in FileData
// without cloning
@@ -187,7 +188,7 @@ where
);
files.push(Arc::clone(&fdata));
initial_jobs.push(Job {
- id: i,
+ id: i as u32,
kind: JobType::Lex { file: id, fdata },
});
}
@@ -203,7 +204,7 @@ where
worker_threads: OnceLock::new(),
interner: Interner::new(),
deps: DashMap::new(),
- next_id: AtomicUsize::new(njobs),
+ next_id: AtomicU32::new(njobs as u32),
/* Temporary solution */
types: boxcar::vec![
OryxType::Integer /* int */ { bits: 64, signed: true },
@@ -439,7 +440,8 @@ fn worker_loop(
ok = false;
}
- if let Some((_, deps)) = c_state.deps.remove(&job.id) {
+ let jid = job.id as usize;
+ if let Some((_, deps)) = c_state.deps.remove(&jid) {
for j in deps {
c_state.job_push(&queue, j);
}
diff --git a/oryxc/src/prelude.rs b/oryxc/src/prelude.rs
index 4e36f33..03dbc07 100644
--- a/oryxc/src/prelude.rs
+++ b/oryxc/src/prelude.rs
@@ -6,20 +6,25 @@ use std::fmt::{
use crate::hashtrie::HTrie;
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
-pub struct FileId(pub usize);
-
-#[repr(transparent)]
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
-pub struct SymbolId(pub u32);
+macro_rules! mkidtype {
+ ($name:ident) => {
+ #[repr(transparent)]
+ #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
+ pub struct $name(pub u32);
+ impl $name {
+ #[allow(dead_code)]
+ pub const INVALID: Self = Self(u32::MAX);
+ }
+ };
+}
-#[repr(transparent)]
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
-pub struct ScopeId(pub usize);
+mkidtype!(FileId);
+mkidtype!(ScopeId);
+mkidtype!(SymbolId);
+mkidtype!(TypeId);
impl ScopeId {
pub const GLOBAL: Self = Self(0);
- pub const INVALID: Self = Self(usize::MAX);
}
#[derive(Debug)]