quivers.dsl.emit¶
Emission from an AST to canonical .qvr source. The emitter walks a
Module; reparsing its output with quivers.dsl.loads produces the
same compiled program.
emit
¶
AST -> .qvr source emit.
Walks a quivers.dsl.ast_nodes.Module
and produces canonical .qvr source text.
The emit is a one-way printer, not a panproto ParseEmitLens:
quivers' AST is already the resolved form. The printer's contract is
semantic: the emitted source, re-parsed by quivers.dsl.loads,
produces a Module that compiles to the same program as the
original AST. The printer is additionally a canonical fixed point:
emit(parse(emit(ast))) == emit(ast) byte for byte.
Canonical formatting conventions:
- 4-space indentation per nesting level.
- One blank line between top-level statements; a single trailing newline at end of file.
- Option blocks, constructor brace options, lists, and tuples are always emitted inline.
- Doc comments are emitted as
textlines directly above the declaration they document. - Numeric option values and draw-arg scalars render integral floats
as
X.0; constructor keyword arguments renderintvalues without a decimal point andfloatvalues inreprform. - Convenience fields that mirror option-block entries (
axes,via,over,reductionon program steps;leveloncompositionrides its own option block) are not re-emitted from the mirror: the option block is the single surface source.
EmitError
¶
Bases: Exception
Raised when an AST value has no valid .qvr surface form.
module_to_source
¶
module_to_source(module: Module) -> str
Serialize a Module AST to canonical .qvr source.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module to print.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The canonical source, ending in a single newline. |
| RAISES | DESCRIPTION |
|---|---|
EmitError
|
If a node in |
Source code in src/quivers/dsl/emit.py
static_argument_to_source
¶
static_argument_to_source(argument: QiecStaticArgument) -> str
Emit one static argument of an effect or type application.
| PARAMETER | DESCRIPTION |
|---|---|
argument
|
A type, an effect written as type syntax, or an index literal.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The argument's source form, as the module emitter writes it. |