Module Mlsem_lang.Ast

module SA = Mlsem_system.Ast
type blockid =
  1. | BFun
  2. | BLoop
  3. | BOther of int
type pattern_constructor =
  1. | PCTuple of int
  2. | PCCons
  3. | PCRec of string list * bool
  4. | PCTag of Mlsem_types.Tag.t
  5. | PCEnum of Mlsem_types.Enum.t
  6. | PCCustom of SA.ccustom * SA.pcustom list
type pattern =
  1. | PType of Mlsem_types.Ty.t
  2. | PVar of Mlsem_types.Ty.t list * Mlsem_common.Variable.t
    (*

    The first parameter is a suggested type decomposition, similarly to let-bindings

    *)
  3. | PConstructor of pattern_constructor * pattern list
  4. | PAnd of pattern * pattern
  5. | POr of pattern * pattern
  6. | PAssign of Mlsem_types.Ty.t list * Mlsem_common.Variable.t * Mlsem_types.GTy.t
    (*

    The first parameter is a suggested type decomposition, similarly to let-bindings

    *)

Patterns must be linear and their alternatives must agree on the variables they bind: a variable must occur in at most one component of a PAnd or of a PConstructor, and in both sides of a POr. Transforming a PatMatch over a pattern that violates this raises Invalid_argument (see Transform.eliminate_cf).

type e =
  1. | Hole of int
  2. | Exc
    (*

    Expression of type empty

    *)
  3. | Void
    (*

    Expression of type void

    *)
  4. | Voidify of t
    (*

    Evaluate the expression inside, but give it the void type, even if it diverges

    *)
  5. | Ignore of t
    (*

    Evaluate the expression inside, but give it the void type, or empty if it diverges

    *)
  6. | Isolate of t
    (*

    Prevent duplications of the outer context when eliminating control flow inside

    *)
  7. | Value of Mlsem_types.GTy.t
  8. | Var of Mlsem_common.Variable.t
  9. | Constructor of SA.constructor * t list
  10. | GConstructor of SA.gconstructor * t list
  11. | Lambda of Mlsem_types.Ty.t list * SA.param_annot * Mlsem_common.Variable.t * t
    (*

    The first parameter is a suggested type decomposition, similarly to let-bindings

    *)
  12. | LambdaRec of (SA.param_annot * Mlsem_common.Variable.t * t) list
  13. | Ite of t * Mlsem_types.Ty.t * t * t
  14. | PatMatch of t * (pattern * t) list
  15. | App of t * t
  16. | Operation of SA.operation * t
  17. | Projection of SA.projection * t
  18. | Declare of Mlsem_types.Ty.t list * Mlsem_common.Variable.t * t
    (*

    Declaration of an uninitialized mutable variable. The variable provided must be mutable (cf. MVariable.create). The type system will not check that the variable is assigned before use. The first parameter is a suggested type decomposition, similarly to let-bindings: it applies to the values later assigned to the variable.

    *)
  19. | Let of Mlsem_types.Ty.t list * Mlsem_common.Variable.t * t * t
    (*

    The first parameter is a suggested type decomposition. If the variable is mutable, it is equivalent to a Declare followed by an assignment: in particular, the whole expression diverges if the definition diverges, regardless of the decomposition.

    *)
  20. | TypeCast of t * Mlsem_types.GTy.t * SA.check
  21. | TypeCoerce of t * Mlsem_types.GTy.t * SA.check
  22. | VarAssign of Mlsem_common.Variable.t * t
    (*

    The variable provided must be mutable (cf. MVariable.create)

    *)
  23. | Loop of t
    (*

    A void expression that may be evaluated multiple times.

    *)
  24. | Seq of t * t
    (*

    Evaluate the first expression, then the second.

    *)
  25. | Try of t list
    (*

    May jump from a branch to another. Used to model try-with expressions.

    *)
  26. | Alt of SA.alt_settings * t list
    (*

    Evaluate branches independently. The result is (the intersection of) the result of the branches that do not fail.

    *)
  27. | Block of blockid * t
    (*

    Identifies a block to which a Ret can refer to.

    *)
  28. | Ret of blockid * t option
    (*

    Evaluate the expression (Exc if not specified), and use it as the value of block specified. Used to encode Return and Break.

    *)
  29. | If of t * Mlsem_types.Ty.t * t * t option
    (*

    If-else block statement. Returns void.

    *)
  30. | While of t * Mlsem_types.Ty.t * t
    (*

    While block statement. Returns void.

    *)
  31. | Return of t
    (*

    Exits the current function.

    *)
  32. | Break
    (*

    Exits the current while loop.

    *)
val map_pat : (pattern -> pattern) -> pattern -> pattern
val map_pat' : (pattern -> pattern option) -> pattern -> pattern
val iter_pat : (pattern -> unit) -> pattern -> unit
val iter_pat' : (pattern -> bool) -> pattern -> unit
val map : (t -> t) -> t -> t
val map' : (t -> t option) -> t -> t
val iter : (t -> unit) -> t -> unit
val iter' : (t -> bool) -> t -> unit
val fill_hole : int -> t -> t -> t
val fv : t -> Mlsem_common.VarSet.t
val vars : t -> Mlsem_common.VarSet.t
val refresh : t -> t
val pp_blockid : Stdlib.Format.formatter -> blockid -> unit
val pp_pattern_constructor : Stdlib.Format.formatter -> pattern_constructor -> unit
val pp_pattern : Stdlib.Format.formatter -> pattern -> unit
val pp_e : Stdlib.Format.formatter -> e -> unit
val pp : Stdlib.Format.formatter -> t -> unit