1 /* Copyright (C) 2005-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
8 /* isObjptr returns true if p looks like an object pointer. */
9 bool isObjptr (objptr p
) {
10 unsigned int shift
= GC_MODEL_MINALIGN_SHIFT
- GC_MODEL_OBJPTR_SHIFT
;
11 objptr mask
= ~((~((objptr
)0)) << shift
);
12 return (0 == (p
& mask
));
15 pointer
objptrToPointer (objptr O
, pointer B
) {
16 uintptr_t O_
= (uintptr_t)O
;
18 unsigned int S_
= GC_MODEL_OBJPTR_SHIFT
;
22 if (GC_MODEL_OBJPTR_BASE
) {
28 P_
= ((O_
<< S_
) + B_
);
31 fprintf (stderr
, "objptrToPointer ("FMTOBJPTR
") = "FMTPTR
"\n", O
, (uintptr_t)P
);
36 objptr
pointerToObjptr (pointer P
, pointer B
) {
37 uintptr_t P_
= (uintptr_t)P
;
39 unsigned int S_
= GC_MODEL_OBJPTR_SHIFT
;
43 if (GC_MODEL_OBJPTR_BASE
) {
49 O_
= ((P_
- B_
) >> S_
);
52 fprintf (stderr
, "pointerToObjptr ("FMTPTR
") = "FMTOBJPTR
"\n", (uintptr_t)P
, O
);
58 * Note that by indirectly fetching and storing object pointers, the
59 * following functions admit implementations that behave according to
60 * model characteristics determined at runtime. Hence, by making
61 * exclusive use of these functions (and adding a GC_state->model
62 * field set by the compiled program), we may be able to implement the
63 * runtime in a manner which is agnostic to the actual objptr
66 pointer
fetchObjptrToPointer (pointer OP
, pointer B
) {
67 return objptrToPointer (*((objptr
*)OP
), B
);
69 void storeObjptrFromPointer (pointer OP
, pointer P
, pointer B
) {
70 *((objptr
*)OP
) = pointerToObjptr (P
, B
);