[project @ 1999-02-05 16:02:18 by simonm]
[ghc-hetmet.git] / ghc / rts / Bytecodes.h
1 /* -*- mode: hugs-c; -*- */
2 /* -----------------------------------------------------------------------------
3  * $Id: Bytecodes.h,v 1.3 1999/02/05 16:02:36 simonm Exp $
4  *
5  * (c) The GHC Team, 1998-1999
6  *
7  * Bytecode definitions.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 /* --------------------------------------------------------------------------
12  * Instructions
13  *
14  * Notes:
15  * o INTERNAL_ERROR is never generated by the compiler and usually
16  *   indicates as error in the heap.
17  *   PANIC is generated by the compiler whenever it tests an "irrefutable"
18  *   pattern which fails.  If we don't see too many of these, we could
19  *   optimise out the redundant test.
20  *
21  * o If you add any new instructions, you have to check that each enumeration
22  *   has at most 256 entries in it --- some of the lists are very close to
23  *   overflowing.
24  * ------------------------------------------------------------------------*/
25
26 typedef enum
27     { i_INTERNAL_ERROR  /* Instruction 0 raises an internal error */
28
29     , i_PANIC           /* irrefutable pattern match failed! */
30
31     , i_STK_CHECK
32     , i_HP_CHECK
33
34     , i_ARG_CHECK
35
36     , i_ALLOC_AP
37     , i_ALLOC_PAP
38     , i_ALLOC_CONSTR
39     , i_MKAP
40     , i_MKPAP
41     , i_PACK
42
43     , i_SLIDE
44
45     , i_TEST
46     , i_UNPACK
47
48     , i_VAR
49     , i_CONST
50     , i_CONST2 /* 16 bit offsets - ad-hoc fix for general problem */
51     , i_ENTER
52
53     , i_RETADDR
54
55     , i_VOID
56
57     , i_RETURN_GENERIC
58
59     , i_VAR_INT
60     , i_CONST_INT
61     , i_RETURN_INT
62     , i_PACK_INT
63     , i_UNPACK_INT
64     , i_TEST_INT
65
66 #ifdef PROVIDE_INT64
67     , i_VAR_INT64
68     , i_CONST_INT64
69     , i_RETURN_INT64
70     , i_PACK_INT64
71     , i_UNPACK_INT64
72 #endif
73 #ifdef PROVIDE_INTEGER
74     , i_CONST_INTEGER
75 #endif
76 #ifdef PROVIDE_WORD
77     , i_VAR_WORD
78     , i_CONST_WORD
79     , i_RETURN_WORD
80     , i_PACK_WORD
81     , i_UNPACK_WORD
82 #endif
83 #ifdef PROVIDE_ADDR
84     , i_VAR_ADDR
85     , i_CONST_ADDR
86     , i_RETURN_ADDR
87     , i_PACK_ADDR
88     , i_UNPACK_ADDR
89 #endif
90     , i_VAR_CHAR
91     , i_CONST_CHAR
92     , i_RETURN_CHAR
93     , i_PACK_CHAR
94     , i_UNPACK_CHAR
95
96     , i_VAR_FLOAT
97     , i_CONST_FLOAT
98     , i_RETURN_FLOAT
99     , i_PACK_FLOAT
100     , i_UNPACK_FLOAT
101
102     , i_VAR_DOUBLE
103     , i_CONST_DOUBLE
104     , i_RETURN_DOUBLE
105     , i_PACK_DOUBLE
106     , i_UNPACK_DOUBLE
107
108 #ifdef PROVIDE_STABLE
109     , i_VAR_STABLE
110     , i_RETURN_STABLE
111     , i_PACK_STABLE
112     , i_UNPACK_STABLE
113 #endif
114
115     , i_PRIMOP1         /* Primop: next byte is an Primop1 */
116     , i_PRIMOP2         /* Primop: next byte is an Primop2 */
117
118     , MAX_Instr = i_PRIMOP2
119 } Instr;
120
121 typedef enum
122     { i_INTERNAL_ERROR1  /* Instruction 0 raises an internal error */
123
124     /* Char# operations */
125     , i_gtChar
126     , i_geChar
127     , i_eqChar
128     , i_neChar
129     , i_ltChar
130     , i_leChar
131     , i_charToInt
132     , i_intToChar
133
134     /* Int# operations */
135     , i_gtInt
136     , i_geInt
137     , i_eqInt
138     , i_neInt
139     , i_ltInt
140     , i_leInt
141     , i_minInt
142     , i_maxInt
143     , i_plusInt
144     , i_minusInt
145     , i_timesInt
146     , i_quotInt
147     , i_remInt
148     , i_quotRemInt
149     , i_negateInt
150     , i_andInt
151     , i_orInt
152     , i_xorInt
153     , i_notInt
154     , i_shiftLInt
155     , i_shiftRAInt
156     , i_shiftRLInt
157
158 #ifdef PROVIDE_INT64
159     /* Int64# operations */
160     , i_gtInt64
161     , i_geInt64
162     , i_eqInt64
163     , i_neInt64
164     , i_ltInt64
165     , i_leInt64
166     , i_minInt64
167     , i_maxInt64
168     , i_plusInt64
169     , i_minusInt64
170     , i_timesInt64
171     , i_quotInt64
172     , i_remInt64
173     , i_quotRemInt64
174     , i_negateInt64
175     , i_andInt64
176     , i_orInt64
177     , i_xorInt64
178     , i_notInt64
179     , i_shiftLInt64
180     , i_shiftRAInt64
181     , i_shiftRLInt64
182     , i_int64ToInt 
183     , i_intToInt64 
184 #ifdef PROVIDE_WORD
185     , i_int64ToWord 
186     , i_wordToInt64 
187 #endif
188     , i_int64ToFloat 
189     , i_floatToInt64 
190     , i_int64ToDouble 
191     , i_doubleToInt64 
192 #endif
193 #ifdef PROVIDE_WORD
194     /* Word# operations */
195     , i_gtWord
196     , i_geWord
197     , i_eqWord
198     , i_neWord
199     , i_ltWord
200     , i_leWord
201     , i_minWord
202     , i_maxWord
203     , i_plusWord
204     , i_minusWord
205     , i_timesWord
206     , i_quotWord
207     , i_remWord
208     , i_quotRemWord
209     , i_negateWord
210     , i_andWord
211     , i_orWord
212     , i_xorWord
213     , i_notWord
214     , i_shiftLWord
215     , i_shiftRAWord
216     , i_shiftRLWord
217     , i_intToWord
218     , i_wordToInt
219 #endif
220 #ifdef PROVIDE_ADDR
221     /* Addr# operations */
222     , i_gtAddr
223     , i_geAddr
224     , i_eqAddr
225     , i_neAddr
226     , i_ltAddr
227     , i_leAddr
228     , i_intToAddr
229     , i_addrToInt
230
231     /* Stateless Addr operations */
232     , i_indexCharOffAddr
233     , i_indexIntOffAddr
234 #ifdef PROVIDE_INT64
235     , i_indexInt64OffAddr
236 #endif
237 #ifdef PROVIDE_WORD
238     , i_indexWordOffAddr
239 #endif
240 #ifdef PROVIDE_ADDR
241     , i_indexAddrOffAddr
242 #endif
243     , i_indexFloatOffAddr
244     , i_indexDoubleOffAddr
245 #ifdef PROVIDE_STABLE
246     , i_indexStableOffAddr
247 #endif
248
249     , i_readCharOffAddr
250     , i_readIntOffAddr
251 #ifdef PROVIDE_INT64
252     , i_readInt64OffAddr
253 #endif
254 #ifdef PROVIDE_WORD
255     , i_readWordOffAddr
256 #endif
257 #ifdef PROVIDE_ADDR
258     , i_readAddrOffAddr
259 #endif
260     , i_readFloatOffAddr
261     , i_readDoubleOffAddr
262 #ifdef PROVIDE_STABLE
263     , i_readStableOffAddr
264 #endif
265
266     , i_writeCharOffAddr
267     , i_writeIntOffAddr
268 #ifdef PROVIDE_INT64
269     , i_writeInt64OffAddr
270 #endif
271 #ifdef PROVIDE_WORD
272     , i_writeWordOffAddr
273 #endif
274 #ifdef PROVIDE_ADDR
275     , i_writeAddrOffAddr
276 #endif
277     , i_writeFloatOffAddr
278     , i_writeDoubleOffAddr
279 #ifdef PROVIDE_STABLE
280     , i_writeStableOffAddr
281 #endif
282
283 #endif /* PROVIDE_ADDR */
284
285 #ifdef PROVIDE_INTEGER
286     /* Integer operations */
287     , i_compareInteger
288     , i_negateInteger
289     , i_plusInteger
290     , i_minusInteger
291     , i_timesInteger
292     , i_quotRemInteger
293     , i_divModInteger
294     , i_integerToInt
295     , i_intToInteger
296 #ifdef PROVIDE_INT64
297     , i_integerToInt64
298     , i_int64ToInteger
299 #endif
300 #ifdef PROVIDE_WORD
301     , i_integerToWord
302     , i_wordToInteger
303 #endif
304     , i_integerToFloat
305     , i_floatToInteger
306     , i_integerToDouble
307     , i_doubleToInteger
308 #endif
309
310     /* Float# operations */
311     , i_gtFloat
312     , i_geFloat
313     , i_eqFloat
314     , i_neFloat
315     , i_ltFloat
316     , i_leFloat
317     , i_minFloat
318     , i_maxFloat
319     , i_radixFloat
320     , i_digitsFloat
321     , i_minExpFloat
322     , i_maxExpFloat
323     , i_plusFloat
324     , i_minusFloat
325     , i_timesFloat
326     , i_divideFloat
327     , i_negateFloat
328     , i_floatToInt
329     , i_intToFloat
330     , i_expFloat
331     , i_logFloat
332     , i_sqrtFloat
333     , i_sinFloat
334     , i_cosFloat
335     , i_tanFloat
336     , i_asinFloat
337     , i_acosFloat
338     , i_atanFloat
339     , i_sinhFloat
340     , i_coshFloat
341     , i_tanhFloat
342     , i_powerFloat
343 #ifdef PROVIDE_INT64
344     , i_decodeFloatz
345     , i_encodeFloatz
346 #endif
347 #ifdef PROVIDE_INTEGER
348     , i_decodeFloatZ
349     , i_encodeFloatZ
350 #endif
351     , i_isNaNFloat
352     , i_isInfiniteFloat
353     , i_isDenormalizedFloat
354     , i_isNegativeZeroFloat
355     , i_isIEEEFloat
356
357     /* Double# operations */
358     , i_gtDouble
359     , i_geDouble
360     , i_eqDouble
361     , i_neDouble
362     , i_ltDouble
363     , i_leDouble
364     , i_minDouble
365     , i_maxDouble
366     , i_radixDouble
367     , i_digitsDouble
368     , i_minExpDouble
369     , i_maxExpDouble
370     , i_plusDouble
371     , i_minusDouble
372     , i_timesDouble
373     , i_divideDouble
374     , i_negateDouble
375     , i_doubleToInt
376     , i_intToDouble
377     , i_doubleToFloat
378     , i_floatToDouble
379     , i_expDouble
380     , i_logDouble
381     , i_sqrtDouble
382     , i_sinDouble
383     , i_cosDouble
384     , i_tanDouble
385     , i_asinDouble
386     , i_acosDouble
387     , i_atanDouble
388     , i_sinhDouble
389     , i_coshDouble
390     , i_tanhDouble
391     , i_powerDouble
392 #ifdef PROVIDE_INT64
393     , i_decodeDoublez
394     , i_encodeDoublez
395 #endif
396 #ifdef PROVIDE_INTEGER
397     , i_decodeDoubleZ
398     , i_encodeDoubleZ
399 #endif
400     , i_isNaNDouble
401     , i_isInfiniteDouble
402     , i_isDenormalizedDouble
403     , i_isNegativeZeroDouble
404     , i_isIEEEDouble
405
406     /* If you add a new primop to this table, check you don't
407      * overflow the 256 limit.  That is MAX_Primop1 <= 255.
408      * Current value (30/10/98) = 0xc8
409      */
410     , MAX_Primop1 = i_isIEEEDouble
411 } Primop1;
412
413
414 typedef enum
415     { i_INTERNAL_ERROR2  /* Instruction 0 raises an internal error */
416
417     , i_raise       
418     , i_catch       
419     , i_force
420
421 #ifdef PROVIDE_ARRAY
422     /* Ref operations */
423     , i_newRef
424     , i_writeRef
425     , i_readRef
426     , i_sameRef
427
428     /* Prim[Mutable]Array operations */
429     , i_sameMutableArray
430     , i_unsafeFreezeArray
431
432     , i_newArray
433     , i_writeArray
434     , i_readArray
435     , i_indexArray
436     , i_sizeArray
437     , i_sizeMutableArray
438
439     /* Prim[Mutable]ByteArray operations */
440     , i_sameMutableByteArray
441     , i_unsafeFreezeByteArray
442     , i_newByteArray
443
444     , i_writeCharArray
445     , i_readCharArray
446     , i_indexCharArray
447
448     , i_writeIntArray
449     , i_readIntArray
450     , i_indexIntArray
451
452 #ifdef PROVIDE_INT64
453     , i_writeInt64Array
454     , i_readInt64Array
455     , i_indexInt64Array
456 #endif
457
458     /* {write,read,index}IntegerArray not provided */
459
460 #ifdef PROVIDE_WORD
461     , i_writeWordArray
462     , i_readWordArray
463     , i_indexWordArray
464 #endif
465 #ifdef PROVIDE_ADDR
466     , i_writeAddrArray
467     , i_readAddrArray
468     , i_indexAddrArray
469 #endif
470     , i_writeFloatArray
471     , i_readFloatArray
472     , i_indexFloatArray
473
474     , i_writeDoubleArray
475     , i_readDoubleArray
476     , i_indexDoubleArray
477
478 #ifdef PROVIDE_STABLE
479     , i_writeStableArray
480     , i_readStableArray
481     , i_indexStableArray
482 #endif
483
484     /* {write,read,index}ForeignObjArray not provided */
485
486 #endif /* PROVIDE_ARRAY */
487
488 #ifdef PROVIDE_PTREQUALITY
489     , i_reallyUnsafePtrEquality
490 #endif
491 #ifdef PROVIDE_COERCE
492     , i_unsafeCoerce
493 #endif
494
495 #ifdef PROVIDE_FOREIGN
496     /* ForeignObj# operations */
497     , i_makeForeignObj
498
499     , indexCharOffForeignObj
500     , indexIntOffForeignObj
501     , indexInt64OffForeignObj
502     , indexWordOffForeignObj
503     , indexAddrOffForeignObj
504     , indexFloatOffForeignObj
505     , indexDoubleOffForeignObj
506     , indexStablePtrOffForeignObj
507 #endif
508 #ifdef PROVIDE_WEAK
509     /* Weak# operations */
510     , i_makeWeak
511     , i_deRefWeak
512 #endif 
513 #ifdef PROVIDE_STABLE
514     /* StablePtr# operations */
515     , i_makeStablePtr
516     , i_deRefStablePtr
517     , i_freeStablePtr
518 #endif
519
520 #ifdef PROVIDE_CONCURRENT
521     /* Concurrency operations */
522     , i_fork
523     , i_killThread
524     , i_sameMVar
525     , i_newMVar
526     , i_takeMVar
527     , i_putMVar
528     , i_delay
529     , i_waitRead
530     , i_waitWrite
531 #endif
532
533     /* CCall! */
534     , i_ccall_Id
535     , i_ccall_IO
536
537     /* If you add a new primop to this table, check you don't
538      * overflow the 256 limit.  That is MAX_Primop2 <= 255.
539      * Current value (30/10/98) = 0x42
540      */
541     , MAX_Primop2 = i_ccall_IO
542 } Primop2;
543
544 typedef unsigned int InstrPtr; /* offset of instruction within BCO */
545
546 /*-------------------------------------------------------------------------*/