1(*
2    Signature for built-in functions
3
4    Copyright David C. J. Matthews 2016
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License version 2.1 as published by the Free Software Foundation.
9    
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14    
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18*)
19
20signature BUILTINS =
21sig
22    datatype testConditions =
23        TestEqual (* No TestNotEqual because that is always generated with "not" *)
24    |   TestLess
25    |   TestLessEqual
26    |   TestGreater
27    |   TestGreaterEqual
28
29    datatype arithmeticOperations =
30        ArithAdd
31    |   ArithSub
32    |   ArithMult
33    |   ArithQuot
34    |   ArithRem
35    |   ArithDiv
36    |   ArithMod
37
38    datatype logicalOperations =
39        LogicalAnd
40    |   LogicalOr
41    |   LogicalXor
42    
43    datatype shiftOperations =
44        ShiftLeft
45    |   ShiftRightLogical   (* Logical shift - zero added bits. *)
46    |   ShiftRightArithmetic (* Arithmetic shift - add the sign bit. *)
47
48    datatype unaryOps =
49        NotBoolean (* true => false; false => true - XOR *)
50    |   IsTaggedValue (* Test the tag bit. *)
51    |   MemoryCellLength (* Return the length of a memory cell (heap object) *)
52    |   MemoryCellFlags (* Return the flags byte of a memory cell (heap object) *)
53    |   ClearMutableFlag (* Remove the mutable flag from the flags byte *)
54    |   AtomicIncrement
55    |   AtomicDecrement
56    |   AtomicReset (* Set a value to (tagged) zero atomically. *)
57    |   LongWordToTagged (* Convert a LargeWord.word to a Word.word or FixedInt.int. *)
58    |   SignedToLongWord (* Convert a tagged value to a LargeWord with sign extension. *)
59    |   UnsignedToLongWord (* Convert a tagged value to a LargeWord without sign extension. *)
60    |   RealAbs     (* Set the sign bit of a real to positive. *)
61    |   RealNeg     (* Invert the sign bit of a real. *)
62    |   FloatFixedInt (* Convert an integer value into a floating point value. *)
63
64    and binaryOps =
65        (* Compare two words and return the result.  This is used for both
66           word values (isSigned=false) and fixed precision integer (isSigned=true).
67           Tests for (in)equality can also be done on pointers in which case
68           this is pointer equality. *)
69        WordComparison of { test: testConditions, isSigned: bool }
70        (* Fixed precision int operations.  These may raise Overflow. *)
71    |   FixedPrecisionArith of arithmeticOperations
72        (* Arithmetic operations on word values.  These do not raise Overflow. *)
73    |   WordArith of arithmeticOperations
74        (* Load a word at a specific offset in a heap object.  If this is immutable and the
75           arguments are constants it can be folded at compile time since the result will
76           never change. *)
77    |   WordLogical of logicalOperations (* Logical operations on words. *)
78    |   WordShift of shiftOperations (* Shift operations on words. *)
79         (* Allocate a heap cell for byte data.  The first argument is the number of words (not bytes)
80            needed.  The second argument is the "flags" byte which must include F_bytes and F_mutable.
81            The new cell is not initialised. *)
82    |   AllocateByteMemory
83        (* Operations on LargeWords.  These are 32/64 bit values that are "boxed". *)
84    |   LargeWordComparison of testConditions
85    |   LargeWordArith of arithmeticOperations
86    |   LargeWordLogical of logicalOperations
87    |   LargeWordShift of shiftOperations
88    |   RealComparison of testConditions
89    |   RealArith of arithmeticOperations
90        
91    val unaryRepr: unaryOps -> string
92    and binaryRepr: binaryOps -> string
93    and testRepr: testConditions -> string
94    and arithRepr: arithmeticOperations -> string
95end;
96