quivers.dsl.emit¶
module_to_source prints an AST Module as .qvr source in a fixed layout
(module to source).
Reparsing its output with quivers.dsl.loads gives the same compiled program, which makes it
suited to inspecting generated programs
and to testing that parsing and printing agree. Translation into other languages is
transpilation.
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
draw_call_to_source
¶
draw_call_to_source(head: str, args: tuple[DrawArg, ...] | None, *, static_args: tuple[DrawArg, ...] = ()) -> str
A draw's right-hand side as QVR source.
| PARAMETER | DESCRIPTION |
|---|---|
head
|
The family or morphism drawn from.
TYPE:
|
args
|
The draw's runtime arguments, keyword or positional.
TYPE:
|
static_args
|
Static specialization arguments, written in square brackets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
| RAISES | DESCRIPTION |
|---|---|
EmitError
|
If an argument has no source spelling. |
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. |