[project @ 2001-04-18 01:49:22 by dsyme]
[ghc-hetmet.git] / ghc / compiler / ilxGen / primops.txt
1 {- NOT YET DONE:
2
3
4 -----------------------------------------------------------------------
5 -- $Id: primops.txt,v 1.1 2001/02/26 15:44:59 rrt Exp $
6 --
7 -- Primitive Operations
8 --
9 -----------------------------------------------------------------------
10
11 -- To add a new primop, you currently need to update the following files:
12 --
13 --      - this file (ghc/compiler/prelude/primops.txt), which includes
14 --        the type of the primop, and various other properties (its
15 --        strictness attributes, whether it is defined as a macro
16 --        or as out-of-line code, etc.)
17 --
18 --      - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
19 --
20 --      - if the primop is inline (i.e. a macro), then:
21 --              ghc/includes/PrimOps.h
22 --              ghc/compiler/nativeGen/StixPrim.lhs
23 --
24 --      - or, for an out-of-line primop:
25 --              ghc/includes/PrimOps.h (just add the declaration)
26 --              ghc/rts/PrimOps.hc     (define it here)
27 --
28 --      - the User's Guide
29 --
30
31 -- The default attribute values which apply if you don't specify
32 -- other ones.  Attribute values can be True, False, or arbitrary
33 -- text between curly brackets.  This is a kludge to enable 
34 -- processors of this file to easily get hold of simple info
35 -- (eg, out_of_line), whilst avoiding parsing complex expressions
36 -- needed for strictness and usage info.
37
38 defaults
39    has_side_effects = False
40    out_of_line      = False
41    commutable       = False
42    needs_wrapper    = False
43    can_fail         = False
44    strictness       = { \ arity -> StrictnessInfo (replicate arity wwPrim) False }
45    usage            = { nomangle other }
46
47
48 ------------------------------------------------------------------------
49 --- Support for the metacircular interpreter                         ---
50 ------------------------------------------------------------------------
51
52 primop   IndexOffClosureOp_Ptr  "indexPtrOffClosure#"  GenPrimOp
53    a -> Int# -> (# b #)
54 primop   IndexOffClosureOp_Word "indexWordOffClosure#"  GenPrimOp
55    a -> Int# -> Word#
56
57
58 primop   Addr2IntOp  "addr2Int#"     GenPrimOp   Addr# -> Int#
59
60 primop   DoubleDecodeOp   "decodeDouble#" GenPrimOp    
61    Double# -> (# Int#, Int#, ByteArr# #)
62    with out_of_line = True
63
64 primop   FloatDecodeOp   "decodeFloat#" GenPrimOp
65    Float# -> (# Int#, Int#, ByteArr# #)
66    with out_of_line = True
67
68 primop   IntegerSubOp   "minusInteger#" GenPrimOp  
69    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
70    with out_of_line = True
71
72 primop   IntegerMulOp   "timesInteger#" GenPrimOp   
73    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
74    with commutable = True
75         out_of_line = True
76
77 primop   IntegerGcdOp   "gcdInteger#" GenPrimOp    
78    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
79    with commutable = True
80         out_of_line = True
81
82 primop   IntegerIntGcdOp   "gcdIntegerInt#" GenPrimOp
83    Int# -> ByteArr# -> Int# -> Int#
84    with commutable = True
85
86 primop   IntegerDivExactOp   "divExactInteger#" GenPrimOp
87    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
88    with out_of_line = True
89
90 primop   IntegerQuotOp   "quotInteger#" GenPrimOp
91    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
92    with out_of_line = True
93
94 primop   IntegerRemOp   "remInteger#" GenPrimOp
95    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
96    with out_of_line = True
97
98 primop   IntegerCmpOp   "cmpInteger#"   GenPrimOp  
99    Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
100    with needs_wrapper = True
101
102 primop   IntegerCmpIntOp   "cmpIntegerInt#" GenPrimOp
103    Int# -> ByteArr# -> Int# -> Int#
104    with needs_wrapper = True
105
106 primop   IntegerQuotRemOp   "quotRemInteger#" GenPrimOp
107    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
108    with can_fail = True
109         out_of_line = True
110
111 primop   IntegerDivModOp    "divModInteger#"  GenPrimOp
112    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
113    with can_fail = True
114         out_of_line = True
115
116 primop   Integer2IntOp   "integer2Int#"    GenPrimOp
117    Int# -> ByteArr# -> Int#
118    with needs_wrapper = True
119
120 primop   Integer2WordOp   "integer2Word#"   GenPrimOp
121    Int# -> ByteArr# -> Word#
122    with needs_wrapper = True
123
124 primop   IntegerToInt64Op   "integerToInt64#" GenPrimOp
125    Int# -> ByteArr# -> Int64#
126
127 primop   IntegerToWord64Op   "integerToWord64#" GenPrimOp
128    Int# -> ByteArr# -> Word64#
129
130 ------------------------------------------------------------------------
131 --- Arrays                                                           ---
132 ------------------------------------------------------------------------
133
134 primop  NewByteArrayOp_Char "newCharArray#" GenPrimOp
135    Int# -> State# s -> (# State# s, MutByteArr# s #)
136    with out_of_line = True
137
138 primop  NewByteArrayOp_Int "newIntArray#" GenPrimOp
139    Int# -> State# s -> (# State# s, MutByteArr# s #)
140    with out_of_line = True
141
142 primop  NewByteArrayOp_Word "newWordArray#" GenPrimOp
143    Int# -> State# s -> (# State# s, MutByteArr# s #)
144    with out_of_line = True
145
146 primop  NewByteArrayOp_Addr "newAddrArray#" GenPrimOp
147    Int# -> State# s -> (# State# s, MutByteArr# s #)
148    with out_of_line = True
149
150 primop  NewByteArrayOp_Float "newFloatArray#" GenPrimOp
151    Int# -> State# s -> (# State# s, MutByteArr# s #)
152    with out_of_line = True
153
154 primop  NewByteArrayOp_Double "newDoubleArray#" GenPrimOp
155    Int# -> State# s -> (# State# s, MutByteArr# s #)
156    with out_of_line = True
157
158 primop  NewByteArrayOp_StablePtr "newStablePtrArray#" GenPrimOp
159    Int# -> State# s -> (# State# s, MutByteArr# s #)
160    with out_of_line = True
161
162
163
164 primop  ReadByteArrayOp_Char "readCharArray#" GenPrimOp
165    MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
166
167 primop  ReadByteArrayOp_Int "readIntArray#" GenPrimOp
168    MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
169
170 primop  ReadByteArrayOp_Word "readWordArray#" GenPrimOp
171    MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
172
173 primop  ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
174    MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
175
176 primop  ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
177    MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
178
179 primop  ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
180    MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
181
182 primop  ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
183    MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
184
185 primop  ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
186    MutByteArr# s -> Int# -> State# s -> (# State# s, Int64# #)
187
188 primop  ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
189    MutByteArr# s -> Int# -> State# s -> (# State# s, Word64# #)
190
191
192
193 primop  WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
194    MutByteArr# s -> Int# -> Char# -> State# s -> State# s
195    with has_side_effects = True
196
197 primop  WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
198    MutByteArr# s -> Int# -> Int# -> State# s -> State# s
199    with has_side_effects = True
200
201 primop  WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
202    MutByteArr# s -> Int# -> Word# -> State# s -> State# s
203    with has_side_effects = True
204
205 primop  WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
206    MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
207    with has_side_effects = True
208
209 primop  WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
210    MutByteArr# s -> Int# -> Float# -> State# s -> State# s
211    with has_side_effects = True
212
213 primop  WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
214    MutByteArr# s -> Int# -> Double# -> State# s -> State# s
215    with has_side_effects = True
216
217 primop  WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
218    MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
219    with has_side_effects = True
220
221 primop  WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
222    MutByteArr# s -> Int# -> Int64# -> State# s -> State# s
223    with has_side_effects = True
224
225 primop  WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
226    MutByteArr# s -> Int# -> Word64# -> State# s -> State# s
227    with has_side_effects = True
228
229
230 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
231    ByteArr# -> Int# -> Char#
232
233 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
234    ByteArr# -> Int# -> Int#
235
236 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
237    ByteArr# -> Int# -> Word#
238
239 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
240    ByteArr# -> Int# -> Addr#
241
242 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
243    ByteArr# -> Int# -> Float#
244
245 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
246    ByteArr# -> Int# -> Double#
247
248 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
249    ByteArr# -> Int# -> StablePtr# a
250
251 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
252    ByteArr# -> Int# -> Int64#
253
254 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
255    ByteArr# -> Int# -> Word64#
256
257
258
259
260 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
261    Addr# -> Int# -> State# s -> (# State# s, Char# #)
262
263 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
264    Addr# -> Int# -> State# s -> (# State# s, Int# #)
265
266 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
267    Addr# -> Int# -> State# s -> (# State# s, Word# #)
268
269 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
270    Addr# -> Int# -> State# s -> (# State# s, Addr# #)
271
272 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
273    Addr# -> Int# -> State# s -> (# State# s, Float# #)
274
275 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
276    Addr# -> Int# -> State# s -> (# State# s, Double# #)
277
278 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
279    Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
280
281 primop ReadOffAddrOp_ForeignObj "readForeignObjOffAddr#" GenPrimOp
282    Addr# -> Int# -> State# s -> (# State# s, ForeignObj# #)
283
284 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
285    Addr# -> Int# -> State# s -> (# State# s, Int64# #)
286
287 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
288    Addr# -> Int# -> State# s -> (# State# s, Word64# #)
289
290
291 primop  WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
292    Addr# -> Int# -> Char# -> State# s -> State# s
293    with has_side_effects = True
294
295 primop  WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
296    Addr# -> Int# -> Int# -> State# s -> State# s
297    with has_side_effects = True
298
299 primop  WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
300    Addr# -> Int# -> Word# -> State# s -> State# s
301    with has_side_effects = True
302
303 primop  WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
304    Addr# -> Int# -> Addr# -> State# s -> State# s
305    with has_side_effects = True
306
307 primop  WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
308    Addr# -> Int# -> Float# -> State# s -> State# s
309    with has_side_effects = True
310
311 primop  WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
312    Addr# -> Int# -> Double# -> State# s -> State# s
313    with has_side_effects = True
314
315 primop  WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
316    Addr# -> Int# -> StablePtr# a -> State# s -> State# s
317    with has_side_effects = True
318
319 primop  WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
320    Addr# -> Int# -> ForeignObj# -> State# s -> State# s
321    with has_side_effects = True
322
323 primop  WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
324    Addr# -> Int# -> Int64# -> State# s -> State# s
325    with has_side_effects = True
326
327 primop  WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
328    Addr# -> Int# -> Word64# -> State# s -> State# s
329    with has_side_effects = True
330
331
332
333 primop  NewArrayOp "newArray#" GenPrimOp
334    Int# -> a -> State# s -> (# State# s, MutArr# s a #)
335    with
336    strictness  = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
337    usage       = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
338    out_of_line = True
339
340 primop  SameMutableArrayOp "sameMutableArray#" GenPrimOp
341    MutArr# s a -> MutArr# s a -> Bool
342    with
343    usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
344
345 primop  SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
346    MutByteArr# s -> MutByteArr# s -> Bool
347
348 primop  ReadArrayOp "readArray#" GenPrimOp
349    MutArr# s a -> Int# -> State# s -> (# State# s, a #)
350    with
351    usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
352
353 primop  WriteArrayOp "writeArray#" GenPrimOp
354    MutArr# s a -> Int# -> a -> State# s -> State# s
355    with
356    usage            = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
357    strictness       = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
358    has_side_effects = True
359
360 primop  IndexArrayOp "indexArray#" GenPrimOp
361    Array# a -> Int# -> (# a #)
362    with
363    usage = { mangle  IndexArrayOp [mkM, mkP] mkM }
364
365 primop  UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
366    MutArr# s a -> State# s -> (# State# s, Array# a #)
367    with
368    usage            = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
369    has_side_effects = True
370
371 primop  UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
372    MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
373    with
374    has_side_effects = True
375
376 primop  UnsafeThawArrayOp  "unsafeThawArray#" GenPrimOp
377    Array# a -> State# s -> (# State# s, MutArr# s a #)
378    with
379    usage       = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
380    out_of_line = True
381
382 primop  SizeofByteArrayOp "sizeofByteArray#" GenPrimOp  
383    ByteArr# -> Int#
384
385 primop  SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
386    MutByteArr# s -> Int#
387
388 ------------------------------------------------------------------------
389 --- Mutable variables                                                ---
390 ------------------------------------------------------------------------
391
392 primop  NewMutVarOp "newMutVar#" GenPrimOp
393    a -> State# s -> (# State# s, MutVar# s a #)
394    with
395    usage       = { mangle NewMutVarOp [mkM, mkP] mkM }
396    strictness  = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
397    out_of_line = True
398
399 primop  ReadMutVarOp "readMutVar#" GenPrimOp
400    MutVar# s a -> State# s -> (# State# s, a #)
401    with
402    usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
403
404 primop  WriteMutVarOp "writeMutVar#"  GenPrimOp
405    MutVar# s a -> a -> State# s -> State# s
406    with
407    strictness       = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
408    usage            = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
409    has_side_effects = True
410
411 primop  SameMutVarOp "sameMutVar#" GenPrimOp
412    MutVar# s a -> MutVar# s a -> Bool
413    with
414    usage = { mangle SameMutVarOp [mkP, mkP] mkM }
415
416 ------------------------------------------------------------------------
417 --- Exceptions                                                       ---
418 ------------------------------------------------------------------------
419
420 primop  CatchOp "catch#" GenPrimOp
421           (State# RealWorld -> (# State# RealWorld, a #) )
422        -> (b -> State# RealWorld -> (# State# RealWorld, a #) ) 
423        -> State# RealWorld
424        -> (# State# RealWorld, a #)
425    with
426    strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
427         -- Catch is actually strict in its first argument
428         -- but we don't want to tell the strictness
429         -- analyser about that!
430    usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
431         --     [mkO, mkO . (inFun mkM mkO)] mkO
432         -- might use caught action multiply
433    out_of_line = True
434
435 primop  RaiseOp "raise#" GenPrimOp
436    a -> b
437    with
438    strictness  = { \ arity -> StrictnessInfo [wwLazy] True }
439       -- NB: True => result is bottom
440    usage       = { mangle RaiseOp [mkM] mkM }
441    out_of_line = True
442
443 primop  BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
444         (State# RealWorld -> (# State# RealWorld, a #))
445      -> (State# RealWorld -> (# State# RealWorld, a #))
446    with
447    strictness  = { \ arity -> StrictnessInfo [wwLazy] False }
448    out_of_line = True
449
450 primop  UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
451         (State# RealWorld -> (# State# RealWorld, a #))
452      -> (State# RealWorld -> (# State# RealWorld, a #))
453    with
454    strictness  = { \ arity -> StrictnessInfo [wwLazy] False }
455    out_of_line = True
456
457 ------------------------------------------------------------------------
458 --- MVars (not the same as mutable variables!)                       ---
459 ------------------------------------------------------------------------
460
461 primop  NewMVarOp "newMVar#"  GenPrimOp
462    State# s -> (# State# s, MVar# s a #)
463    with
464    usage       = { mangle NewMVarOp [mkP] mkR }
465    out_of_line = True
466
467 primop  TakeMVarOp "takeMVar#" GenPrimOp
468    MVar# s a -> State# s -> (# State# s, a #)
469    with
470    usage            = { mangle TakeMVarOp [mkM, mkP] mkM }
471    has_side_effects = True
472    out_of_line      = True
473
474 primop  PutMVarOp "putMVar#" GenPrimOp
475    MVar# s a -> a -> State# s -> State# s
476    with
477    strictness       = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
478    usage            = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
479    has_side_effects = True
480    out_of_line      = True
481
482 primop  SameMVarOp "sameMVar#" GenPrimOp
483    MVar# s a -> MVar# s a -> Bool
484    with
485    usage = { mangle SameMVarOp [mkP, mkP] mkM }
486
487 primop  TakeMaybeMVarOp "tryTakeMVar#" GenPrimOp
488    MVar# s a -> State# s -> (# State# s, Int#, a #)
489    with
490    usage            = { mangle TakeMaybeMVarOp [mkM, mkP] mkM }
491    has_side_effects = True
492    out_of_line      = True
493
494 primop  IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
495    MVar# s a -> State# s -> (# State# s, Int# #)
496    with
497    usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
498
499
500 ------------------------------------------------------------------------
501 --- delay/wait operations                                            ---
502 ------------------------------------------------------------------------
503
504 primop  DelayOp "delay#" GenPrimOp
505    Int# -> State# s -> State# s
506    with
507    needs_wrapper    = True
508    has_side_effects = True
509    out_of_line      = True
510
511 primop  WaitReadOp "waitRead#" GenPrimOp
512    Int# -> State# s -> State# s
513    with
514    needs_wrapper    = True
515    has_side_effects = True
516    out_of_line      = True
517
518 primop  WaitWriteOp "waitWrite#" GenPrimOp
519    Int# -> State# s -> State# s
520    with
521    needs_wrapper    = True
522    has_side_effects = True
523    out_of_line      = True
524
525 ------------------------------------------------------------------------
526 --- concurrency primitives                                           ---
527 ------------------------------------------------------------------------
528
529 primop  ForkOp "fork#" GenPrimOp
530    a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
531    with
532    usage            = { mangle ForkOp [mkO, mkP] mkR }
533    strictness       = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
534    has_side_effects = True
535    out_of_line      = True
536
537 primop  KillThreadOp "killThread#"  GenPrimOp
538    ThreadId# -> a -> State# RealWorld -> State# RealWorld
539    with
540    usage            = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
541    has_side_effects = True
542    out_of_line      = True
543
544 primop  YieldOp "yield#" GenPrimOp
545    State# RealWorld -> State# RealWorld
546    with
547    has_side_effects = True
548    out_of_line      = True
549
550 primop  MyThreadIdOp "myThreadId#" GenPrimOp
551     State# RealWorld -> (# State# RealWorld, ThreadId# #)
552
553 ------------------------------------------------------------------------
554 --- foreign objects                                                  ---
555 ------------------------------------------------------------------------
556
557 primop  MkForeignObjOp "mkForeignObj#" GenPrimOp
558    Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
559    with
560    has_side_effects = True
561    out_of_line      = True
562
563 primop  WriteForeignObjOp "writeForeignObj#" GenPrimOp
564    ForeignObj# -> Addr# -> State# s -> State# s
565    with
566    has_side_effects = True
567
568 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
569    ForeignObj# -> Addr#
570
571 primop TouchOp "touch#" GenPrimOp
572    o -> State# RealWorld -> State# RealWorld
573    with
574    strictness       = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
575
576 ------------------------------------------------------------------------
577 --- Bytecode objects                                                 ---
578 ------------------------------------------------------------------------
579
580 primop  NewBCOOp "newBCO#" GenPrimOp
581    Int# -> Int# -> Int# -> a -> State# RealWorld -> (# State# RealWorld, BCO# #)
582    with
583    has_side_effects = True
584    out_of_line      = True
585    strictness       = { \ arity -> StrictnessInfo 
586                                    [wwPrim, wwPrim, wwPrim, wwLazy, wwPrim] False }
587    usage            = { mangle NewBCOOp [mkP, mkP, mkP, mkM, mkP] mkR }
588
589 primop  WriteBCOPtrOp "writeBCOPtr#" GenPrimOp
590    BCO# -> Int# -> o -> State# RealWorld -> State# RealWorld
591    with
592    usage            = { mangle WriteBCOPtrOp [mkP, mkP, mkM, mkP] mkR }
593    strictness       = { \ arity -> StrictnessInfo 
594                                    [wwPrim, wwPrim, wwLazy, wwPrim] False }
595    has_side_effects = True
596
597 primop  WriteBCONonPtrOp "writeBCONonPtr#" GenPrimOp
598    BCO# -> Int# -> Word# -> State# RealWorld -> State# RealWorld
599    with
600    has_side_effects = True
601
602 primop  WriteBCOInstrOp "writeBCOInstr#" GenPrimOp
603    BCO# -> Int# -> Word# -> State# RealWorld -> State# RealWorld
604    with
605    has_side_effects = True
606
607 primop  ReadBCOPtrOp "readBCOPtr#"  GenPrimOp
608    BCO# -> Int# -> State# RealWorld -> (# State# RealWorld, Word# #)
609    with
610    usage = { mangle ReadBCOPtrOp [mkP, mkP] mkM }
611
612 primop  ReadBCONonPtrOp "readBCONonPtr#"  GenPrimOp
613    BCO# -> Int# -> State# RealWorld -> (# State# RealWorld, Word# #)
614
615 primop  ReadBCOInstrOp "readBCOInstr#" GenPrimOp
616    BCO# -> Int# -> State# RealWorld -> (# State# RealWorld, Word# #)
617
618 primop  SameBCOOp "sameBCO#" GenPrimOp
619    BCO# -> BCO# -> Bool
620    with
621    -- is this usage right?
622    usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
623
624
625 ------------------------------------------------------------------------
626 --- Weak pointers                                                    ---
627 ------------------------------------------------------------------------
628
629 -- note that tyvar "o" denoted openAlphaTyVar
630
631 primop  MkWeakOp "mkWeak#" GenPrimOp
632    o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
633    with
634    strictness       = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
635    usage            = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
636    has_side_effects = True
637    out_of_line      = True
638
639 primop  DeRefWeakOp "deRefWeak#" GenPrimOp
640    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
641    with
642    usage            = { mangle DeRefWeakOp [mkM, mkP] mkM }
643    has_side_effects = True
644
645 primop  FinalizeWeakOp "finalizeWeak#" GenPrimOp
646    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, 
647               (State# RealWorld -> (# State# RealWorld, Unit #)) #)
648    with
649    usage            = { mangle FinalizeWeakOp [mkM, mkP] 
650                                (mkR . (inUB FinalizeWeakOp 
651                                             [id,id,inFun FinalizeWeakOp mkR mkM])) }
652    has_side_effects = True
653    out_of_line      = True
654
655
656 ------------------------------------------------------------------------
657 --- Stable pointers and names                                        ---
658 ------------------------------------------------------------------------
659
660 primop  MakeStablePtrOp "makeStablePtr#" GenPrimOp
661    a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
662    with
663    strictness       = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
664    usage            = { mangle MakeStablePtrOp [mkM, mkP] mkM }
665    has_side_effects = True
666
667 primop  DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
668    StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
669    with
670    usage            = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
671    needs_wrapper    = True
672    has_side_effects = True
673
674 primop  EqStablePtrOp "eqStablePtr#" GenPrimOp
675    StablePtr# a -> StablePtr# a -> Int#
676    with
677    usage            = { mangle EqStablePtrOp [mkP, mkP] mkR }
678    has_side_effects = True
679
680 primop  MakeStableNameOp "makeStableName#" GenPrimOp
681    a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
682    with
683    usage            = { mangle MakeStableNameOp [mkZ, mkP] mkR }
684    strictness       = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
685    needs_wrapper    = True
686    has_side_effects = True
687    out_of_line      = True
688
689 primop  EqStableNameOp "eqStableName#" GenPrimOp
690    StableName# a -> StableName# a -> Int#
691    with
692    usage = { mangle EqStableNameOp [mkP, mkP] mkR }
693
694 primop  StableNameToIntOp "stableNameToInt#" GenPrimOp
695    StableName# a -> Int#
696    with
697    usage = { mangle StableNameToIntOp [mkP] mkR }
698
699 ------------------------------------------------------------------------
700 --- Unsafe pointer equality (#1 Bad Guy: Alistair Reid :)            ---
701 ------------------------------------------------------------------------
702
703 primop  ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
704    a -> a -> Int#
705    with
706    usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
707
708 ------------------------------------------------------------------------
709 --- Parallelism                                                      ---
710 ------------------------------------------------------------------------
711
712 primop  SeqOp "seq#" GenPrimOp
713    a -> Int#
714    with
715    usage            = { mangle  SeqOp [mkO] mkR }
716    strictness       = { \ arity -> StrictnessInfo [wwStrict] False }
717       -- Seq is strict in its argument; see notes in ConFold.lhs
718    has_side_effects = True
719
720 primop  ParOp "par#" GenPrimOp
721    a -> Int#
722    with
723    usage            = { mangle ParOp [mkO] mkR }
724    strictness       = { \ arity -> StrictnessInfo [wwLazy] False }
725       -- Note that Par is lazy to avoid that the sparked thing
726       -- gets evaluted strictly, which it should *not* be
727    has_side_effects = True
728
729 -- HWL: The first 4 Int# in all par... annotations denote:
730 --   name, granularity info, size of result, degree of parallelism
731 --      Same  structure as _seq_ i.e. returns Int#
732 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
733 --   `the processor containing the expression v'; it is not evaluated
734
735 primop  ParGlobalOp  "parGlobal#"  GenPrimOp
736    a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
737    with
738    usage            = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
739    has_side_effects = True
740
741 primop  ParLocalOp  "parLocal#"  GenPrimOp
742    a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
743    with
744    usage            = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
745    has_side_effects = True
746
747 primop  ParAtOp  "parAt#"  GenPrimOp
748    b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
749    with
750    usage            = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
751    has_side_effects = True
752
753 primop  ParAtAbsOp  "parAtAbs#"  GenPrimOp
754    a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
755    with
756    usage            = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
757    has_side_effects = True
758
759 primop  ParAtRelOp  "parAtRel#" GenPrimOp
760    a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
761    with
762    usage            = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
763    has_side_effects = True
764
765 primop  ParAtForNowOp  "parAtForNow#" GenPrimOp
766    b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
767    with
768    usage            = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
769    has_side_effects = True
770
771 primop  CopyableOp  "copyable#" GenPrimOp
772    a -> Int#
773    with
774    usage            = { mangle CopyableOp [mkZ] mkR }
775    has_side_effects = True
776
777 primop  NoFollowOp "noFollow#" GenPrimOp
778    a -> Int#
779    with
780    usage            = { mangle NoFollowOp [mkZ] mkR }
781    has_side_effects = True
782
783
784 ------------------------------------------------------------------------
785 --- tag to enum stuff                                                ---
786 ------------------------------------------------------------------------
787
788 primop  DataToTagOp "dataToTag#" GenPrimOp
789    a -> Int#
790    with
791    strictness = { \ arity -> StrictnessInfo [wwLazy] False }
792
793 primop  TagToEnumOp "tagToEnum#" GenPrimOp     
794    Int# -> a
795
796
797 thats_all_folks
798
799 ------------------------------------------------------------------------
800 ---                                                                  ---
801 ------------------------------------------------------------------------
802
803
804     -- Char#-related ops:
805
806     -- Int#-related ops:
807
808     -- Float#-related ops:
809
810     -- primitive ops for primitive arrays
811
812
813     | ReadOffAddrOp     PrimRep
814     | WriteOffAddrOp    PrimRep
815     | IndexOffAddrOp    PrimRep
816         -- PrimRep can be one of :
817         --      {Char,Int,Word,Addr,Float,Double,StablePtr,Int64,Word64}Rep.
818         -- This is just a cheesy encoding of a bunch of ops.
819         -- Note that ForeignObjRep is not included -- the only way of
820         -- creating a ForeignObj is with a ccall or casm.
821     | IndexOffForeignObjOp PrimRep
822
823     | UnsafeFreezeArrayOp | UnsafeFreezeByteArrayOp
824     | SizeofByteArrayOp   | SizeofMutableByteArrayOp
825
826
827
828     -- exceptions
829
830     -- foreign objects
831     | MkForeignObjOp
832     | WriteForeignObjOp
833
834     -- weak pointers
835     | MkWeakOp
836     | DeRefWeakOp
837     | FinalizeWeakOp
838
839     -- stable names
840     | MakeStableNameOp
841     | EqStableNameOp
842     | StableNameToIntOp
843
844     -- stable pointers
845     | MakeStablePtrOp
846     | DeRefStablePtrOp
847     | EqStablePtrOp
848
849     -- Foreign calls
850     | CCallOp CCall
851     -- Operation to test two closure addresses for equality (yes really!)
852     -- BLAME ALASTAIR REID FOR THIS!  THE REST OF US ARE INNOCENT!
853     | ReallyUnsafePtrEqualityOp
854
855     -- parallel stuff
856     | SeqOp
857     | ParOp
858
859     -- concurrency
860     | ForkOp
861     | KillThreadOp
862     | YieldOp
863     | MyThreadIdOp
864     | DelayOp
865     | WaitReadOp
866     | WaitWriteOp
867
868     -- more parallel stuff
869     | ParGlobalOp       -- named global par
870     | ParLocalOp        -- named local par
871     | ParAtOp           -- specifies destination of local par
872     | ParAtAbsOp        -- specifies destination of local par (abs processor)
873     | ParAtRelOp        -- specifies destination of local par (rel processor)
874     | ParAtForNowOp     -- specifies initial destination of global par
875     | CopyableOp        -- marks copyable code
876     | NoFollowOp        -- marks non-followup expression
877
878     -- tag-related
879     | DataToTagOp
880     | TagToEnumOp
881 -}