Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/ast.x
Shared helpers for x2c compiler AST nodes.
Functions
| Function | Summary |
|---|---|
ast_changes_left_operand | Returns whether op writes its left operand. |
ast_contains_head | Returns whether any list under value has kind as its head. |
binding_identity_new | Constructs a (binding identity spelling) node. |
binding_identity_spelling | Returns a valid binding node’s source spelling, or NULL. |
binding_identity_try_parts | Extracts a valid (binding positive-integer string) node. |
Ast.never_returns | Returns whether control cannot flow out the bottom of ast. |
Ast.rewrite_children | Applies per_child to each List child of ast and returns the node rebuilt from the results; non-list children pass through. |
Symbol.compound_assignment | Returns the compound assignment for a binary operator, or zero. |
Symbol.compound_operator | Returns the binary operator computed by a compound assignment, or zero. |
Symbol.is_assignment_op | Returns whether op is plain or compound assignment. |
Functions
ast_changes_left_operand
int ast_changes_left_operand(Symbol op)
Returns whether op writes its left operand.
Source: src/ast.x:90
ast_contains_head
int ast_contains_head(Var value, Symbol kind)
Returns whether any list under value has kind as its head. The
worklist keeps deeply nested operator chains off the C stack.
Source: src/ast.x:95
binding_identity_new
List binding_identity_new(int identity, String spelling)
Constructs a (binding identity spelling) node.
The caller must supply a positive compiler-issued identity.
Source: src/ast.x:38
binding_identity_spelling
String binding_identity_spelling(List binding)
Returns a valid binding node’s source spelling, or NULL.
Source: src/ast.x:57
binding_identity_try_parts
int binding_identity_try_parts(List binding, int *identity, String *spelling)
Extracts a valid (binding positive-integer string) node.
Returns one on success and writes only non-NULL outputs; failure returns
zero without changing either output.
Source: src/ast.x:45
Ast
Ast.never_returns
int Ast.never_returns(Ast ast)
Returns whether control cannot flow out the bottom of ast.
Recognized terminals are shared non-returning raises, native termination
calls, and blocks ending in either one when the block contains no
return. Generation uses this fact to mark the enclosing function
_Noreturn.
Source: src/ast.x:184
Ast.rewrite_children
Ast Ast.rewrite_children(Ast ast, Func per_child)
Applies per_child to each List child of ast and returns the node
rebuilt from the results; non-list children pass through. When no child
changed, the scratch storage is freed and ast itself returns, so the
fixed-point transform driver can compare unchanged-node identity.
Source: src/ast.x:114
Symbol
Symbol.compound_assignment
Symbol Symbol.compound_assignment(Symbol op)
Returns the compound assignment for a binary operator, or zero.
Source: src/ast.x:83
Symbol.compound_operator
Symbol Symbol.compound_operator(Symbol op)
Returns the binary operator computed by a compound assignment, or zero.
Source: src/ast.x:80
Symbol.is_assignment_op
int Symbol.is_assignment_op(Symbol op)
Returns whether op is plain or compound assignment.
Source: src/ast.x:86
Public types
| Type | Kind | Summary |
|---|---|---|
Ast | alias | Represents one compiler AST node as a canonical immutable List. |
AstPos | enum | Names the syntactic position in which an AST is parsed or bound. |
Ast
typedef List Ast
Represents one compiler AST node as a canonical immutable List.
NULL denotes no node, and nonempty nodes have the canonical List-pool
lifetime.
Source: src/ast.x:13
AstPos
typedef enum AstPos { AST_UNIT, AST_BLOCK, AST_FIELD, AST_ENUMERATOR, AST_MAP_ENTRY, AST_STATEMENT, AST_EXPRESSION } AstPos
Names the syntactic position in which an AST is parsed or bound.
Source: src/ast.x:16
Design notes
Keeps sequence placement in one place. Simple fixed-shape nodes remain
direct immutable Lists.