[MLton-commit] r4125

Matthew Fluet MLton@mlton.org
Sun, 30 Oct 2005 06:38:46 -0800


Weak functions
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-10-30 03:31:46 UTC (rev 4124)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/Makefile	2005-10-30 14:38:45 UTC (rev 4125)
@@ -115,6 +115,7 @@
 	size.c								\
 	profiling.c							\
 	world.c								\
+	weak.c								\
 	init.c								\
 	done.c								\
 	assumptions.c							\

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c	2005-10-30 03:31:46 UTC (rev 4124)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/weak.c	2005-10-30 14:38:45 UTC (rev 4125)
@@ -7,34 +7,35 @@
  */
 
 
-bool GC_weakCanGet (pointer p) {
-        Bool res;
+uint32_t GC_weakCanGet (GC_state s, pointer p) {
+  uint32_t res;
 
-        res = WEAK_GONE_HEADER != GC_getHeader (p);
-        if (DEBUG_WEAK)
-                fprintf (stderr, "%s = GC_weakCanGet (0x%08x)\n",
-                                boolToString (res), (uint)p);
-        return res;
+  res = GC_WEAK_GONE_HEADER != getHeader (p);
+  if (DEBUG_WEAK)
+    fprintf (stderr, "%s = GC_weakCanGet ("FMTPTR")\n",
+             boolToString (res), (uintptr_t)p);
+  return res;
 }
 
-Pointer GC_weakGet (Pointer p) {
-        pointer res;
+pointer GC_weakGet (GC_state s, pointer p) {
+  pointer res;
 
-        res = ((GC_weak)p)->object;
-        if (DEBUG_WEAK)
-                fprintf (stderr, "0x%08x = GC_weakGet (0x%08x)\n",
-                                (uint)res, (uint)p);
-        return res;
+  res = objptrToPointer(((GC_weak)p)->objptr, s->heap.start);
+  if (DEBUG_WEAK)
+    fprintf (stderr, FMTPTR" = GC_weakGet ("FMTPTR")\n",
+             (uintptr_t)res, (uintptr_t)p);
+  return res;
 }
 
-Pointer GC_weakNew (GC_state s, Word32 header, Pointer p) {
-        pointer res;
+pointer GC_weakNew (GC_state s, GC_header header, pointer p) {
+  pointer res;
 
-        res = object (s, header, GC_NORMAL_HEADER_SIZE + 3 * WORD_SIZE, 
-                        FALSE, FALSE);
-        ((GC_weak)res)->object = p;
-        if (DEBUG_WEAK)
-                fprintf (stderr, "0x%08x = GC_weakNew (0x%08x, 0x%08x)\n",
-                                (uint)res, (uint)header, (uint)p);
-        return res;
+  res = newObject (s, header, 
+                   GC_NORMAL_HEADER_SIZE + sizeof(struct GC_weak), 
+                   FALSE);
+  ((GC_weak)res)->objptr = pointerToObjptr(p, s->heap.start);
+  if (DEBUG_WEAK)
+    fprintf (stderr, FMTPTR" = GC_weakNew ("FMTHDR", "FMTPTR")\n",
+             (uintptr_t)res, header, (uintptr_t)p);
+  return res;
 }