1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
(*
Title: Foreign Function Interface: constants
Author: David Matthews
Copyright David Matthews 2015, 2016-17
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*)
(* This is defined separately so that the values are computed and
available as constants for the Foreign structure. *)
structure ForeignConstants =
struct
local
val ffiGeneralCall = RunCall.rtsCallFull2 "PolyFFIGeneral"
fun ffiGeneral(code: int, arg: 'a): 'b = RunCall.unsafeCast(ffiGeneralCall(RunCall.unsafeCast(code, arg)))
in
local
fun getSizeAndAlign (n: int) =
let
val ffiType = ffiGeneral (52, n)
val (size: word, align: word, _, _) = (* Just get the first two fields. *)
ffiGeneral (53, ffiType)
in
{size=size, align=align}
end
in
val saVoid = getSizeAndAlign 0
and saUint8 = getSizeAndAlign 1
and saSint8 = getSizeAndAlign 2
and saUint16 = getSizeAndAlign 3
and saSint16 = getSizeAndAlign 4
and saUint32 = getSizeAndAlign 5
and saSint32 = getSizeAndAlign 6
and saUint64 = getSizeAndAlign 7
and saSint64 = getSizeAndAlign 8
and saFloat = getSizeAndAlign 9
and saDouble = getSizeAndAlign 10
and saPointer = getSizeAndAlign 11
and saUChar = getSizeAndAlign 12
and saSChar = getSizeAndAlign 13
and saUShort = getSizeAndAlign 14
and saSShort = getSizeAndAlign 15
and saUint = getSizeAndAlign 16
and saSint = getSizeAndAlign 17
and saUlong = getSizeAndAlign 18
and saSlong = getSizeAndAlign 19
end
val bigEndian : bool = LibrarySupport.bigEndian
and wordSize : word = RunCall.bytesPerWord
(* Minimum argument size. *)
val ffiMinArgSize: Word.word = ffiGeneral (51, 15)
end
end;
|