| 1 |
(* c-int.sig |
| 2 |
* 2005 Matthew Fluet ([email protected]) |
| 3 |
* Adapted for MLton. |
| 4 |
*) |
| 5 |
|
| 6 |
(* |
| 7 |
* A "private" extension to the encoding of C types in SML. |
| 8 |
* The routines here are for use by code that will be automatically |
| 9 |
* generated from corresponding C files. User code is not supposed |
| 10 |
* to access them because they are unsafe. (As if subverting the C |
| 11 |
* type system were such a big deal...) |
| 12 |
* |
| 13 |
* (C) 2001, Lucent Technologies, Bell Laboratories |
| 14 |
* |
| 15 |
* author: Matthias Blume ([email protected]) |
| 16 |
*) |
| 17 |
signature C_INT = sig |
| 18 |
|
| 19 |
include C |
| 20 |
|
| 21 |
type addr = CMemory.addr |
| 22 |
|
| 23 |
(* make struct or union size from its size given as a word; |
| 24 |
* needs explicit type constraint *) |
| 25 |
val mk_su_size : word -> 's S.size |
| 26 |
|
| 27 |
(* make struct or union RTTI given its corresponding size *) |
| 28 |
val mk_su_typ : 's su S.size -> 's su T.typ |
| 29 |
|
| 30 |
(* make function pointer type give the ML function that |
| 31 |
* implements the calling protocol *) |
| 32 |
val mk_fptr_typ : (addr -> 'a -> 'b) -> ('a -> 'b) fptr T.typ |
| 33 |
|
| 34 |
(* mk_obj' makes light-weight objects *) |
| 35 |
val mk_obj' : addr -> ('t, 'c) obj' |
| 36 |
|
| 37 |
(* make a void* from an address *) |
| 38 |
val mk_voidptr : addr -> voidptr |
| 39 |
|
| 40 |
(* given the function that implements the calling protocol and the |
| 41 |
* functions raw address, make a function pointer *) |
| 42 |
val mk_fptr : (addr -> 'a -> 'b) * addr -> ('a -> 'b) fptr |
| 43 |
|
| 44 |
(* making normal and const-declared struct- or union-fields |
| 45 |
* given the field's type and its offset *) |
| 46 |
val mk_rw_field : 'm T.typ * int * ('s, 'c) su_obj -> ('m, 'c) obj |
| 47 |
val mk_ro_field : 'm T.typ * int * ('s, 'c) su_obj -> ('m, ro) obj |
| 48 |
|
| 49 |
(* light version *) |
| 50 |
(* NOTE: We do not pass RTTI to the light version (which would |
| 51 |
* internally throw it away anyway). This means that we |
| 52 |
* will need an explicit type constraint. *) |
| 53 |
val mk_field' : int * ('s, 'ac) su_obj' -> ('m, 'rc) obj' |
| 54 |
|
| 55 |
(* making normal signed bitfields *) |
| 56 |
val mk_rw_sbf : int * word * word -> (* offset * bits * shift *) |
| 57 |
('s, 'c) su_obj -> 'c sbf |
| 58 |
val mk_ro_sbf : int * word * word -> (* offset * bits * shift *) |
| 59 |
('s, 'c) su_obj -> ro sbf |
| 60 |
|
| 61 |
(* light versions *) |
| 62 |
val mk_rw_sbf' : int * word * word -> (* offset * bits * shift *) |
| 63 |
('s, 'c) su_obj' -> 'c sbf |
| 64 |
val mk_ro_sbf' : int * word * word -> (* offset * bits * shift *) |
| 65 |
('s, 'c) su_obj' -> ro sbf |
| 66 |
|
| 67 |
(* making normal unsigned bitfields *) |
| 68 |
val mk_rw_ubf : int * word * word -> (* offset * bits * shift *) |
| 69 |
('s, 'c) su_obj -> 'c ubf |
| 70 |
val mk_ro_ubf : int * word * word -> (* offset * bits * shift *) |
| 71 |
('s, 'c) su_obj -> ro ubf |
| 72 |
|
| 73 |
(* light versions *) |
| 74 |
val mk_rw_ubf' : int * word * word -> (* offset * bits * shift *) |
| 75 |
('s, 'c) su_obj' -> 'c ubf |
| 76 |
val mk_ro_ubf' : int * word * word -> (* offset * bits * shift *) |
| 77 |
('s, 'c) su_obj' -> ro ubf |
| 78 |
|
| 79 |
(* reveal address behind void*; this is used to |
| 80 |
* implement the function-call protocol for functions that have |
| 81 |
* pointer arguments *) |
| 82 |
val reveal : voidptr -> addr |
| 83 |
val freveal : 'f fptr' -> addr |
| 84 |
|
| 85 |
val vcast : addr -> voidptr |
| 86 |
val pcast : addr -> 'o ptr' |
| 87 |
val fcast : addr -> 'f fptr' |
| 88 |
|
| 89 |
(* unsafe low-level array subscript that does not require RTTI *) |
| 90 |
val unsafe_sub : int -> (* element size *) |
| 91 |
(('t, 'n) arr, 'c) obj' * int -> |
| 92 |
('t, 'n) obj' |
| 93 |
end |