Module Bigraph.Expr

Expressions and constraints for use in control parameters.

exception TYPE_ERROR

Raised when a type mismatch occurs during expression evaluation, e.g., applying arithmetic to incompatible value types.

exception EXP_ERROR of string

A model error encountered while evaluating a control parameter expression at match/sim time (e.g. a value-dependent division by zero that a static check cannot foresee). Carries a user-facing message; handled in the frontend, which reports it and exits 1, so a model error never surfaces as an unhandled-exception crash.

type vals =
  1. | Int of int
  2. | Float of float
  3. | Str of string

The type of base values

val pp_vals : Ppx_deriving_runtime.Format.formatter -> vals -> Ppx_deriving_runtime.unit
val show_vals : vals -> Ppx_deriving_runtime.string
val vals_to_yojson : vals -> Yojson.Safe.t
val vals_of_yojson : Yojson.Safe.t -> vals Ppx_deriving_yojson_runtime.error_or
val compare_vals : vals -> vals -> int

Comparator for base values. throws TYPE_ERROR if value types cannot be coerced

val vals_eq : vals -> vals -> bool

Total "same value?" test. Unlike compare_vals, never raises: a cross-type pair (Str vs numeric) is a disagreement (false).

type exp =
  1. | Const of vals
  2. | Var of string
  3. | Hole
    (*

    The bracket hole $: bound to the captured value inside a bracket guard, unbound in a value expression (a reaction RHS [...]).

    *)
  4. | Minus of exp
  5. | Add of exp * exp
  6. | Sub of exp * exp
  7. | Prod of exp * exp
  8. | Div of exp * exp
  9. | Abs of exp

The type of expressions over base values

val exp_to_yojson : exp -> Yojson.Safe.t
val exp_of_yojson : Yojson.Safe.t -> exp Ppx_deriving_yojson_runtime.error_or
type env = {
  1. hole : vals option;
  2. vars : (string * vals) list;
}

The evaluation environment: the bracket hole, bound to the captured value inside a bracket guard and absent elsewhere (in a value expression, e.g. a reaction RHS [...], where using the hole is a model error), plus the named bindings (captures and global values).

val eq_exp : exp -> exp -> bool

Strict equality of expressions including var names

val compare_exp : exp -> exp -> int

Total order on expressions, consistent with eq_exp

val eval_exp : env -> exp -> exp

Reduce an expression as much as possible

val eval_exp_to_val : env -> exp -> vals

Reduce an expression and coerce it to a value if possible

val eval_exp_to_int : env -> exp -> int

Reduce an expression and coerce it to an int if possible

val eval_exp_to_float : env -> exp -> float

Reduce an expression and coerce it to a float if possible

val eval_exp_to_string : env -> exp -> string

Reduce an expression and coerce it to a string if possible

type cons =
  1. | Any
  2. | EQ of exp * exp
  3. | NEQ of exp * exp
  4. | LT of exp * exp
  5. | LTE of exp * exp
  6. | GT of exp * exp
  7. | GTE of exp * exp
  8. | And of cons * cons
  9. | Or of cons * cons
  10. | Not of cons

The type of parameter constraints

val pp_cons : Ppx_deriving_runtime.Format.formatter -> cons -> Ppx_deriving_runtime.unit
val show_cons : cons -> Ppx_deriving_runtime.string
val cons_to_yojson : cons -> Yojson.Safe.t
val cons_of_yojson : Yojson.Safe.t -> cons Ppx_deriving_yojson_runtime.error_or
val check_cons : string option -> cons -> vals -> bool

Check if the given constraint is valid for a value v. string option is the name of the capture the constraint belongs to, or None for a nameless guard: inside its own guard the capture is always equal to the value it matches, so when present it is bound to v alongside the hole, which lets a labelled guard soundly refer to its own capture (e.g. x: $ = x). The hole is bound to v in every guard, so a nameless guard evaluates any $-based constraint identically.

val eq_cons : cons -> cons -> bool

Strict equality of constraints including var names