package wax-lib
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4361e1324b7754a4c08ab5b505df32061f3ce0cea60443fd0d3699e0fa796b32
sha512=fcc756d2f160ba90a9aa1131f2ab22ed7f45466ccd658c21cf9df6868a6aab0cee7f404719d698a379958802f9820398f2fe0685ecc4dda018ca4f653294e39b
doc/wax-lib.wax/Wax_lang/Ast_utils/index.html
Module Wax_lang.Ast_utilsSource
map_instr f instr applies the function f to the info field of instr and recursively applies it to all nested instructions.
Share-preserving List.map: returns the input list itself (physically) when f leaves every element unchanged (==), so an untouched list is not reallocated.
Share-preserving Option.map (see smart_map).
val map_desc :
instr:('i Ast.instr -> 'i Ast.instr) ->
block:('i Ast.instr list -> 'i Ast.instr list) ->
'i Ast.instr_desc ->
'i Ast.instr_descStructurally rebuild an instr_desc, rewriting each nested operand with instr and each nested statement list with block, but returning the original desc (physically) when nothing changed. Lets a rewrite pass that leaves a subtree untouched allocate nothing for it.
sub_instrs i is the instructions immediately nested within i (its operands and block bodies), in source order — the order the typer visits them, which the conditional-compilation plan (Typing.plan_shape) relies on.
iter_instr f i applies f to i and, recursively, to every instruction nested within it. Unlike map_instr, f receives the whole node (so it can inspect the desc), not just the info field.
val lower_dispatch :
block_info:'info ->
index:'info Ast.instr ->
cases:Ast.label list ->
default:Ast.label ->
arms:(Ast.label * ('info Ast.instr list, Ast.location) Ast.annotated) list ->
'info Ast.instr listlower_dispatch desugars a dispatch to its nested-block-around-a-br_table form: a list of the outermost case block followed by the first arm's trailing body (see the implementation). It is the inverse of Recover_dispatch and is used by both type checking and Wax-to-Wasm conversion.
Placeholder loop label used only in the discarded type-check lowering (the name never reaches emitted Wat; see lower_while and To_wasm).
val lower_while :
block_info:'info ->
fresh_loop:Ast.label ->
label:Ast.label option ->
cond:'info Ast.instr ->
step:'info Ast.instr option ->
block:'info Ast.instr list ->
'info Ast.instr listlower_while desugars a leading-test while C { B } to 'L: loop { if C { B; br 'L; } }. A continue-expression step runs at the end of every iteration: an unlabelled loop appends it to the body; a labelled loop wraps the body in a block (the continue target) so a continue runs the step before the fresh_loop back-edge. Inverse of the while case of Recover_loops; used by both type checking and Wax-to-Wasm conversion.
val lower_match :
block_info:'info ->
labels:Ast.label list ->
scrutinee:'info Ast.instr ->
arms:
(Ast.match_pattern * ('info Ast.instr list, Ast.location) Ast.annotated)
list ->
default:('info Ast.instr list, Ast.location) Ast.annotated ->
'info Ast.instr listlower_match desugars a match to a nested type-test ladder: the scrutinee is evaluated once and threaded through a br_on_cast/br_on_null chain in the innermost block, each test branching out to its arm's block (carrying the narrowed value), with the arm body just after that block and an outer void escape block past all the bodies. labels supplies n+1 fresh block labels — one per arm in order, then the escape label. It is the inverse of Recover_match and is used by both type checking and Wax-to-Wasm conversion.
val lower_trycatch :
block_info:'info ->
join:Ast.label ->
arm_labels:Ast.label list ->
typ:Ast.functype ->
block:('info Ast.instr list, Ast.location) Ast.annotated ->
arms:'info Ast.trycatch_arm list ->
'info Ast.instrlower_trycatch desugars a structured try to try_table plus a block ladder: one block per arm (the first innermost, its result type the arm's entry stack) inside the join block, the try_table innermost with one catch clause per arm, arm bodies as trailing code (fall-through order), and the body's completion escaping with a br to join carrying the try's value. arm_labels supplies one fresh label per arm; join is the try's own label when it has one. It is the exact inverse of Recover_trycatch and is used by Wax-to-Wasm conversion.
map_modulefield f modulefield applies the function f to the info field of instructions within modulefield and returns a new modulefield.
val map_modulefield_instr :
('info Ast.instr -> 'info Ast.instr) ->
'info Ast.modulefield ->
'info Ast.modulefieldmap_modulefield_instr fi modulefield rewrites each instruction ROOT the field holds (a function body's statements, an initializer, a segment offset) with fi, which owns the recursion into that root's operands — the rewriting counterpart of iter_module_instr's field walk. A field's attribute values are left alone (they are always location-annotated).
val iter_fields :
(('info Ast.modulefield, Ast.location) Ast.annotated -> unit) ->
'info Ast.module_ ->
unitThe instruction roots a field holds, in source order: a function body's statements, an initializer, a segment or table init and its offset. A Conditional has none of its own (its nested fields are reached through the field walk).
iter_module_instr f m applies f to every instruction in m — each field's operands and bodies, and everything nested within them (including through conditionals).
binop_kind op is the precedence class of op.
confusing_precedence outer inner is whether a binary operator of kind outer whose operand is a binary operator of kind inner is a precedence footgun — a shift mixed with arithmetic, or a comparison mixed with a bitwise operator. Symmetric.
import_name decl is the name decl is imported under: its import_as override if present, else the Wax name decl.id.