Module Instruct.Make_trans

Apply a transformation module and a semantics module to produce a new semantics module that uses the transformation state.

The module this creates won't do any transformations by itself, and its values are defined as identity functions. You need to override specific functions to apply transformations.

Define the semantics of our abstract language.

Parameters

module T : TRANS
module F : SEM with type 'a exp = 'a T.from_exp and type 'a stm = 'a T.from_stm

Signature

Statements and expressions.

type 'a stm = 'a T.stm

A statement, generally some side-effecting code.

type 'a obs = 'a F.obs

The final evaluation result.

val observe : 'a stm -> 'a obs

Observe the evaluation result after all transformations have applied.

type 'a exp = 'a T.exp

An expression.

val return : 'a exp -> 'a stm

Return value 'a from a function.

val raise : string exp -> 'a stm
val stm : unit exp -> unit stm
type 'a ref = 'a F.ref

A mutable reference variable. This is not compatible with expressions.

val (let|) : unit stm -> (unit -> 'a stm) -> 'a stm

Evaluate a unit statement.

val (let$) : (string * 'a exp) -> ('a exp -> 'b stm) -> 'b stm

Define a new immutable binding. The string is used for pretty-printing.

val (let&) : (string * 'a exp) -> ('a ref -> 'b stm) -> 'b stm

Define a new reference variable. The string is used for pretty-printing.

val (!) : 'a ref -> 'a exp
val (:=) : 'a ref -> 'a exp -> unit stm
val incr : int ref -> unit stm

Functions.

val lambda : ('a exp -> 'b stm) -> ('a -> 'b) exp
val (@@) : ('a -> 'b) exp -> 'a exp -> 'b exp

Control flow.

val if_else : bool exp -> then_:(unit -> 'a stm) -> else_:(unit -> 'a stm) -> 'a stm
val while_ : ('a exp -> bool exp) -> 'a ref -> (unit -> unit stm) -> unit stm

Standard values.

val unit : unit stm
val not : bool exp -> bool exp
val int : int -> int exp
val float : float -> float exp
val string : string -> string exp
val bool : bool -> bool exp
val (=) : 'a exp -> 'a exp -> bool exp
val pair : ('a exp * 'b exp) -> ('a * 'b) exp
val unpair : ('a * 'b) exp -> 'a exp * 'b exp
val string_of_int : int exp -> string exp
val string_of_float : float exp -> string exp
val string_of_bool : bool exp -> string exp

Sequences.

val uncons : 'a Stdlib.Seq.t exp -> nil:(unit -> 'b stm) -> cons:('a exp -> 'a Stdlib.Seq.t exp -> 'b stm) -> 'b stm
val generator : (('a exp -> unit stm) -> unit stm) -> 'a Stdlib.Seq.t exp
val iter : 'a Stdlib.Seq.t exp -> ('a exp -> unit stm) -> unit stm

Strings and characters.

val string_to_seq : string exp -> char Stdlib.Seq.t exp
val match_char : char exp -> (char -> 'a stm) -> 'a stm

The given function applies to the following characters and it ignores all others: '&' '"' '\'' '>' '<' '/' '`' '=' .

Arrays.

val array : 'a exp array -> 'a array exp
val array_make : int -> 'a exp -> 'a array exp
val (.%()) : 'a array exp -> int exp -> 'a exp
val (.%()<-) : 'a array exp -> int exp -> 'a exp -> unit stm

Hash tables.

type 'a hashtbl := 'a Stdlib.Hashtbl.MakeSeeded(Stdlib.String).t
val hashtbl : (string exp * 'a exp) Stdlib.Seq.t -> 'a hashtbl exp
val hashtbl_create : unit -> 'a hashtbl exp
val (.%{}) : 'a hashtbl exp -> string exp -> 'a exp
val (.%{}<-) : 'a hashtbl exp -> string exp -> 'a exp -> unit stm
val hashtbl_mem : 'a hashtbl exp -> string exp -> bool exp
val hashtbl_to_seq : 'a hashtbl exp -> (string * 'a) Stdlib.Seq.t exp

Mutable string buffers.

val buffer_create : unit -> Stdlib.Buffer.t exp
val buffer_add_string : Stdlib.Buffer.t exp -> string exp -> unit stm
val buffer_add_char : Stdlib.Buffer.t exp -> char exp -> unit stm
val buffer_contents : Stdlib.Buffer.t exp -> string exp
val buffer_length : Stdlib.Buffer.t exp -> int exp

Promises.

type 'a promise = 'a F.promise

An asynchronous computation.

val await : 'a promise exp -> 'a exp
val async_lambda : ('a exp -> 'b stm) -> ('a -> 'b promise) exp

This is necessary for JavaScript async/await syntax compatibility.

Data

type untyped = F.untyped
module type UNTYPED = sig ... end
val untyped : string -> ((module UNTYPED with type t = 'a) -> 'b stm) -> 'b stm

Make a new untyped wrapper. The string is used for pretty-printing.

module External : sig ... end

Data from the outside world that we need to decode.

Importing and exporting.

type import = F.import

Information to import a function from external code.

val import : import -> ((External.t -> string promise) exp -> 'a stm) -> 'a stm
val export : 'a exp -> 'a stm