Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / mlton / atoms / prim.sig
CommitLineData
7f918cf1
CE
1(* Copyright (C) 2014,2017 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 *)
9
10signature PRIM_STRUCTS =
11 sig
12 structure CFunction: C_FUNCTION
13 structure CType: C_TYPE
14 structure Con: CON
15 structure Const: CONST
16 structure RealSize: REAL_SIZE
17 structure WordSize: WORD_SIZE
18 sharing RealSize = Const.RealX.RealSize
19 sharing WordSize = Const.WordX.WordSize
20 end
21
22signature PRIM =
23 sig
24 include PRIM_STRUCTS
25
26 structure Name:
27 sig
28 datatype 'a t =
29 Array_alloc of {raw: bool} (* to rssa (as runtime C fn) *)
30 | Array_copyArray (* to rssa (as runtime C fn) *)
31 | Array_copyVector (* to rssa (as runtime C fn) *)
32 | Array_length (* to rssa *)
33 | Array_sub (* to ssa2 *)
34 | Array_toArray (* to rssa *)
35 | Array_toVector (* to rssa *)
36 | Array_uninit (* to rssa *)
37 | Array_uninitIsNop (* to rssa *)
38 | Array_update (* to ssa2 *)
39 | CPointer_add (* codegen *)
40 | CPointer_diff (* codegen *)
41 | CPointer_equal (* codegen *)
42 | CPointer_fromWord (* codegen *)
43 | CPointer_getCPointer (* to rssa *)
44 | CPointer_getObjptr (* to rssa *)
45 | CPointer_getReal of RealSize.t (* to rssa *)
46 | CPointer_getWord of WordSize.t (* to rssa *)
47 | CPointer_lt (* codegen *)
48 | CPointer_setCPointer (* to rssa *)
49 | CPointer_setObjptr (* to rssa *)
50 | CPointer_setReal of RealSize.t (* to rssa *)
51 | CPointer_setWord of WordSize.t (* to rssa *)
52 | CPointer_sub (* codegen *)
53 | CPointer_toWord (* codegen *)
54 | Exn_extra (* implement exceptions *)
55 | Exn_name (* implement exceptions *)
56 | Exn_setExtendExtra (* implement exceptions *)
57 | FFI of 'a CFunction.t (* to rssa *)
58 | FFI_Symbol of {name: string,
59 cty: CType.t option,
60 symbolScope: CFunction.SymbolScope.t } (* codegen *)
61 | GC_collect (* to rssa (as runtime C fn) *)
62 | IntInf_add (* to rssa (as runtime C fn) *)
63 | IntInf_andb (* to rssa (as runtime C fn) *)
64 | IntInf_arshift (* to rssa (as runtime C fn) *)
65 | IntInf_compare (* to rssa (as runtime C fn) *)
66 | IntInf_gcd (* to rssa (as runtime C fn) *)
67 | IntInf_lshift (* to rssa (as runtime C fn) *)
68 | IntInf_mul (* to rssa (as runtime C fn) *)
69 | IntInf_neg (* to rssa (as runtime C fn) *)
70 | IntInf_notb (* to rssa (as runtime C fn) *)
71 | IntInf_orb (* to rssa (as runtime C fn) *)
72 | IntInf_quot (* to rssa (as runtime C fn) *)
73 | IntInf_rem (* to rssa (as runtime C fn) *)
74 | IntInf_sub (* to rssa (as runtime C fn) *)
75 | IntInf_toString (* to rssa (as runtime C fn) *)
76 | IntInf_toVector (* to rssa *)
77 | IntInf_toWord (* to rssa *)
78 | IntInf_xorb (* to rssa (as runtime C fn) *)
79 (* of type unit -> 'a.
80 * Makes a bogus value of any type.
81 *)
82 | MLton_bogus (* to rssa *)
83 | MLton_bug (* to rssa (as impure C fn) *)
84 | MLton_deserialize (* unused *)
85 | MLton_eq (* to rssa (as Word_equal) *)
86 | MLton_equal (* polymorphic equality *)
87 | MLton_halt (* to rssa (as runtime C fn) *)
88 | MLton_hash (* polymorphic hash *)
89 (* MLton_handlesSignals and MLton_installSignalHandler work together
90 * to inform the optimizer and basis library whether or not the
91 * program uses signal handlers.
92 *
93 * MLton_installSignalHandler is called by MLton.Signal.setHandler,
94 * and is effectively a noop, but is left in the program until, so
95 * that the optimizer can test whether or not the program installs
96 * signal handlers.
97 *
98 * MLton_handlesSignals is translated by closure conversion into
99 * a boolean, and is true iff MLton_installsSignalHandler is called.
100 *)
101 | MLton_handlesSignals (* closure conversion *)
102 | MLton_installSignalHandler (* to rssa (as nop) *)
103 | MLton_serialize (* unused *)
104 | MLton_share (* to rssa (as nop or runtime C fn) *)
105 | MLton_size (* to rssa (as runtime C fn) *)
106 | MLton_touch (* to rssa (as nop) or backend (as nop) *)
107 | Real_Math_acos of RealSize.t (* codegen *)
108 | Real_Math_asin of RealSize.t (* codegen *)
109 | Real_Math_atan of RealSize.t (* codegen *)
110 | Real_Math_atan2 of RealSize.t (* codegen *)
111 | Real_Math_cos of RealSize.t (* codegen *)
112 | Real_Math_exp of RealSize.t (* codegen *)
113 | Real_Math_ln of RealSize.t (* codegen *)
114 | Real_Math_log10 of RealSize.t (* codegen *)
115 | Real_Math_sin of RealSize.t (* codegen *)
116 | Real_Math_sqrt of RealSize.t (* codegen *)
117 | Real_Math_tan of RealSize.t (* codegen *)
118 | Real_abs of RealSize.t (* codegen *)
119 | Real_add of RealSize.t (* codegen *)
120 | Real_castToWord of RealSize.t * WordSize.t (* codegen *)
121 | Real_div of RealSize.t (* codegen *)
122 | Real_equal of RealSize.t (* codegen *)
123 | Real_ldexp of RealSize.t (* codegen *)
124 | Real_le of RealSize.t (* codegen *)
125 | Real_lt of RealSize.t (* codegen *)
126 | Real_mul of RealSize.t (* codegen *)
127 | Real_muladd of RealSize.t (* codegen *)
128 | Real_mulsub of RealSize.t (* codegen *)
129 | Real_neg of RealSize.t (* codegen *)
130 | Real_qequal of RealSize.t (* codegen *)
131 | Real_rndToReal of RealSize.t * RealSize.t (* codegen *)
132 | Real_rndToWord of RealSize.t * WordSize.t * {signed: bool} (* codegen *)
133 | Real_round of RealSize.t (* codegen *)
134 | Real_sub of RealSize.t (* codegen *)
135 | Ref_assign (* to ssa2 *)
136 | Ref_deref (* to ssa2 *)
137 | Ref_ref (* to ssa2 *)
138 | String_toWord8Vector (* defunctorize *)
139 | Thread_atomicBegin (* to rssa *)
140 | Thread_atomicEnd (* to rssa *)
141 | Thread_atomicState (* to rssa *)
142 | Thread_copy (* to rssa (as runtime C fn) *)
143 | Thread_copyCurrent (* to rssa (as runtime C fn) *)
144 | Thread_returnToC (* codegen *)
145 (* switchTo has to be a _prim because we have to know that it
146 * enters the runtime -- because everything must be saved
147 * on the stack.
148 *)
149 | Thread_switchTo (* to rssa (as runtime C fn) *)
150 | TopLevel_getHandler (* implement exceptions *)
151 | TopLevel_getSuffix (* implement suffix *)
152 | TopLevel_setHandler (* implement exceptions *)
153 | TopLevel_setSuffix (* implement suffix *)
154 | Vector_length (* to ssa2 *)
155 | Vector_sub (* to ssa2 *)
156 | Vector_vector (* to ssa2 *)
157 | Weak_canGet (* to rssa (as runtime C fn) *)
158 | Weak_get (* to rssa (as runtime C fn) *)
159 | Weak_new (* to rssa (as runtime C fn) *)
160 | Word_add of WordSize.t (* codegen *)
161 | Word_addCheck of WordSize.t * {signed: bool} (* codegen *)
162 | Word_andb of WordSize.t (* codegen *)
163 | Word_castToReal of WordSize.t * RealSize.t (* codegen *)
164 | Word_equal of WordSize.t (* codegen *)
165 | Word_extdToWord of WordSize.t * WordSize.t * {signed: bool} (* codegen *)
166 | Word_lshift of WordSize.t (* codegen *)
167 | Word_lt of WordSize.t * {signed: bool} (* codegen *)
168 | Word_mul of WordSize.t * {signed: bool} (* codegen *)
169 | Word_mulCheck of WordSize.t * {signed: bool} (* codegen *)
170 | Word_neg of WordSize.t (* codegen *)
171 | Word_negCheck of WordSize.t (* codegen *)
172 | Word_notb of WordSize.t (* codegen *)
173 | Word_orb of WordSize.t (* codegen *)
174 | Word_quot of WordSize.t * {signed: bool} (* codegen *)
175 | Word_rem of WordSize.t * {signed: bool} (* codegen *)
176 | Word_rndToReal of WordSize.t * RealSize.t * {signed: bool} (* codegen *)
177 | Word_rol of WordSize.t (* codegen *)
178 | Word_ror of WordSize.t (* codegen *)
179 | Word_rshift of WordSize.t * {signed: bool} (* codegen *)
180 | Word_sub of WordSize.t (* codegen *)
181 | Word_subCheck of WordSize.t * {signed: bool} (* codegen *)
182 | Word_toIntInf (* to rssa *)
183 | Word_xorb of WordSize.t (* codegen *)
184 | WordVector_toIntInf (* to rssa *)
185 | WordArray_subWord of {seqSize:WordSize.t, eleSize:WordSize.t} (* to rssa *)
186 | WordArray_updateWord of {seqSize: WordSize.t, eleSize: WordSize.t} (* to rssa *)
187 | WordVector_subWord of {seqSize: WordSize.t, eleSize: WordSize.t} (* to rssa *)
188 | Word8Vector_toString (* defunctorize *)
189 | World_save (* to rssa (as runtime C fn) *)
190
191 val toString: 'a t -> string
192 end
193
194 structure ApplyArg:
195 sig
196 datatype 'a t =
197 Con of {con: Con.t, hasArg: bool}
198 | Const of Const.t
199 | Var of 'a
200
201 val layout: ('a -> Layout.t) -> 'a t -> Layout.t
202 end
203 structure ApplyResult:
204 sig
205 type 'a prim
206 datatype ('a, 'b) t =
207 Apply of 'a prim * 'b list
208 | Bool of bool
209 | Const of Const.t
210 | Overflow
211 | Unknown
212 | Var of 'b
213
214 val layout: ('b -> Layout.t) -> ('a, 'b) t -> Layout.t
215 end
216
217 type 'a t
218 sharing type t = ApplyResult.prim
219 val apply:
220 'a t * 'b ApplyArg.t list * ('b * 'b -> bool) -> ('a, 'b) ApplyResult.t
221 val arrayAlloc: {raw: bool} -> 'a t
222 val arrayLength: 'a t
223 val arrayToVector: 'a t
224 val arrayUpdate: 'a t
225 val assign: 'a t
226 val bogus: 'a t
227 val bug: 'a t
228 val checkApp: 'a t * {args: 'a vector,
229 result: 'a,
230 targs: 'a vector,
231 typeOps: {array: 'a -> 'a,
232 arrow: 'a * 'a -> 'a,
233 bool: 'a,
234 cpointer: 'a,
235 equals: 'a * 'a -> bool,
236 exn: 'a,
237 intInf: 'a,
238 real: RealSize.t -> 'a,
239 reff: 'a -> 'a,
240 thread: 'a,
241 unit: 'a,
242 vector: 'a -> 'a,
243 weak: 'a -> 'a,
244 word: WordSize.t -> 'a}} -> bool
245 val cpointerAdd: 'a t
246 val cpointerDiff: 'a t
247 val cpointerEqual: 'a t
248 val cpointerGet: CType.t -> 'a t
249 val cpointerLt: 'a t
250 val cpointerSet: CType.t -> 'a t
251 val cpointerSub: 'a t
252 val cpointerToWord: 'a t
253 val deref: 'a t
254 val eq: 'a t (* pointer equality *)
255 val equal: 'a t (* polymorphic equality *)
256 val equals: 'a t * 'a t -> bool
257 val extractTargs: 'a t * {args: 'b vector,
258 result: 'b,
259 typeOps: {deArray: 'b -> 'b,
260 deArrow: 'b -> 'b * 'b,
261 deRef: 'b -> 'b,
262 deVector: 'b -> 'b,
263 deWeak: 'b -> 'b}} -> 'b vector
264 val ffi: 'a CFunction.t -> 'a t
265 val ffiSymbol: {name: string,
266 cty: CType.t option,
267 symbolScope: CFunction.SymbolScope.t } -> 'a t
268 val fromString: string -> 'a t option
269 val hash: 'a t (* polymorphic hash *)
270 val intInfToWord: 'a t
271 val intInfToVector: 'a t
272 val isCommutative: 'a t -> bool
273 (*
274 * isFunctional p = true iff p always returns same result when given
275 * same args and has no side effects.
276 * isFuntional implies not maySideEffect.
277 * examples: Array_length, MLton_equal, Vector_vector, Word_add
278 * not examples: Array_alloc, Array_sub, Ref_deref, Ref_ref
279 *)
280 val isFunctional: 'a t -> bool
281 val layout: 'a t -> Layout.t
282 val layoutApp: 'a t * 'b vector * ('b -> Layout.t) -> Layout.t
283 val layoutFull: 'a t * ('a -> Layout.t) -> Layout.t
284 val map: 'a t * ('a -> 'b) -> 'b t
285 (* examples: Word_addCheck, Word_mulCheck, Word_subCheck *)
286 val mayOverflow: 'a t -> bool
287 (* examples: Array_update, Ref_assign
288 * not examples: Array_sub, Array_uninit, Ref_deref, Ref_ref
289 *)
290 val maySideEffect: 'a t -> bool
291 val name: 'a t -> 'a Name.t
292 val realCastToWord: RealSize.t * WordSize.t -> 'a t
293 val reff: 'a t
294 val toString: 'a t -> string
295 val touch: 'a t
296 val vector: 'a t
297 val vectorLength: 'a t
298 val vectorSub: 'a t
299 val wordAdd: WordSize.t -> 'a t
300 val wordAddCheck: WordSize.t * {signed: bool} -> 'a t
301 val wordAndb: WordSize.t -> 'a t
302 val wordCastToReal : WordSize.t * RealSize.t -> 'a t
303 val wordEqual: WordSize.t -> 'a t
304 val wordExtdToWord: WordSize.t * WordSize.t * {signed: bool} -> 'a t
305 val wordLshift: WordSize.t -> 'a t
306 val wordLt: WordSize.t * {signed: bool} -> 'a t
307 val wordMul: WordSize.t * {signed: bool} -> 'a t
308 val wordNeg: WordSize.t -> 'a t
309 val wordOrb: WordSize.t -> 'a t
310 val wordQuot: WordSize.t * {signed: bool} -> 'a t
311 val wordRshift: WordSize.t * {signed: bool} -> 'a t
312 val wordSub: WordSize.t -> 'a t
313 val wordXorb: WordSize.t -> 'a t
314 end