package wax-lib

  1. Overview
  2. Docs
Libraries for Wax, a Rust-like syntax for WebAssembly

Install

dune-project
 Dependency

Authors

Maintainers

Sources

wax-0.1.0.tbz
sha256=41b580846af8d41bdf6c3f005f62e38feda3e60fe2e9e4aa440db34ce515a153
sha512=4b3a181fcc7d743194a8647260870fb5190770066a197bcc48104c2b77fd40c643228b795c2bcd6b29a120820e969eb42a37a9bcec98b3f608d13f152d9f6579

doc/wax-lib.wasm/Wax_wasm/Cond_specialize/index.html

Module Wax_wasm.Cond_specializeSource

Specialization of conditional annotations against user-supplied variable bindings (the -D/--define CLI option).

Conditional annotations (@if <cond> ...) are normally preserved verbatim (see Cond_solver for their path-sensitive validation). Given values for some condition variables, this module partially evaluates the conditions:

  • a conditional whose condition becomes fully determined is removed, splicing the surviving branch into the enclosing position;
  • a conditional that still mentions unset variables is kept, with its condition simplified (the known variables substituted and the result constant-folded).
Sourcetype value =
  1. | Bool of bool
  2. | Version of int * int * int
  3. | String of string
Sourcetype bindings

A mapping from condition-variable names to values.

Sourceval parse_define : string -> (string * value, string) result

parse_define s parses one -D/--define argument, either "name" or "name=value". A bare name binds a boolean true. Otherwise the value kind is inferred: "true"/"false" is a boolean, N.N.N (three non-negative integers) a version, and anything else a string. Returns Error msg on a malformed argument (an empty variable name).

Sourceval of_list : (string * value) list -> bindings

Build bindings from name/value pairs. On a duplicate name, the last entry wins.

Sourceval is_empty : bindings -> bool
Sourcetype result =
  1. | True
  2. | False
  3. | Residual of Ast.cond
    (*

    The outcome of partially evaluating a condition: a determined constant, or a residual condition still mentioning unset variables.

    *)

eval ctx env c partially evaluates c under env. Unbound variables are left in the residual; bound ones are substituted and the condition is constant-folded. Reports an error diagnostic (and leaves the offending sub-condition residual) when a variable is set to a value of a kind incompatible with how the condition uses it.

Splice out and simplify every conditional annotation in a WAT module according to eval. Returns the specialized module and the half-open byte ranges of the branches that were removed, for dropping their comments (see Wax_utils.Trivia.drop_in_ranges). With empty bindings this is the identity (no conditional is determined, so all are kept unchanged) and no range is produced.