lambda.mli 2.43 KB
Newer Older
1 2 3 4 5
(* Representation of programs used by the runtime evaluator.
   Similar to the typed abstract syntax tree representation, but:
   - the pattern matching is compiled;
   - the identifiers locations are resolved. *)

6 7 8
open Ident

type var_loc =
9 10
  | Local of int
      (* Slot in the table of locals *)
11
  | Env of int
12 13 14 15 16 17
      (* Slot in the environment *)
  | Ext of Compunit.t * int 
      (* Global slot from a given compilation unit *)
      (* If pos < 0, the first arg is the value *)
  | External of Compunit.t * int 
      (* OCaml External *)
18
      (* If pos < 0, the first arg is the value *)
19
  | Builtin of string
20 21 22
      (* OCaml external embedded in the runtime *)
  | Global of int 
      (* Only for the toplevel *)
23 24
  | Dummy

25
type iface = (Types.t * Types.t) list
26

27
type sigma = 
28
  | Identity
29
  | List of  Types.Subst.t list
30
  | Comp of (sigma * sigma)
31
  | Sel of (var_loc * iface * sigma) 
32

33 34
(* only TVar (polymorphic type variable) and Abstraction have
 * a sigma annotation *)
35 36
type expr = 
  | Var of var_loc
37
  | TVar of (var_loc * sigma)
38
  | Apply of expr * expr
Pietro Abate's avatar
Pietro Abate committed
39
  | Abstraction of var_loc array * iface * branches * int
40
      (* environment, interface, branches, size of locals *)
41
  | PolyAbstraction of var_loc array * iface * branches * int * sigma
42 43
  | Check of expr * Auto_pat.state
  | Const of Value.t
44 45
  | Pair of expr * expr
  | Xml of expr * expr * expr
46
  | XmlNs of expr * expr * expr * Ns.table
47
  | Record of expr Imap.t
48 49 50 51 52 53
  | String of U.uindex * U.uindex * U.t * expr
  | Match of expr * branches
  | Map of expr * branches
  | Transform of expr * branches
  | Xtrans of expr * branches
  | Try of expr * branches
54
  | Validate of expr * Schema_validator.t
55 56 57
  | RemoveField of expr * label
  | Dot of expr * label
  | Ref of expr * Types.Node.t
58
  | Op of string * expr list  
59
  | OpResolved of (Value.t list -> Value.t) * expr list
60
  | NsTable of Ns.table * expr
61 62 63

and branches = {
  brs_accept_chars: bool;
64 65 66
  brs_disp: Auto_pat.state;
  brs_rhs: expr Auto_pat.rhs array;
  brs_stack_pos: int
67 68 69
}

type code_item =
70 71 72 73 74
  | Eval of expr * int
      (* expression, size of locals *)
  | LetDecls of expr * int * Auto_pat.state * int
      (* expression, size of locals, dispatcher, number of globals to set *)
  | LetDecl of expr * int
75 76


77
type code = code_item list
78 79

module Print : sig
80 81 82
  val pp : Format.formatter -> expr -> unit
  val pp_sigma : Format.formatter -> sigma -> unit
  val pp_vloc : Format.formatter -> var_loc -> unit
83
  val string_of_lambda : expr -> string
84
end