Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/generate/generate.x

The generated header and source of one unit.

Functions

FunctionSummary
Compiler.definition_rowsReturns one row for each function, foreign alias, and typedef that the lowered unit ast defines, in source order: (function NAME DISPLAY TYPE PARAMETERS LINE DOC STATIC ORIGIN DECLARATOR SPAN) or (typedef NAME BASE MODIFIERS SPAN).
Compiler.dump_definitionsPrints the --dump-definitions projection of the lowered unit ast: (unit PATH), the module comment as (module TEXT) when the file opens with one, then one row per Compiler.definition_rows entry.
Compiler.generate_codeWrites the generated C header and source for one lowered translation unit.
Compiler.generate_code_textReturns the generated header and source of the lowered ast as (hfile htext cfile ctext), named from basename, without writing them.
Compiler.init_statementsReturns the statements queued for phase, in the order they were added.
Compiler.initializer_functionReturns the function type name(void) running body.
Compiler.place_source_preludePlaces generated declarations after source types and includes, before the first function or captured initializer that can use them.
Compiler.run_once_bodyReturns a run-once initializer body: before, then a return when guard is set that sets it otherwise, then after.
Init.enterReturns function with its entry setup: the protocol initializer and the type initializer run once, and a guarded entry calls the region’s initializer unless its guard is set.

Compiler

Compiler.definition_rows

List Compiler.definition_rows(Compiler c, List ast)

Returns one row for each function, foreign alias, and typedef that the lowered unit ast defines, in source order: (function NAME DISPLAY TYPE PARAMETERS LINE DOC STATIC ORIGIN DECLARATOR SPAN) or (typedef NAME BASE MODIFIERS SPAN). ORIGIN is <source>, <macro> for a Unit macro or generated body, or <alias>. DECLARATOR is the token range of an authored function’s declarator, and SPAN the token range and privacy of the top-level form that produced the definition; either is empty when the compiler made the definition. LINE is 1 and DOC empty for a definition without authored source.

Source: src/generate/definitions.x:15

Compiler.dump_definitions

void Compiler.dump_definitions(Compiler c, List ast)

Prints the --dump-definitions projection of the lowered unit ast: (unit PATH), the module comment as (module TEXT) when the file opens with one, then one row per Compiler.definition_rows entry. The command-line reference in the book describes the fields.

Source: src/generate/definitions.x:108

Compiler.generate_code

void Compiler.generate_code(Compiler c, List ast, String dir)

Writes the generated C header and source for one lowered translation unit. ast must be the normalized result of transform_ast for this compiler; its filename, symbols, binding facts, cache keys, and initialization state must still describe that same unit. dir must already exist. Generation partitions the AST, materializes caches and once-only initialization, and writes or replaces <dir>/<source-stem>.h, .c, and the .xi interface of a collected unit through one Path.publish_files, so a failed write replaces none of them. It appends generated bindings and initialization work to the compiler and is not idempotent. Failures are reported as emit diagnostics.

Source: src/generate/output.x:35

Compiler.generate_code_text

List Compiler.generate_code_text(Compiler c, List ast, String basename)

Returns the generated header and source of the lowered ast as (hfile htext cfile ctext), named from basename, without writing them. It affects the compiler as Compiler.generate_code does.

Source: src/generate/output.x:47

Compiler.init_statements

List Compiler.init_statements(Compiler c, Symbol phase)

Returns the statements queued for phase, in the order they were added.

Source: src/generate/initialization.x:199

Compiler.initializer_function

List Compiler.initializer_function( Compiler c, Type type, List name, List body)

Returns the function type name(void) running body.

Source: src/generate/initialization.x:6

Compiler.place_source_prelude

List Compiler.place_source_prelude( Compiler c, List source, List declarations)

Places generated declarations after source types and includes, before the first function or captured initializer that can use them. An outer conditional containing that first use follows the declarations. A unit without such a use gets them at its end, after the declarations they may assign.

Source: src/generate/output.x:102

Compiler.run_once_body

List Compiler.run_once_body(Compiler c, List before, List guard, List after)

Returns a run-once initializer body: before, then a return when guard is set that sets it otherwise, then after.

Source: src/generate/initialization.x:12

Init

Init.enter

List Init.enter(Init &i, List function, int guarded)

Returns function with its entry setup: the protocol initializer and the type initializer run once, and a guarded entry calls the region’s initializer unless its guard is set.

Source: src/generate/initialization.x:49

Public types

TypeKindSummary
InitstructHolds one region’s initialization.

Init

typedef struct Init { Compiler c, String initializer, List guard, entry, shutdown, synthetic; Map reachable; } Init

Holds one region’s initialization. guard is set once the region has initialized, and entry is the function a guarded entry calls. In the source, initializer names the type initializer, shutdown registers the unit’s shutdown function, synthetic is the synthetic initializer or NULL, and reachable holds the entries a cache-only file guards, or is NULL when every public entry is guarded.

Source: src/generate/generate.x:37

Design notes

This module owns a unit’s generated files: it splits the lowered AST into header and source without changing source order, gives the source its once-only initialization and static prototypes, wraps the header in its guard, and publishes both with the unit’s interface. The definition rows the interface lists, and --dump-definitions prints, come from the same lowered AST.