Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/expressions/expressions.x
Expression syntax and its resolution.
Functions
| Function | Summary |
|---|---|
Compiler.apply_macro_value | Applies the Macro value expr to supplied argument expressions. |
Compiler.check_explicit_converter | Reports parsed when it is the explicit converter call resolved last and target converts its receiver on its own: either side is Var, the types share one C type, or the receiver declares a converter to the target. |
Compiler.complete_iter_chain | Completes an eligible resolved Iter call chain for immediate consumption. |
Compiler.convert_expression | Adds operations to convert a resolved expression AST to target. |
Compiler.convert_segment_to_string | Converts a resolved interpolation segment to String when available. |
Compiler.converter_call | The call to the converter that type, or the first of its typedef names that declares one, provides for target, applied to expr, or NULL when none declares one. |
Compiler.func_call_parts | Returns the callee and arguments of a typed Func call, or NULL for any other expression. |
Compiler.is_builtin_converter_call | The global builtin boxers and scalar formatters only observe their arguments. |
Compiler.needs_resolution | True when syntax still needs ordinary binding or macro substitution. |
Compiler.parse_assignment | Parses one right-associative assignment expression. |
Compiler.parse_conditional | Parses a binary expression and its optional conditional tail. |
Compiler.parse_expression | Parses an assignment expression and any following comma expressions. |
Compiler.parse_macro_expression_target | Parses one macro target through the cast-expression grammar. |
Compiler.parse_parenthesized_statement | Parses a statement beginning with (. |
Compiler.parse_primary | Parses one primary expression or expression-valued macro slot. |
Compiler.parse_variable | Parses and resolves one complex identifier expression. |
Compiler.postfix_completions | Returns sorted visible field and method names that resolve on receiver through access. |
Compiler.printf_static_format | Returns the C spelling of the format a printf-family call consumes when it is known at translation time, or NULL. |
Compiler.promote_string_literal | Converts a C string literal to String where no C meaning applies: as a method receiver, a foreach collection, or a raise detail. |
Compiler.require_var_tag | Returns the exact Var tag for a type test, rejecting types without one. |
Compiler.resolve_expression | Resolves and type-annotates one expression AST in current compiler state. |
Compiler.resolve_map_entry | Resolves the key and value of one (map-entry key value) AST row. |
Compiler.resolve_postfix_member | Resolves one field or method selection without consuming parser tokens. |
Compiler.var_tag_expression | Builds an exact tag expression, deferring macro type slots until binding. |
List.printf_family | Returns the printf-family entry a callee names, or NULL. |
Compiler
Compiler.apply_macro_value
List Compiler.apply_macro_value( Compiler c, List expr, List supplied, Token origin)
Applies the Macro value expr to supplied argument expressions.
Inside a template body the call is retained so the template can capture
the value it applies; elsewhere it is an ordinary Macro_apply over the
argument values.
Source: src/expressions/syntax.x:533
Compiler.check_explicit_converter
void Compiler.check_explicit_converter( Compiler c, List parsed, Type target, int context)
Reports parsed when it is the explicit converter call resolved last
and target converts its receiver on its own: either side is Var, the
types share one C type, or the receiver declares a converter to the
target. The call then changes nothing but the spelling. context is 0
for a typed destination, 1 for an interpolation hole, which displays
every value through Var.str, and 2 for a printf-family value, which
the format converts when it is a Var.
Source: src/expressions/conversions.x:48
Compiler.complete_iter_chain
List Compiler.complete_iter_chain(Compiler c, List expression)
Completes an eligible resolved Iter call chain for immediate consumption.
It accepts only a typed identifier call of the form
(expr R (call (expr ((func P) T) (ident B)) (args A))), where R and
the last formal in P canonicalize to Iter. Iter arguments are
completed recursively; a call missing only that last formal receives the
hidden destination. Variadic calls and Iter_unzip are returned unchanged.
Source: src/expressions/calls.x:416
Compiler.convert_expression
List Compiler.convert_expression(Compiler c, List expr, Type target)
Adds operations to convert a resolved expression AST to target.
The result may contain converter, boxing, unboxing, Func, reference, or
composite-literal operations. Returns the original expression when C
performs the conversion implicitly; an unsupported x2c conversion reports
a type error through c. Synthesized operations may add generated
bindings or immutable literal entries to compiler state.
Source: src/expressions/conversions.x:224
Compiler.convert_segment_to_string
List Compiler.convert_segment_to_string(Compiler c, List expr)
Converts a resolved interpolation segment to String when available.
A missing String conversion is expected: the transform boxes that segment
to Var and renders it at runtime.
A declared numeric converter keeps its formatting; other numeric segments
use Var.str. A segment statically spelled Var also uses Var.str for
every
runtime tag. The ordinary Var-to-String conversion is
not equivalent: it
extracts only a String payload and yields empty String for every other
tag.
Source: src/expressions/conversions.x:417
Compiler.converter_call
List Compiler.converter_call(Compiler c, List expr, Type type, Type target)
The call to the converter that type, or the first of its typedef names
that declares one, provides for target, applied to expr, or NULL
when none declares one.
Source: src/expressions/conversions.x:575
Compiler.func_call_parts
List Compiler.func_call_parts(Compiler c, Var content)
Returns the callee and arguments of a typed Func call, or NULL for any
other expression. content is the body of the call’s expr node. Each
argument is (func-arg value address source): the argument boxed as a
Var, or (no-value) when it has no Var form; its address, or 0; and its
type, which is (expr ("List") (ident reference)) for a null argument
that takes the callee’s own type.
Source: src/expressions/calls.x:355
Compiler.is_builtin_converter_call
int Compiler.is_builtin_converter_call(Compiler c, List expr)
The global builtin boxers and scalar formatters only observe their arguments. A custom converter or a shadowed callee may change state.
Source: src/expressions/conversions.x:628
Compiler.needs_resolution
int Compiler.needs_resolution(Compiler c, Var value)
True when syntax still needs ordinary binding or macro substitution.
Source: src/expressions/resolution.x:80
Compiler.parse_assignment
List Compiler.parse_assignment(Compiler c)
Parses one right-associative assignment expression.
A parenthesized identifier list on the left becomes a destructuring
assignment only for =. c.token stops after the expression.
Source: src/expressions/syntax.x:38
Compiler.parse_conditional
List Compiler.parse_conditional(Compiler c)
Parses a binary expression and its optional conditional tail.
The false arm recurses at conditional precedence, making ?:
right-associative, and c.token stops after the expression.
Source: src/expressions/syntax.x:87
Compiler.parse_expression
List Compiler.parse_expression(Compiler c)
Parses an assignment expression and any following comma expressions.
A comma expression retains source order and takes the type of its final
value. c.token stops at the first token outside the expression.
Source: src/expressions/syntax.x:13
Compiler.parse_macro_expression_target
List Compiler.parse_macro_expression_target(Compiler c)
Parses one macro target through the cast-expression grammar.
Parsing starts at c.token and leaves it at the first token after
the target.
Source: src/expressions/syntax.x:279
Compiler.parse_parenthesized_statement
List Compiler.parse_parenthesized_statement(Compiler c)
Parses a statement beginning with (.
The ordinary parameter parser consumes the contents once: one anonymous
parameter is a cast type, while named parameters are destructuring
declarations. Everything following an ordinary parenthesized expression
resumes at the postfix tail it had already reached. This entry consumes
the terminating ; and returns (stmnt expression) or an origin-anchored
(dstrdecl ...).
Source: src/expressions/syntax.x:209
Compiler.parse_primary
List Compiler.parse_primary(Compiler c)
Parses one primary expression or expression-valued macro slot.
Dispatch starts at c.token to the selected literal, identifier,
grouping, or macro parser and leaves the token after that primary form.
Source: src/expressions/syntax.x:607
Compiler.parse_variable
List Compiler.parse_variable(Compiler c)
Parses and resolves one complex identifier expression.
Parsing starts at c.token and leaves it after the identifier.
Source: src/expressions/syntax.x:665
Compiler.postfix_completions
List Compiler.postfix_completions( Compiler c, Type receiver, Symbol access)
Returns sorted visible field and method names that resolve on receiver
through access.
Source: src/expressions/access.x:327
Compiler.printf_static_format
String Compiler.printf_static_format(Compiler c, Var format)
Returns the C spelling of the format a printf-family call consumes when
it is known at translation time, or NULL. That is a quoted C string
literal, the canonical String one becomes, or the String_new of one;
any other format, such as a variable or an object macro, is not readable
here. A String literal’s text is spelled as a C literal.
Source: src/expressions/calls.x:504
Compiler.promote_string_literal
List Compiler.promote_string_literal(Compiler c, List expr)
Converts a C string literal to String where no C meaning applies: as a
method receiver, a foreach collection, or a raise detail. Parentheses
and a conditional whose arms are both literals count as the literal; any
other expression is returned unchanged.
Source: src/expressions/conversions.x:176
Compiler.require_var_tag
Symbol Compiler.require_var_tag( Compiler c, Type target, Token origin)
Returns the exact Var tag for a type test, rejecting types without one. Enums retain no identity after boxing and cannot be tested this way.
Source: src/expressions/resolution.x:324
Compiler.resolve_expression
List Compiler.resolve_expression(Compiler c, List input, Token origin)
Resolves and type-annotates one expression AST in current compiler state.
Existing expr type annotations are resolved semantic types.
Already-resolved trees without unresolved descendants and non-expression
inputs are returned unchanged; abstract declarations use the declaration
binder. origin anchors diagnostics and generated operations that must
retain source position.
Source: src/expressions/resolution.x:55
Compiler.resolve_map_entry
List Compiler.resolve_map_entry(Compiler c, List input, Token origin)
Resolves the key and value of one (map-entry key value) AST row.
Any other shape is reported at origin as a parse error.
Source: src/expressions/resolution.x:450
Compiler.resolve_postfix_member
List Compiler.resolve_postfix_member( Compiler c, Type receiver_type, List field, Symbol access, int call_context)
Resolves one field or method selection without consuming parser tokens.
field is a single-name List and access is . or
->. The result is a
(field access type), (method binding signature), or (ambiguous ...)
row, or NULL when no member is visible. Method lookup is enabled only by
call_context and records the selected binding in c.sym.
Source: src/expressions/access.x:177
Compiler.var_tag_expression
List Compiler.var_tag_expression(Compiler c, Type target, Token origin)
Builds an exact tag expression, deferring macro type slots until binding.
Source: src/expressions/resolution.x:337
List
List.printf_family
const PrintfFn *List.printf_family(List l)
Returns the printf-family entry a callee names, or NULL. A resolved
user function that happens to use a libc spelling is not one.
Source: src/expressions/calls.x:483
Public types
| Type | Kind | Summary |
|---|---|---|
PrintfFn | struct | A printf-family function: its name, the indexes of its format and first value arguments, and whether only a spelling no declaration resolves names it. |
PrintfFn
typedef struct PrintfFn { const char *name, int fmt_arg, first_arg, unresolved; } PrintfFn
A printf-family function: its name, the indexes of its format and first value arguments, and whether only a spelling no declaration resolves names it.
Source: src/expressions/expressions.x:19
Design notes
The parser reads expressions with C precedence and resolves each node as
it builds it; constructed syntax enters the same resolver. Resolution
gives a node its type and binding, and its last step converts the value
to the type its destination declares. That conversion lives here; the
walk of a brace initializer over its subobjects lives in
initializers.x.