pub struct Program {
pub includes: Vec<Include>,
pub unions: Vec<UnionDef>,
pub words: Vec<WordDef>,
}Fields§
§includes: Vec<Include>§unions: Vec<UnionDef>§words: Vec<WordDef>Implementations§
Source§impl Program
impl Program
Sourcepub const MAX_VARIANT_FIELDS: usize = 12
pub const MAX_VARIANT_FIELDS: usize = 12
Generate constructor words for all union definitions
Maximum number of fields a variant can have (limited by runtime support)
pub fn new() -> Self
pub fn find_word(&self, name: &str) -> Option<&WordDef>
Sourcepub fn validate_word_calls(&self) -> Result<(), String>
pub fn validate_word_calls(&self) -> Result<(), String>
Validate that all word calls reference either a defined word or a built-in
Sourcepub fn validate_word_calls_with_externals(
&self,
external_words: &[&str],
) -> Result<(), String>
pub fn validate_word_calls_with_externals( &self, external_words: &[&str], ) -> Result<(), String>
Validate that all word calls reference a defined word, built-in, or external word.
The external_words parameter should contain names of words available from
external sources (e.g., included modules) that should be considered valid.
Sourcepub fn generate_constructors(&mut self) -> Result<(), String>
pub fn generate_constructors(&mut self) -> Result<(), String>
Generate helper words for union types:
- Constructors:
Make-VariantName- creates variant instances - Predicates:
is-VariantName?- tests if value is a specific variant - Accessors:
VariantName-fieldname- extracts field values (RFC #345)
Example: For union Message { Get { chan: Int } }
Generates:
: Make-Get ( Int -- Message ) :Get variant.make-1 ;
: is-Get? ( Message -- Bool ) variant.tag :Get symbol.= ;
: Get-chan ( Message -- Int ) 0 variant.field-at ;
Returns an error if any variant exceeds the maximum field count.
Sourcepub fn fixup_union_types(&mut self)
pub fn fixup_union_types(&mut self)
RFC #345: Fix up type variables in stack effects that should be union types
When parsing files with includes, type variables like “Message” in
( Message -- Int ) may be parsed as Type::Var("Message") if the
union definition is in an included file. After resolving includes,
we know all union names and can convert these to Type::Union("Message").
This ensures proper nominal type checking for union types across files.