perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r25926 - in branches/pdd17pmc/src: . pmc

Subject: [svn:parrot] r25926 - in branches/pdd17pmc/src: . pmc
From:
Date: Wed, 20 Feb 2008 22:37:28 -0800 PST
Newsgroups: perl.cvs.parrot

Author: chromatic
Date: Wed Feb 20 22:37:27 2008
New Revision: 25926

Modified:
   branches/pdd17pmc/src/inter_misc.c
   branches/pdd17pmc/src/pmc/nci.pmc

Log:
[PMC] Migrated NCI PMC to PDD 17 for attributes.

Using the type PMC * instead of void * for the function pointer is a nasty
hack, but PDD 17 doesn't (yet) support void * as an attribute.

For now this only requires some dodgy type casting, but if and when the PMC
parser handles mark() and destroy() automatically, treating a function pointer
as a PMC is only asking for trouble.


Modified: branches/pdd17pmc/src/inter_misc.c
==============================================================================
--- branches/pdd17pmc/src/inter_misc.c  (original)
+++ branches/pdd17pmc/src/inter_misc.c  Wed Feb 20 22:37:27 2008
@@ -23,8 +23,6 @@
 #include "inter_misc.str"
 #include "../compilers/imcc/imc.h"
 
-void Parrot_NCI_make_raw_nci_actual(PARROT_INTERP, PMC *, void *);
-
 /* HEADERIZER HFILE: include/parrot/interpreter.h */
 
 /*
@@ -78,7 +76,7 @@
         NULL, PObj_constant_FLAG|PObj_external_FLAG);
 
     /* setup call func */
-    Parrot_NCI_make_raw_nci_actual(interp, method, func);
+    VTABLE_set_pointer(interp, method, func);
 
     /* insert it into namespace */
     VTABLE_set_pmc_keyed_str(interp, interp->vtables[type]->_namespace,

Modified: branches/pdd17pmc/src/pmc/nci.pmc
==============================================================================
--- branches/pdd17pmc/src/pmc/nci.pmc   (original)
+++ branches/pdd17pmc/src/pmc/nci.pmc   Wed Feb 20 22:37:27 2008
@@ -20,22 +20,10 @@
 
 #include "parrot/parrot.h"
 
-/* NCI PMC's underlying struct. */
-typedef struct Parrot_NCI {
-    STRING *signature;    /* The signature. */
-    int arity;            /* Cached arity of the NCI. */
-    funcptr_t *func;      /* Function pointer to what we'll call. */
-} Parrot_NCI;
-
-/* Macro to access underlying structure of an NCI PMC. */
-#define PARROT_NCI(o) ((Parrot_NCI *) PMC_data(o))
-
-void Parrot_NCI_make_raw_nci_actual(PARROT_INTERP, PMC *SELF, void *func) {
-    PMC_struct_val(SELF) = (void *)func;
-    PObj_flag_SET(private2, SELF);
-}
-
 pmclass NCI need_ext {
+    ATTR STRING    *signature;    /* The signature. */
+    ATTR PMC       *func;         /* Function pointer to what we'll call. */
+    ATTR INTVAL     arity;        /* Cached arity of the NCI. */
 
 /*
 
@@ -63,7 +51,7 @@
 */
 
     METHOD make_raw_nci(PMC *func) {
-        Parrot_NCI_make_raw_nci_actual(interp, SELF, (void *)func);
+        VTABLE_set_pointer(interp, SELF, (void *)func);
     }
 
 /*
@@ -96,6 +84,11 @@
 
 */
 
+    VTABLE void set_pointer(void *ptr) {
+        PMC_struct_val(SELF) = (void *)ptr;
+        PObj_flag_SET(private2, SELF);
+    }
+
     VTABLE void set_pointer_keyed_str(STRING *key, void *func) {
         Parrot_NCI * const nci_info = PARROT_NCI(SELF);
 
@@ -107,8 +100,7 @@
         nci_info->arity      = string_length(INTERP, key) - 1;
 
         /* Build call function. */
-        nci_info->func       =
-            (void (**)(void))(build_call_func(INTERP, SELF, key));
+        nci_info->func       = (PMC *)(build_call_func(INTERP, SELF, key));
     }
 
 /*
@@ -152,16 +144,16 @@
         PMC_struct_val(ret) = PMC_struct_val(SELF);
         PMC_pmc_val(ret)    = PMCNULL;
         PMC_data(ret)       = mem_allocate_zeroed_typed(Parrot_NCI);
-        nci_info_ret = PARROT_NCI(ret);
+        nci_info_ret        = PARROT_NCI(ret);
 
         /* FIXME if data is malloced (JIT/i386!) then we need
          * the length of data here, to memcpy it
          * ManagedStruct or Buffer?
          */
-        nci_info_ret->func = nci_info_self->func;
+        nci_info_ret->func      = nci_info_self->func;
         nci_info_ret->signature = nci_info_self->signature;
-        nci_info_ret->arity = nci_info_self->arity;
-        PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x7);
+        nci_info_ret->arity     = nci_info_self->arity;
+        PObj_get_FLAGS(ret)    |= (PObj_get_FLAGS(SELF) & 0x7);
 
         return ret;
     }

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r25926 - in branches/pdd17pmc/src: . pmc, chromatic <=