Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/compiler/ElabData/prim/primop.sig
 [smlnj] / sml / trunk / compiler / ElabData / prim / primop.sig

Diff of /sml/trunk/compiler/ElabData/prim/primop.sig

sml/trunk/src/compiler/FLINT/kernel/primop.sig revision 1174, Sat Mar 23 21:14:40 2002 UTC sml/trunk/compiler/ElabData/prim/primop.sig revision 4886, Wed Oct 10 16:54:46 2018 UTC
# Line 1  Line 1
1  (* Copyright 1996 by AT&T Bell Laboratories *)  (* primop.sig
2  (* primop.sig *)   *
3     * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org)
5     *)
6
7  (*********************************************************************  (*********************************************************************
8                     Integer/Word Conversions Explained                     Integer/Word Conversions Explained
# Line 118  Line 121
121  can be eliminated.  can be eliminated.
122  *********************************************************************)  *********************************************************************)
123
124  signature PRIM_OP =  signature PRIMOP =
125  sig  sig
126
127  (* numkind includes kind and number of bits *)  (* numkind includes kind and number of bits *)
# Line 126  Line 129
129    = INT of int    = INT of int
130    | UINT of int    | UINT of int
131    | FLOAT of int    | FLOAT of int
132    (* QUESTION: what about IntInf.int? *)
133
134  datatype arithop  datatype arithop
135    = + | - | * | / | ~                           (* int or float *)        = ADD | SUB | MUL | NEG                   (* int or float *)
136    | ABS | FSQRT | FSIN | FCOS | FTAN            (* floating point only *)        | FDIV | ABS | FSQRT | FSIN | FCOS | FTAN (* floating point only *)
137    | LSHIFT | RSHIFT | RSHIFTL                   (* int only *)    | LSHIFT | RSHIFT | RSHIFTL                   (* int only *)
138    | ANDB | ORB | XORB | NOTB                    (* int only *)    | ANDB | ORB | XORB | NOTB                    (* int only *)
139          | DIV | MOD | QUOT | REM                  (* int only *)
140
141  datatype cmpop = > | >= | < | <= | LEU | LTU | GEU | GTU | EQL | NEQ      datatype cmpop
142          = GT | GTE | LT | LTE                     (* signed comparisons *)
143  (*        | LEU | LTU | GEU | GTU                   (* unsigned comparisons *)
144   * Various primitive operations.  Those that are designated "inline" are        | EQL | NEQ                               (* equality *)
145   * expanded into lambda code in terms of other operators,        | FSGN                                    (* floating point only *)
146   * as is the "checked=true" version of NUMSUBSCRIPT or NUMUPDATE.
147   * NUMSUBSCRIPT and NUMUPDATE are for arrays of floats or integers    (* datatype primop:
148   * stored WITHOUT boxing or tags.     * Various primitive operations. Those that are designated "inline" (L:) in
149       * the comments are expanded into lambda code in terms of other operators,
150       * as are the "checked=true" versions of NUMSUBSCRIPT and NUMUPDATE (L?:).
151       * "Environmental" primops (occurring in the InLine structure) are indicated
152       * by "E:" in the comment.
153   *)   *)
154  datatype primop  datatype primop
155    = ARITH of {oper: arithop, overflow: bool, kind: numkind}        = ARITH of {                              (* E: arithmetic ops *)
156    | INLLSHIFT of numkind              oper: arithop, overflow: bool, kind: numkind
157    | INLRSHIFT of numkind            }
158    | INLRSHIFTL of numkind        | INLLSHIFT of numkind                    (* E: left shift *)
159    | CMP of {oper: cmpop, kind: numkind}        | INLRSHIFT of numkind                    (* E: right shift *)
160          | INLRSHIFTL of numkind                   (* E: right shift logical *)
161    | TESTU of int * int        | CMP of {oper: cmpop, kind: numkind}     (* E: generic compare *)
162    | TEST of int * int        | TESTU of int * int                      (* E: conversions to int, e.g. testu_31_31 *)
163    | TRUNC of int * int        | TEST of int * int                       (* E: conversions to int, e.g. test_32_31_w *)
164    | EXTEND of int * int        | TRUNC of int * int                      (* E: truncations to smaller int/word, e.g. trunc_32_31_i *)
165    | COPY of int * int        | EXTEND of int * int                     (* E: extensions to int32, word32 *)
166          | COPY of int * int                       (* E: conversions, e.g. copy_32_32_ii *)
167    | ROUND of {floor: bool, fromkind: numkind, tokind: numkind}        | TEST_INF of int                         (* E: intinf conversions, e.g. test_inf_31 *)
168    | REAL of {fromkind: numkind, tokind: numkind}        | TRUNC_INF of int                        (* E: intinf truncations, e.g. trunc_inf_31 *)
169          | EXTEND_INF of int                       (* E: intinf extensions, e.g. extend_8_inf *)
170    | NUMSUBSCRIPT of {kind: numkind, checked: bool, immutable: bool}        | COPY_INF of int                         (* E: conversions to intinf, e.g. copy_8_inf *)
171    | NUMUPDATE of {kind: numkind, checked: bool}        | ROUND of {                              (* E: floor, round *)
172                floor: bool, fromkind: numkind, tokind: numkind
173    | SUBSCRIPT                  (* polymorphic array subscript *)            }
174    | SUBSCRIPTV                 (* poly vector subscript *)        | REAL of {                               (* E: real, real32 *)
175    | INLSUBSCRIPT               (* inline poly array subscript *)              fromkind: numkind, tokind: numkind
176    | INLSUBSCRIPTV              (* inline poly vector subscript *)            }
177    | INLMKARRAY                 (* inline poly array creation *)        | NUMSUBSCRIPT of {                       (* E: L?: ordof, etc. *)
178                kind: numkind, checked: bool, immutable: bool
179    | PTREQL | PTRNEQ            (* pointer equality *)            }
180    | POLYEQL | POLYNEQ          (* polymorphic equality *)        | NUMUPDATE of {                          (* E: L?: store, etc. *)
181    | BOXED | UNBOXED            (* boxity tests *)              kind: numkind, checked: bool
182    | LENGTH                     (* vector, string, array, ... length *)            }
183    | OBJLENGTH                  (* length of arbitrary heap object *)        | SUBSCRIPT                               (* E: polymorphic array subscript *)
184    | CAST        | SUBSCRIPTV                              (* E: poly vector subscript *)
185    | WCAST        | INLSUBSCRIPT                            (* E: L: poly array subscript *)
186    | GETRUNVEC                  (* get the pointer to the run-vector *)        | INLSUBSCRIPTV                           (* E: L: poly vector subscript *)
187    | MARKEXN                    (* mark an exception value with a string *)        | INLMKARRAY                              (* E: L: poly array creation *)
188    | GETHDLR | SETHDLR          (* get/set exn handler pointer *)        | PTREQL | PTRNEQ                         (* E: pointer equality *)
189    | GETVAR | SETVAR            (* get/set var register *)        | POLYEQL | POLYNEQ                       (* E: polymorphic equality *)
190    | GETPSEUDO | SETPSEUDO      (* get/set pseudo registers *)        | BOXED | UNBOXED                         (* E: boxity tests *)
191    | SETMARK | DISPOSE          (* capture/dispose frames *)        | LENGTH                                  (* E: vector, string, array, ... length *)
192    | MAKEREF                    (* allocate a ref cell *)        | OBJLENGTH                               (* E: length of arbitrary heap object *)
193    | CALLCC | CAPTURE | THROW   (* continuation operations *)        | CAST                                    (* E: cast *)
194    | ISOLATE                    (* isolating a function *)        | GETHDLR | SETHDLR                       (* E: get/set exn handler pointer *)
195    | DEREF                      (* dereferencing *)        | GETVAR | SETVAR                         (* E: get/set var register *)
196    | ASSIGN                     (* assignment *)        | MAKEREF                                 (* E: allocate a ref cell *)
197    | UNBOXEDASSIGN              (* assignment to integer reference *)        | CALLCC | CAPTURE | THROW                (* E: continuation operations *)
198    | UPDATE                     (* array update (maybe boxed) *)        | ISOLATE                                 (* E: isolating a function *)
199    | INLUPDATE                  (* inline array update (maybe boxed) *)        | DEREF                                   (* E: dereferencing *)
200    | BOXEDUPDATE                (* boxed array update *)        | ASSIGN                                  (* E: assignment *)
201    | UNBOXEDUPDATE              (* update array of integers WITH tags *)        | UPDATE                                  (* E: array or reference update (maybe boxed) *)
202          | INLUPDATE                               (* E: L: array update (maybe boxed) *)
203    | GETTAG                     (* extract the tag portion of an *)        | UNBOXEDUPDATE                           (* E: update array of integers WITH tags
204                                 (* object's descriptor as an ML int *)                                                   * removed by Zhong, put back by Matthias
205    | MKSPECIAL                  (* make a special object *)                                                   * (see FLINT/trans/primopmap.sml) *)
206    | SETSPECIAL                 (* set the state of a special object *)        | GETTAG                                  (* E: extract the tag portion of an
207    | GETSPECIAL                 (* get the state of a special object *)                                                   * object's descriptor as an ML int *)
208    | USELVAR | DEFLVAR        | MKSPECIAL                               (* E: make a special object *)
209    | INLDIV | INLMOD | INLREM   (* inline interger arithmetic *)        | SETSPECIAL                              (* E: set the state of a special object *)
210    | INLMIN |INLMAX | INLABS    (* inline interger arithmetic *)        | GETSPECIAL                              (* E: get the state of a special object *)
211    | INLNOT                     (* inline bool not operator *)        | INLMIN of numkind                       (* E: L: min *)
212    | INLCOMPOSE                 (* inline compose "op o"  operator *)        | INLMAX of numkind                       (* E: L: max *)
213    | INLBEFORE                  (* inline "before" operator *)        | INLABS of numkind                       (* E: L: abs *)
214    | INL_ARRAY                  (* inline polymorphic array allocation *)        | INLNOT                                  (* E: L: bool not operator *)
215    | INL_VECTOR                 (* inline polymorphic vector allocation *)        | INLCOMPOSE                              (* E: L: compose "op o"  operator *)
216    | INL_MONOARRAY of numkind   (* inline monomorphic array allocation *)        | INLBEFORE                               (* E: L: "before" operator *)
217    | INL_MONOVECTOR of numkind  (* inline monomorphic vector allocation *)        | INLIGNORE                               (* E: L: "ignore" function *)
218        (* primops to support new array representations *)
219    | MKETAG                     (* make a new exception tag *)        | NEW_ARRAY0                              (* E: allocate zero-length array header *)
220    | WRAP                       (* box a value by wrapping it *)        | GET_SEQ_DATA                            (* E: get data pointer from arr/vec header *)
221    | UNWRAP                     (* unbox a value by unwrapping it *)        | SUBSCRIPT_REC                           (* E: record subscript operation *)
222  (* Primops to support new array representations *)        | SUBSCRIPT_RAW64                         (* E: raw64 subscript operation *)
223    | NEW_ARRAY0                  (* allocate zero-length array header *)        | INLIDENTITY                             (* E: polymorphic identity *)
224    | GET_SEQ_DATA                (* get data pointer from arr/vec header *)        | CVT64                                   (* E: convert between external and
225    | SUBSCRIPT_REC               (* record subscript operation *)                                                   * internal representation of compiler
226    | SUBSCRIPT_RAW64             (* raw64 subscript operation *)                                                   * simulated 64-bit scalars, e.g. w64p *)
227  (* Primops to support new experimental C FFI. *)      (* Primops to support C FFI. *)
228    | RAW_LOAD of numkind         (* load from arbitrary memory location *)        | RAW_LOAD of numkind                     (* E: load from arbitrary memory location *)
229    | RAW_STORE of numkind        (* store to arbitrary memory location *)        | RAW_STORE of numkind                    (* E: store to arbitrary memory location *)
230      (* make a call to a C-function;      (* E: make a call to a C-function;
231       * The primop carries C function prototype information and specifies       * The primop carries C function prototype information and specifies
232       * which of its (ML-) arguments are floating point. C prototype       * which of its (ML-) arguments are floating point. C prototype
233       * information is for use by the backend, ML information is for       * information is for use by the backend, ML information is for
234       * use by the CPS converter. *)       * use by the CPS converter. *)
235    | RAW_CCALL of { c_proto: CTypes.c_proto,        | RAW_CCALL of {
236                c_proto: PrimCTypes.c_proto,
237                     ml_args: ccall_type list,                     ml_args: ccall_type list,
238                     ml_res_opt: ccall_type option,                     ml_res_opt: ccall_type option,
239                     reentrant : bool                     reentrant : bool
240                   } option                   } option
241     (* Allocate uninitialized storage on the heap.     (* Allocate uninitialized storage on the heap.
242      * The record is meant to hold short-lived C objects, i.e., they      * The record is meant to hold short-lived C objects, i.e., they
243      * are not ML pointers.  With the tag, the representation is      * are not ML pointers.  The representation is
244      * the same as RECORD with tag tag_raw32 (sz=4), or tag_fblock (sz=8)      * the same as RECORD with tag tag_raw32 or tag_fblock.
245      *)      *)
246    | RAW_RECORD of {tag:bool,sz:int}        | RAW_RECORD of { fblock: bool }  (* E: *)
and ccall_type = CCALL_INT32 | CCALL_REAL64 | CCALL_ML_PTR
247
249          | UNBOXEDASSIGN                   (* assignment to integer reference *)
250
251          | WCAST                           (* ? *)
252          | MARKEXN                         (* mark an exception value with a string *)
253
254          | INL_ARRAY                       (* L: polymorphic array allocation *)
255          | INL_VECTOR                      (* L: polymorphic vector allocation *)
256          | INL_MONOARRAY of numkind        (* L: monomorphic array allocation *)
257          | INL_MONOVECTOR of numkind       (* L: monomorphic vector allocation *)
258
259          | MKETAG                          (* make a new exception tag *)
260          | WRAP                            (* box a value by wrapping it *)
261          | UNWRAP                          (* unbox a value by unwrapping it *)
262
263        and ccall_type =
264            CCI32 |                         (* passed as int32 *)
265            CCI64 |                         (* int64, currently unused *)
266            CCR64 |                         (* passed as real64 *)
267            CCML                            (* passed as Unsafe.Object.object *)
268
270  val ISUB : primop  (* default integer subtraction *)  val ISUB : primop  (* default integer subtraction *)
# Line 250  Line 279
279  val ILT : primop  val ILT : primop
280  val ILE : primop  val ILE : primop
281  val IGE : primop  val IGE : primop
282        val UIEQL : primop  (* for UINT kind, may not matter *)
283
284        val mkIEQL : int -> primop   (* make equality primop for other sizes *)
285        val mkUIEQL : int -> primop  (* and for unsigned (kind = UINT) *)
286
287  val prNumkind : numkind -> string  val prNumkind : numkind -> string
288  val prPrimop: primop -> string  val prPrimop: primop -> string
289  val mayRaise : primop -> bool  val mayRaise : primop -> bool
290
291  (* This should return more than just a boolean.  (* This should return more than just a boolean.
292   * True means "can not be dead-code eliminated" *)   * True means "can not be dead-code eliminated" *)
293  val effect : primop -> bool  val effect : primop -> bool

Legend:
 Removed from v.1174 changed lines Added in v.4886