Module Bidir.Types

Defines the bidirectional imperative language in bidir.

Definitions

Value type

type value =
  1. | VInt of int
    (*

    An arbitrary-size integer.

    *)
  2. | VStr of string
  3. | VBits of string
    (*

    Bitvectors are strings of only 0/1. Bitvector length is the string length.

    *)
  4. | VTup of value list

A value in the bidirectional language.

val equal_value : value -> value -> Ppx_deriving_runtime.bool
val value_to_yojson : value -> Yojson.Safe.t
val equal_value_types : value -> value -> bool

Varname type

type varname =
  1. | VarName of string
val equal_varname : varname -> varname -> Ppx_deriving_runtime.bool
val show_varname : varname -> Ppx_deriving_runtime.string
val varname_to_yojson : varname -> Yojson.Safe.t
val str_of_varname : varname -> string

Expr type

type expr =
  1. | ELit of value
  2. | EVar of varname
  3. | ETup of expr list
  4. | EWildcard

An expression in the bidirectional language. Every expression can be interpreted bidirectionally, i.e., as a left- or right- expression.

val equal_expr : expr -> expr -> Ppx_deriving_runtime.bool
val expr_to_yojson : expr -> Yojson.Safe.t

Stmt type

type 'a bidir =
  1. | Assign of expr * 'a list * expr
    (*

    An assignment reading from the first expression, piping left-to-right through the intrinsics, then storing into the second expression.

    *)
  2. | Decl of varname list
    (*

    Requires the given variables are in scope and narrows the current state to only the specified variables. This behaves identical forwards or backwards.

    *)
  3. | Delete of varname list
    (*

    Removes the given variables from the scope. This behaves identically forwards and backwards.

    *)
  4. | Choice of 'a bidir list
    (*

    A mutually-exclusive choice between the given alternatives. Exactly one alternative must succeed.

    *)
  5. | Parallel of 'a bidir list
    (*

    Parallel execution of the given bidirectional programs. All parallels must succeed. Each parallel should be independent (i.e., input and output disjoint variables) from the others.

    *)
  6. | Sequential of 'a bidir list
    (*

    A sequential composition of statements. In the backwards direction, the list is reversed.

    *)

A statement in the bidirectional language which can be interpreted forwards or backwards. The type parameter is the type of intrinsic functions. Unless mentioned otherwise, the descriptions here are for the forwards direction.

val equal_bidir : 'a. ('a -> 'a -> Ppx_deriving_runtime.bool) -> 'a bidir -> 'a bidir -> Ppx_deriving_runtime.bool
val bidir_to_yojson : 'a. ('a -> Yojson.Safe.t) -> 'a bidir -> Yojson.Safe.t

State type

val equal_state : state -> state -> Ppx_deriving_runtime.bool

Helper methods

val apply : 'a -> ('a -> 'b) -> 'b

Flipped function application, taking a value followed by a function to apply it to. Very useful when folding a list of functions.

val fanout : ('a -> 'b) list -> 'a -> 'b list

Given a list of functions, sends the given input value to every function and collects the results.

val vars_of_expr : expr -> varname list
val vars_of_stmt : 'a bidir -> varname list