Author: heimdall
Date: Tue Aug  9 07:37:12 2005
New Revision: 8887

Modified:
   branches/gmc/include/parrot/smallobject.h
   branches/gmc/src/gc_gmc.c
   branches/gmc/src/headers.c
   branches/gmc/src/pmc.c
   branches/gmc/vtable.tbl
Log:
Addition of a size() method in vtable.tbl. I don't know if this is the right way
to do it...
Another function in smallobject.h for pools : get_free_typed_object.


Modified: branches/gmc/include/parrot/smallobject.h
==============================================================================
--- branches/gmc/include/parrot/smallobject.h   (original)
+++ branches/gmc/include/parrot/smallobject.h   Tue Aug  9 07:37:12 2005
@@ -39,6 +39,10 @@ struct Small_Object_Pool;
 
 typedef void (*add_free_object_fn_type)(Interp *,
                              struct Small_Object_Pool *, void *);
+#if PARROT_GC_GMC
+typedef void * (*get_free_typed_object_fn_type)(Interp *,
+                             struct Small_Object_Pool *, INTVAL);
+#endif
 typedef void * (*get_free_object_fn_type)(Interp *,
                              struct Small_Object_Pool *);
 typedef void  (*alloc_objects_fn_type)(Interp *,
@@ -230,6 +234,9 @@ struct Small_Object_Pool {
     UINTVAL align_1;    /* alignment (must be power of 2) minus one */
     /* adds a free object to the pool's free list  */
     add_free_object_fn_type     add_free_object;
+#if PARROT_GC_GMC
+    get_free_typed_object_fn_type get_free_typed_object;
+#endif
     get_free_object_fn_type     get_free_object;
     alloc_objects_fn_type       alloc_objects;
     alloc_objects_fn_type       more_objects;

Modified: branches/gmc/src/gc_gmc.c
==============================================================================
--- branches/gmc/src/gc_gmc.c   (original)
+++ branches/gmc/src/gc_gmc.c   Tue Aug  9 07:37:12 2005
@@ -4,11 +4,23 @@
 
 
 static void gc_gmc_add_free_object(Interp*, struct Small_Object_Pool*, void*);
+static void *gc_gmc_get_free_typed_object(Interp*, struct Small_Object_Pool*, 
INTVAL);
 static void *gc_gmc_get_free_object(Interp*, struct Small_Object_Pool*);
 static void gc_gmc_alloc_objects(Interp*, struct Small_Object_Pool*);
 static void gc_gmc_more_objects(Interp*, struct Small_Object_Pool*);
 
 
+/* Determines the size of a PMC according to its base_type. */
+UINTVAL
+gc_gmc_get_PMC_size(Interp *interpreter, INTVAL base_type)
+{
+    VTABLE *vtable = Parrot_base_vtables[base_type];
+    if (!vtable)
+       return (UINTVAL)0;
+    return vtable->size(interpreter, NULL);
+}
+
+
 /* Allocates and initializes a generation, but does not plug it to the pool 
yet. */
 static Gc_gmc_gen *
 gc_gmc_gen_init(Interp *interpreter)
@@ -87,6 +99,7 @@ gc_gmc_pool_init(Interp *interpreter, st
     
     pool->add_free_object = gc_gmc_add_free_object;
     pool->get_free_object = gc_gmc_get_free_object;
+    pool->get_free_typed_object = gc_gmc_get_free_typed_object;
     pool->alloc_objects   = gc_gmc_alloc_objects;
     pool->more_objects    = gc_gmc_more_objects;
 
@@ -144,6 +157,14 @@ gc_gmc_get_free_object(Interp *interpret
     return NULL;
 }
 
+
+void *
+gc_gmc_get_free_typed_object(Interp *interpreter,
+       struct Small_Object_Pool *pool, INTVAL base_type)
+{
+    return NULL;
+}
+
 void 
 gc_gmc_add_free_object(Interp *interpreter,
        struct Small_Object_Pool *pool, void *to_add)
@@ -196,5 +217,13 @@ gc_gmc_real_get_free_object(Interp *inte
   return ptr;
 }
 
+void
+gc_gmc_real_add_free_object(Interp *interpreter,
+       struct Small_Object_Pool *pool, void *to_add)
+{
+    Gc_gmc *gc = pool->gc;
+}
+
+
 
 #endif /* PARROT_GC_GMC */

Modified: branches/gmc/src/headers.c
==============================================================================
--- branches/gmc/src/headers.c  (original)
+++ branches/gmc/src/headers.c  Tue Aug  9 07:37:12 2005
@@ -238,9 +238,6 @@ Get a header.
 
 */
 
-/*#if PARROT_GC_GMC
-static pmc_body * new_pmc_body(Parrot_Interp);
-#endif*/
 
 static PMC_EXT * new_pmc_ext(Parrot_Interp);
 
@@ -291,25 +288,52 @@ new_pmc_header(Interp *interpreter, UINT
 
 /* 
 
-=item C<void *
-new_pmc_body(Interp *interpreter)>
+=item C<PMC *
+new_pmc_typed_header(Interp *interpreter, UINTVAL flags, INTVAL base_type)>
 
-Allocates a pmc_body.
-Basically same as new_pmc_ext.
+Get a header for a pmc of type base_type.
 
 =cut
 
+*/
 
-static pmc_body *
-new_pmc_body(Interp *interpreter)
+PMC *
+new_pmc_typed_header(Interp *interpreter, UINTVAL flags, INTVAL base_type)
 {
-    struct Small_Object_Pool *pool = interpreter->arena_base->pmc_body_pool;
-    void *ptr;
+    struct Small_Object_Pool *pool;
+    PMC *pmc;
 
-    ptr = pool->get_free_object (interpreter, pool);
-    memset(ptr, 0, sizeof(pmc_body));
-    return ptr;
-}*/
+    pool = flags & PObj_constant_FLAG ?
+        interpreter->arena_base->constant_pmc_pool :
+        interpreter->arena_base->pmc_pool;
+#if ARENA_DOD_FLAGS
+    assert(sizeof(Dead_PObj) <= sizeof(PMC));
+#endif
+    pmc = pool->get_free_typed_object(interpreter, pool, base_type);
+    /* clear flags, set is_PMC_FLAG */
+    if (flags & PObj_is_PMC_EXT_FLAG) {
+#if ARENA_DOD_FLAGS
+        *((Dead_PObj*)pmc)->arena_dod_flag_ptr |=
+            (PObj_is_special_PMC_FLAG << ((Dead_PObj*)pmc)->flag_shift);
+#else
+        flags |= PObj_is_special_PMC_FLAG;
+#endif
+        pmc->pmc_ext = new_pmc_ext(interpreter);
+        if (flags & PObj_is_PMC_shared_FLAG) {
+            PMC_sync(pmc) = mem_internal_allocate(sizeof(*PMC_sync(pmc)));
+            PMC_sync(pmc)->owner = interpreter;
+            MUTEX_INIT(PMC_sync(pmc)->pmc_lock);
+        }
+    }
+    else
+        pmc->pmc_ext = NULL;
+    PObj_get_FLAGS(pmc) |= PObj_is_PMC_FLAG|flags;
+    pmc->vtable = NULL;
+#if ! PMC_DATA_IN_EXT
+    PMC_data(pmc) = NULL;
+#endif
+    return pmc;
+}
 
 #endif /* PARROT_GC_GMC */
 

Modified: branches/gmc/src/pmc.c
==============================================================================
--- branches/gmc/src/pmc.c      (original)
+++ branches/gmc/src/pmc.c      Tue Aug  9 07:37:12 2005
@@ -211,7 +211,11 @@ get_new_pmc_header(Interp *interpreter, 
             flags |= PObj_is_PMC_shared_FLAG;
     }
 
+#if PARROT_GC_GMC
+    pmc = new_pmc_typed_header(interpreter, flags, base_type);
+#else
     pmc = new_pmc_header(interpreter, flags);
+#endif
     if (!pmc) {
         internal_exception(ALLOCATION_ERROR,
                 "Parrot VM: PMC allocation failed!\n");

Modified: branches/gmc/vtable.tbl
==============================================================================
--- branches/gmc/vtable.tbl     (original)
+++ branches/gmc/vtable.tbl     Tue Aug  9 07:37:12 2005
@@ -36,6 +36,8 @@ PMC* find_method(STRING* method_name)
 
 INTVAL hash(size_t seed)
 
+UINTVAL size()
+
 [FETCH]
 INTVAL get_integer()
 INTVAL get_integer_keyed(PMC* key)

Reply via email to