summaryrefslogtreecommitdiff
path: root/oryxc
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-03-10 17:38:30 +0100
committerThomas Voss <mail@thomasvoss.com> 2026-03-10 17:38:30 +0100
commit59b2e5bd0fd7cea5fc3f9c74241cf4fa08e99228 (patch)
treeb6628d20ba5d62413c97bfd975cd456fa7ce65e1 /oryxc
parent73cc7b764478cadb42ac9e3cb2cc86cc054548a3 (diff)
Wrap the AST nodes and extra data in a struct
Diffstat (limited to 'oryxc')
-rw-r--r--oryxc/src/compiler.rs39
-rw-r--r--oryxc/src/parser.rs15
2 files changed, 26 insertions, 28 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs
index 98947f6..d934a29 100644
--- a/oryxc/src/compiler.rs
+++ b/oryxc/src/compiler.rs
@@ -37,7 +37,7 @@ use crate::errors::OryxError;
use crate::intern::Interner;
use crate::lexer::Token;
use crate::parser::{
- AstNode,
+ Ast,
AstType,
};
use crate::prelude::*;
@@ -51,12 +51,10 @@ use crate::{
#[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 symtab: DashMap<(ScopeId, SymbolId), Symbol>,
+ pub name: OsString,
+ pub buffer: String,
+ pub tokens: OnceLock<Soa<Token>>,
+ pub ast: OnceLock<Ast>,
}
impl FileData {
@@ -72,14 +70,12 @@ impl FileData {
fs::File::open(&name)?.read_to_string(&mut buffer)?;
buffer.push_str(unsafe { std::str::from_utf8_unchecked(&PAD) });
- Ok(Self {
+ return Ok(Self {
name,
buffer,
tokens: OnceLock::new(),
ast: OnceLock::new(),
- extra_data: OnceLock::new(),
- symtab: DashMap::new(),
- })
+ });
}
}
@@ -289,14 +285,13 @@ fn worker_loop(
if c_state.flags.debug_parser {
let mut handle = io::stderr().lock();
- for n in ast.iter() {
+ for n in ast.nodes.iter() {
let _ = write!(handle, "{n:?}\n");
}
}
- let root = (ast.len() - 1) as u32;
+ let root = (ast.nodes.len() - 1) as u32;
fdata.ast.set(ast).unwrap();
- fdata.extra_data.set(extra_data).unwrap();
c_state.job_push(
&queue,
@@ -315,26 +310,22 @@ fn worker_loop(
} => {
let tokens = fdata.tokens.get().unwrap();
let ast = fdata.ast.get().unwrap();
- let extra_data = fdata.extra_data.get().unwrap();
- let SubNodes(beg, nstmts) = ast.sub()[block as usize];
+ let SubNodes(beg, nstmts) = ast.nodes.sub()[block as usize];
let mut errors = Vec::new();
for i in beg..beg + nstmts {
- let multi_def_bind = extra_data[i as usize];
-
- if ast.kind()[multi_def_bind as usize]
- != AstType::MultiDefBind
+ let node = ast.extra[i as usize];
+ if ast.nodes.kind()[node as usize] != AstType::MultiDefBind
{
continue;
}
- let def_idents = ast.sub()[multi_def_bind as usize].0;
- let nidents = extra_data[def_idents as usize];
+ let identsbeg = ast.nodes.sub()[node as usize].0;
+ let nidents = ast.extra[identsbeg as usize];
for j in 0..nidents {
- let ident =
- extra_data[(def_idents + 1 + j * 2) as usize];
+ let ident = ast.extra[(identsbeg + 1 + j * 2) as usize];
let span = tokens.view()[ident as usize];
/* Make string slice lifetime 'static */
diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs
index 70b530f..319beea 100644
--- a/oryxc/src/parser.rs
+++ b/oryxc/src/parser.rs
@@ -44,6 +44,12 @@ pub struct AstNode {
pub sub: SubNodes,
}
+#[derive(Debug)]
+pub struct Ast {
+ pub nodes: Soa<AstNode>,
+ pub extra: Vec<u32>,
+}
+
struct Parser<'a> {
ast: Soa<AstNode>,
extra_data: Vec<u32>,
@@ -885,9 +891,7 @@ impl<'a> Parser<'a> {
}
}
-pub fn parse(
- tokens: &Soa<Token>,
-) -> Result<(Soa<AstNode>, Vec<u32>), Vec<OryxError>> {
+pub fn parse(tokens: &Soa<Token>) -> Result<Ast, Vec<OryxError>> {
let mut p = Parser::new(tokens);
while p.get() != TokenType::Eof {
p.parse_toplevel();
@@ -904,5 +908,8 @@ pub fn parse(
tok: 0,
sub: SubNodes(stmtsbeg as u32, nstmts as u32),
});
- return Ok((p.ast, p.extra_data));
+ return Ok(Ast {
+ nodes: p.ast,
+ extra: p.extra_data,
+ });
}