diff options
| author | Thomas Voss <mail@thomasvoss.com> | 2026-03-29 23:09:46 +0200 |
|---|---|---|
| committer | Thomas Voss <mail@thomasvoss.com> | 2026-03-29 23:09:46 +0200 |
| commit | da65ee39162d0323321340b2a9cef9a013ad36ef (patch) | |
| tree | 127f6afd6bb418c5df3216e1ad83239aa693ef77 /oryxc/src/parser.rs | |
| parent | db11ea02d777a33fedb6af4ee056e85f52fbb008 (diff) | |
Beginning sema work
Diffstat (limited to 'oryxc/src/parser.rs')
| -rw-r--r-- | oryxc/src/parser.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs index 8c24df1..93adc9f 100644 --- a/oryxc/src/parser.rs +++ b/oryxc/src/parser.rs @@ -1,3 +1,5 @@ +use std::iter; + use soa_rs::{ Soa, Soars, @@ -36,6 +38,16 @@ pub enum AstType { UnaryOperator, /* (rhs, _) */ } +/// The number of AstType variants that represent expressions/binops/etc. In +/// the places where we match/switch on just the subset of AstTypes that are +/// expressions/etc., we can static assert that this equals its current value. +/// This is useful because if a new AstType of the given subset is added and +/// these numbers are incremented, the static asserts fail everywhere where code +/// changes are required. +pub const NEXPRKINDS: usize = 10; +pub const NUNARYKINDS: usize = 5; +pub const NBINARYKINDS: usize = 23; + #[derive(Soars)] #[soa_derive(Debug)] pub struct AstNode { @@ -48,7 +60,7 @@ pub struct AstNode { pub struct Ast { pub nodes: Soa<AstNode>, pub extra: Vec<u32>, - pub types: Box<[TypeId]>, + pub types: Box<[TypeCell]>, pub textra: boxcar::Vec<TypeId>, } @@ -923,7 +935,9 @@ pub fn parse(tokens: &Soa<Token>) -> Result<Ast, Vec<OryxError>> { return Ok(Ast { nodes: p.ast, extra: p.extra_data, - types: vec![TypeId::INVALID; nodecnt].into_boxed_slice(), + types: iter::repeat_with(|| TypeCell::new(TypeId::INVALID)) + .take(nodecnt) + .collect::<Box<[_]>>(), /* TODO: Get the parser to try to compute the required capacity */ textra: boxcar::vec![], }); |