Module of module types for OrderedType,ComparableType,Printable,Serializable,Discrete...
[ocaml.git] / bytecomp / lambda.mli
blob6a9c75fd850bafbdd56af1022fc0235cab4ff19f
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 (* The "lambda" intermediate code *)
17 open Asttypes
19 type primitive =
20 Pidentity
21 | Pignore
22 (* Globals *)
23 | Pgetglobal of Ident.t
24 | Psetglobal of Ident.t
25 (* Operations on heap blocks *)
26 | Pmakeblock of int * mutable_flag
27 | Pfield of int
28 | Psetfield of int * bool
29 | Pfloatfield of int
30 | Psetfloatfield of int
31 | Pduprecord of Types.record_representation * int
32 (* External call *)
33 | Pccall of Primitive.description
34 (* Exceptions *)
35 | Praise
36 (* Boolean operations *)
37 | Psequand | Psequor | Pnot
38 (* Integer operations *)
39 | Pnegint | Paddint | Psubint | Pmulint | Pdivint | Pmodint
40 | Pandint | Porint | Pxorint
41 | Plslint | Plsrint | Pasrint
42 | Pintcomp of comparison
43 | Poffsetint of int
44 | Poffsetref of int
45 (* Float operations *)
46 | Pintoffloat | Pfloatofint
47 | Pnegfloat | Pabsfloat
48 | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
49 | Pfloatcomp of comparison
50 (* String operations *)
51 | Pstringlength | Pstringrefu | Pstringsetu | Pstringrefs | Pstringsets
52 (* Array operations *)
53 | Pmakearray of array_kind
54 | Parraylength of array_kind
55 | Parrayrefu of array_kind
56 | Parraysetu of array_kind
57 | Parrayrefs of array_kind
58 | Parraysets of array_kind
59 (* Test if the argument is a block or an immediate integer *)
60 | Pisint
61 (* Test if the (integer) argument is outside an interval *)
62 | Pisout
63 (* Bitvect operations *)
64 | Pbittest
65 (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *)
66 | Pbintofint of boxed_integer
67 | Pintofbint of boxed_integer
68 | Pcvtbint of boxed_integer (*source*) * boxed_integer (*destination*)
69 | Pnegbint of boxed_integer
70 | Paddbint of boxed_integer
71 | Psubbint of boxed_integer
72 | Pmulbint of boxed_integer
73 | Pdivbint of boxed_integer
74 | Pmodbint of boxed_integer
75 | Pandbint of boxed_integer
76 | Porbint of boxed_integer
77 | Pxorbint of boxed_integer
78 | Plslbint of boxed_integer
79 | Plsrbint of boxed_integer
80 | Pasrbint of boxed_integer
81 | Pbintcomp of boxed_integer * comparison
82 (* Operations on big arrays *)
83 | Pbigarrayref of int * bigarray_kind * bigarray_layout
84 | Pbigarrayset of int * bigarray_kind * bigarray_layout
86 and comparison =
87 Ceq | Cneq | Clt | Cgt | Cle | Cge
89 and array_kind =
90 Pgenarray | Paddrarray | Pintarray | Pfloatarray
92 and boxed_integer =
93 Pnativeint | Pint32 | Pint64
95 and bigarray_kind =
96 Pbigarray_unknown
97 | Pbigarray_float32 | Pbigarray_float64
98 | Pbigarray_sint8 | Pbigarray_uint8
99 | Pbigarray_sint16 | Pbigarray_uint16
100 | Pbigarray_int32 | Pbigarray_int64
101 | Pbigarray_caml_int | Pbigarray_native_int
102 | Pbigarray_complex32 | Pbigarray_complex64
104 and bigarray_layout =
105 Pbigarray_unknown_layout
106 | Pbigarray_c_layout
107 | Pbigarray_fortran_layout
109 type structured_constant =
110 Const_base of constant
111 | Const_pointer of int
112 | Const_block of int * structured_constant list
113 | Const_float_array of string list
114 | Const_immstring of string
116 type function_kind = Curried | Tupled
118 type let_kind = Strict | Alias | StrictOpt | Variable
119 (* Meaning of kinds for let x = e in e':
120 Strict: e may have side-effets; always evaluate e first
121 (If e is a simple expression, e.g. a variable or constant,
122 we may still substitute e'[x/e].)
123 Alias: e is pure, we can substitute e'[x/e] if x has 0 or 1 occurrences
124 in e'
125 StrictOpt: e does not have side-effects, but depend on the store;
126 we can discard e if x does not appear in e'
127 Variable: the variable x is assigned later in e' *)
129 type meth_kind = Self | Public | Cached
131 type shared_code = (int * int) list (* stack size -> code label *)
133 type lambda =
134 Lvar of Ident.t
135 | Lconst of structured_constant
136 | Lapply of lambda * lambda list
137 | Lfunction of function_kind * Ident.t list * lambda
138 | Llet of let_kind * Ident.t * lambda * lambda
139 | Lletrec of (Ident.t * lambda) list * lambda
140 | Lprim of primitive * lambda list
141 | Lswitch of lambda * lambda_switch
142 | Lstaticraise of int * lambda list
143 | Lstaticcatch of lambda * (int * Ident.t list) * lambda
144 | Ltrywith of lambda * Ident.t * lambda
145 | Lifthenelse of lambda * lambda * lambda
146 | Lsequence of lambda * lambda
147 | Lwhile of lambda * lambda
148 | Lfor of Ident.t * lambda * lambda * direction_flag * lambda
149 | Lassign of Ident.t * lambda
150 | Lsend of meth_kind * lambda * lambda * lambda list
151 | Levent of lambda * lambda_event
152 | Lifused of Ident.t * lambda
154 and lambda_switch =
155 { sw_numconsts: int; (* Number of integer cases *)
156 sw_consts: (int * lambda) list; (* Integer cases *)
157 sw_numblocks: int; (* Number of tag block cases *)
158 sw_blocks: (int * lambda) list; (* Tag block cases *)
159 sw_failaction : lambda option} (* Action to take if failure *)
160 and lambda_event =
161 { lev_loc: Location.t;
162 lev_kind: lambda_event_kind;
163 lev_repr: int ref option;
164 lev_env: Env.summary }
166 and lambda_event_kind =
167 Lev_before
168 | Lev_after of Types.type_expr
169 | Lev_function
171 val same: lambda -> lambda -> bool
172 val const_unit: structured_constant
173 val lambda_unit: lambda
174 val name_lambda: lambda -> (Ident.t -> lambda) -> lambda
175 val name_lambda_list: lambda list -> (lambda list -> lambda) -> lambda
176 val is_guarded: lambda -> bool
177 val patch_guarded : lambda -> lambda -> lambda
179 val iter: (lambda -> unit) -> lambda -> unit
180 module IdentSet: Set.S with type elt = Ident.t
181 val free_variables: lambda -> IdentSet.t
182 val free_methods: lambda -> IdentSet.t
184 val transl_path: Path.t -> lambda
185 val make_sequence: ('a -> lambda) -> 'a list -> lambda
187 val subst_lambda: lambda Ident.tbl -> lambda -> lambda
188 val bind : let_kind -> Ident.t -> lambda -> lambda -> lambda
190 val commute_comparison : comparison -> comparison
191 val negate_comparison : comparison -> comparison
193 (***********************)
194 (* For static failures *)
195 (***********************)
197 (* Get a new static failure ident *)
198 val next_raise_count : unit -> int
201 val staticfail : lambda (* Anticipated static failure *)
203 (* Check anticipated failure, substitute its final value *)
204 val is_guarded: lambda -> bool
205 val patch_guarded : lambda -> lambda -> lambda