Expand description
Abstract Syntax Tree types for Gruel.
The AST represents the syntactic structure of the source code. It closely mirrors the source syntax and preserves all information needed for error reporting.
§SmallVec Usage
Some non-recursive Vec fields use SmallVec to avoid heap allocation for common small sizes:
Directives(SmallVec<[Directive; 1]>) - most items have 0-1 directives
§Vec Usage (Cannot Use SmallVec)
Vec fields containing recursive types (Expr) cannot use SmallVec because Expr’s size cannot be determined at compile time. These include:
Vec<CallArg>- CallArg contains ExprVec<MatchArm>- contains ExprVec<FieldInit>- contains BoxVec<IntrinsicArg>- contains ExprVec<Statement>- Statement contains ExprVec<Expr>- directly recursive
The IR layers (RIR, AIR, CFG) use index-based references which avoid this issue and are already efficiently allocated.
Structs§
- Anon
Struct Field - A field in an anonymous struct type expression.
- Array
LitExpr - An array literal expression (e.g.,
[1, 2, 3]). - Assign
Statement - An assignment statement.
- Assoc
FnCall Expr - An associated function call expression (e.g.,
Point::origin()ormodule.Point::origin()). - Ast
- A complete source file (list of items).
- Binary
Expr - A binary expression.
- Block
Expr - A block expression containing statements and a final expression.
- BoolLit
- A boolean literal.
- Break
Expr - A break expression (exits the innermost loop).
- CallArg
- An argument in a function call.
- Call
Expr - A function call expression.
- Checked
Block Expr - A checked block expression (e.g.,
checked { @ptr_read(p) }). Unchecked operations (raw pointer manipulation, calling unchecked functions) are only allowed inside checked blocks. - Comptime
Block Expr - A comptime block expression (e.g.,
comptime { 1 + 2 }). The expression inside must be evaluable at compile time. - Comptime
Unroll ForExpr - A comptime_unroll for expression. The collection is evaluated at compile time, then the body is unrolled once per element.
- Const
Decl - A constant declaration.
- Continue
Expr - A continue expression (skips to the next iteration of the innermost loop).
- Destructure
Field - A field binding in a struct destructure pattern.
- Directive
- A directive that modifies compiler behavior for the following item or statement.
- DropFn
- A user-defined destructor declaration.
- Enum
Decl - An enum declaration.
- Enum
Struct LitExpr - An enum struct variant literal expression (e.g.,
Shape::Circle { radius: 5 }). - Enum
Variant - A variant in an enum declaration.
- Enum
Variant Field - A named field in a struct-style enum variant.
- Field
Decl - A field declaration in a struct.
- Field
Expr - A field access expression (e.g.,
point.x). - Field
Init - A field initializer in a struct literal.
- Float
Lit - A floating-point literal, stored as f64 bits for Eq compatibility.
- ForExpr
- A for-in loop expression (e.g.,
for x in expr { body }). - Function
- A function definition.
- Ident
- An identifier.
- IfExpr
- An if expression.
- Index
Expr - An array index expression (e.g.,
arr[0]). - IntLit
- An integer literal.
- Intrinsic
Call Expr - An intrinsic call expression (e.g.,
@dbg(42)or@size_of(i32)). - LetStatement
- A let binding statement.
- Loop
Expr - An infinite loop expression.
- Match
Arm - A single arm in a match expression.
- Match
Expr - A match expression.
- Method
- A method definition in an impl block.
- Method
Call Expr - A method call expression (e.g.,
point.distance()). - NegInt
Lit - A negative integer literal pattern.
- Node
Data - Fixed-size node data (12 bytes total).
- Node
Index - Node index - references a node in the SOA AST.
- Param
- A function parameter.
- Paren
Expr - A parenthesized expression.
- Path
Expr - A path expression (e.g.,
Color::Redormodule.Color::Redfor enum variant). - Path
Pattern - A path pattern (e.g.,
Color::Redormodule.Color::Redfor enum variant matching). - Pattern
Field Binding - A named field binding in a struct variant pattern.
- Return
Expr - A return expression (returns a value from the current function).
- Self
Expr - A self expression (the
selfkeyword in method bodies). - Self
Param - A self parameter in a method.
- SoaAst
- Struct-of-Arrays AST representation.
- String
Lit - A string literal.
- Struct
Decl - A struct declaration.
- Struct
LitExpr - A struct literal expression (e.g.,
Point { x: 1, y: 2 }ormodule.Point { x: 1, y: 2 }). - Type
LitExpr - A type literal expression (e.g.,
i32used as a value). This represents a type used as a value in expression context, typically as an argument to a generic function with comptime parameters. - Unary
Expr - A unary expression.
- UnitLit
- A unit literal expression - represents
()or implicit unit. - While
Expr - A while loop expression.
Enums§
- ArgMode
- Argument passing mode.
- Assign
Target - An assignment target.
- Binary
Op - Binary operators.
- Destructure
Binding - How a field is bound in a struct destructure.
- Directive
Arg - An argument to a directive.
- Enum
Variant Kind - The kind of an enum variant.
- Expr
- An expression.
- Intrinsic
Arg - An argument to an intrinsic call (can be an expression or a type).
- Item
- A top-level item in a source file.
- LetPattern
- A pattern in a let binding.
- NodeTag
- Node tag - identifies what kind of node this is.
- Param
Mode - Parameter passing mode.
- Pattern
- A pattern in a match arm.
- Pattern
Binding - A binding in a data variant pattern.
- Statement
- A statement (does not produce a value).
- Type
Expr - A type expression in the AST.
- UnaryOp
- Unary operators.
- Visibility
- Visibility of an item (function, struct, enum, etc.)
Constants§
- NULL_
NODE - Sentinel value representing “no node” or “null node”. Used for optional children (e.g., else block in if expression).
Functions§
- encode_
unary_ op - Encode a UnaryOp into a u32 for storage in NodeData.
Type Aliases§
- Directives
- Type alias for a small vector of directives. Most items have 0-1 directives, so we inline capacity for 1.