From da65ee39162d0323321340b2a9cef9a013ad36ef Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 29 Mar 2026 23:09:46 +0200 Subject: Beginning sema work --- oryxc/src/parser.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'oryxc/src/parser.rs') 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, pub extra: Vec, - pub types: Box<[TypeId]>, + pub types: Box<[TypeCell]>, pub textra: boxcar::Vec, } @@ -923,7 +935,9 @@ pub fn parse(tokens: &Soa) -> Result> { 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::>(), /* TODO: Get the parser to try to compute the required capacity */ textra: boxcar::vec![], }); -- cgit v1.2.3