lambda.mli 1.89 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
25
26
  | Dummy

type expr = 
  | Var of var_loc
27
28
29
30
31
  | Apply of expr * expr
  | Abstraction of var_loc array * (Types.t * Types.t) list * branches * int
      (* environment, interface, branches, size of locals *)
  | Check of expr * Auto_pat.state
  | Const of Value.t
32
33
  | Pair of expr * expr
  | Xml of expr * expr * expr
34
  | XmlNs of expr * expr * expr * Ns.table
35
  | Record of expr Imap.t
36
37
38
39
40
41
  | 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
42
  | Validate of expr * Schema_validator.t
43
44
45
  | RemoveField of expr * label
  | Dot of expr * label
  | Ref of expr * Types.Node.t
46
  | Op of string * expr list  
47
  | OpResolved of (Value.t list -> Value.t) * expr list
48
  | NsTable of Ns.table * expr
49
50
51

and branches = {
  brs_accept_chars: bool;
52
53
54
  brs_disp: Auto_pat.state;
  brs_rhs: expr Auto_pat.rhs array;
  brs_stack_pos: int
55
56
57
}

type code_item =
58
59
60
61
62
  | 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
63
64


65
type code = code_item list