package wax-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Wax_lang.Ast_utilsSource

Sourceval map_instr : ('a -> 'b) -> 'a Ast.instr -> 'b Ast.instr

map_instr f instr applies the function f to the info field of instr and recursively applies it to all nested instructions.

Sourceval smart_map : ('a -> 'a) -> 'a list -> 'a list

Share-preserving List.map: returns the input list itself (physically) when f leaves every element unchanged (==), so an untouched list is not reallocated.

Sourceval smart_opt : ('a -> 'a) -> 'a option -> 'a option

Share-preserving Option.map (see smart_map).

Sourceval 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_desc

Structurally 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.

Sourceval sub_instrs : 'info Ast.instr -> 'info Ast.instr list

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.

Sourceval iter_instr : ('info Ast.instr -> unit) -> 'info Ast.instr -> unit

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.

Sourceval 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 list

lower_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.

Sourceval synthetic_loop_label : string

Placeholder loop label used only in the discarded type-check lowering (the name never reaches emitted Wat; see lower_while and To_wasm).

Sourceval 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 list

lower_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.

Sourceval 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 list

lower_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.

Sourceval 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.instr

lower_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.

Sourceval map_modulefield : ('a -> 'b) -> 'a Ast.modulefield -> 'b Ast.modulefield

map_modulefield f modulefield applies the function f to the info field of instructions within modulefield and returns a new modulefield.

Sourceval map_modulefield_instr : ('info Ast.instr -> 'info Ast.instr) -> 'info Ast.modulefield -> 'info Ast.modulefield

map_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).

Sourceval iter_fields : (('info Ast.modulefield, Ast.location) Ast.annotated -> unit) -> 'info Ast.module_ -> unit
Sourceval field_roots : 'info Ast.modulefield -> 'info Ast.instr list

The 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).

Sourceval iter_module_instr : ('info Ast.instr -> unit) -> 'info Ast.module_ -> unit

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).

Sourcetype binop_kind = [
  1. | `Shift
  2. | `Arith
  3. | `Bitwise
  4. | `Comparison
]

The precedence class of a binary operator, shared by the precedence lint (Typing) and the Wax printer (Output) so the parentheses the printer emits match exactly the operator mixes the lint would flag.

Sourceval binop_kind : Ast.binop -> binop_kind

binop_kind op is the precedence class of op.

Sourceval confusing_precedence : binop_kind -> binop_kind -> bool

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.

Sourceval import_name : Ast.import_decl -> (string, Ast.location) Ast.annotated

import_name decl is the name decl is imported under: its import_as override if present, else the Wax name decl.id.