[svn:parrot] r36919 - in trunk: config/gen/makefiles src/pmc tools/build

cotto at svn.parrot.org cotto at svn.parrot.org
Sat Feb 21 08:35:42 UTC 2009


Author: cotto
Date: Sat Feb 21 08:35:42 2009
New Revision: 36919
URL: https://trac.parrot.org/parrot/changeset/36919

Log:
[PMC] make NCI PMCs use ATTRs, with one temporary workaround for i386 jit

Modified:
   trunk/config/gen/makefiles/root.in
   trunk/src/pmc/nci.pmc
   trunk/tools/build/nativecall.pl

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in	Sat Feb 21 05:32:25 2009	(r36918)
+++ trunk/config/gen/makefiles/root.in	Sat Feb 21 08:35:42 2009	(r36919)
@@ -1160,7 +1160,8 @@
 
 $(SRC_DIR)/gc/system$(O) : $(GENERAL_H_FILES)  $(SRC_DIR)/gc/gc_private.h
 
-$(SRC_DIR)/nci.c : $(SRC_DIR)/call_list.txt $(BUILD_TOOLS_DIR)/nativecall.pl
+$(SRC_DIR)/nci.c : $(SRC_DIR)/call_list.txt $(BUILD_TOOLS_DIR)/nativecall.pl \
+	$(SRC_DIR)/pmc/pmc_nci.h
 	$(PERL) $(BUILD_TOOLS_DIR)/nativecall.pl $(SRC_DIR)/call_list.txt
 
 $(SRC_DIR)/warnings$(O) : $(GENERAL_H_FILES)

Modified: trunk/src/pmc/nci.pmc
==============================================================================
--- trunk/src/pmc/nci.pmc	Sat Feb 21 05:32:25 2009	(r36918)
+++ trunk/src/pmc/nci.pmc	Sat Feb 21 08:35:42 2009	(r36919)
@@ -20,6 +20,9 @@
 
 #include "parrot/parrot.h"
 
+typedef INTVAL (*nci_sub_t)(PARROT_INTERP, PMC *);
+typedef INTVAL (*nci_jit_sub_t)(PARROT_INTERP, PMC *, char *);
+
 void pcc_params(PARROT_INTERP, STRING *sig, Parrot_NCI_attributes * const nci_info);
 void pcc_params(PARROT_INTERP, STRING *sig, Parrot_NCI_attributes * const nci_info) {
         char   *sig_c      = Parrot_str_to_cstring(interp, sig);
@@ -96,6 +99,7 @@
 pmclass NCI need_ext {
     ATTR STRING    *signature;              /* The signature. */
     ATTR void      *func;                   /* Function pointer to what we'll call. */
+    ATTR void      *orig_func;              /* Function pointer used to create func*/
     ATTR STRING    *pcc_params_signature;   /* The signature. */
     ATTR INTVAL     arity;                  /* Cached arity of the NCI. */
     ATTR INTVAL     jitted;                 /* Is this a jitted NCI stub. */
@@ -144,8 +148,7 @@
 */
 
     VTABLE void init() {
-        PMC_struct_val(SELF) = NULL;
-        PMC_data(SELF)       = mem_allocate_zeroed_typed(Parrot_NCI_attributes);
+        PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_NCI_attributes);
 
         /* Mark that we're not a raw NCI. */
         PObj_flag_CLEAR(private2, SELF);
@@ -164,7 +167,7 @@
 */
 
     VTABLE void set_pointer(void *ptr) {
-        PMC_struct_val(SELF) = ptr;
+        SET_ATTR_orig_func(INTERP, SELF, ptr);
         PObj_flag_SET(private2, SELF);
     }
 
@@ -174,7 +177,7 @@
         char                     * const key_c = Parrot_str_to_cstring(INTERP, key);
 
         /* Store the original function and signature. */
-        PMC_struct_val(SELF) = func;
+        SET_ATTR_orig_func(INTERP, SELF, func);
         nci_info->signature  = string_make(interp, key_c, strlen(key_c),
                                     NULL, PObj_constant_FLAG);
         Parrot_str_free_cstring(key_c);
@@ -241,10 +244,9 @@
     VTABLE PMC *clone() {
         Parrot_NCI_attributes * const nci_info_self = PARROT_NCI(SELF);
         Parrot_NCI_attributes *nci_info_ret;
+        void                  *orig_func;
 
         PMC * const ret     = pmc_new(INTERP, SELF->vtable->base_type);
-        PMC_struct_val(ret) = PMC_struct_val(SELF);
-        SET_ATTR_multi_sig(INTERP, ret, PMCNULL);
         PMC_data(ret)       = mem_allocate_zeroed_typed(Parrot_NCI_attributes);
         nci_info_ret        = PARROT_NCI(ret);
 
@@ -253,6 +255,7 @@
          * ManagedStruct or Buffer?
          */
         nci_info_ret->func                  = nci_info_self->func;
+        nci_info_ret->orig_func             = nci_info_self->orig_func;
         nci_info_ret->signature             = nci_info_self->signature;
         nci_info_ret->pcc_params_signature  = nci_info_self->pcc_params_signature;
         nci_info_ret->arity                 = nci_info_self->arity;
@@ -290,25 +293,29 @@
 */
 
     VTABLE opcode_t *invoke(void *next) {
-        Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
-
-        typedef INTVAL (*nci_sub_t)(PARROT_INTERP, PMC *);
 
-        nci_sub_t func = PObj_flag_TEST(private2, SELF)
-            ? (nci_sub_t) D2FPTR(PMC_struct_val(SELF))
+        Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
+        nci_sub_t                     func;
+        void                         *orig_func;
+        PMC                          *cont;
+
+        GET_ATTR_orig_func(INTERP, SELF, orig_func);
+        func = PObj_flag_TEST(private2, SELF)
+            ? (nci_sub_t) D2FPTR(orig_func)
             : (nci_sub_t) D2FPTR(nci_info->func);
 
-        PMC *cont;
-
         if (!func)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
                 "attempt to call NULL function");
 
         if (nci_info->jitted) {
-            typedef INTVAL (*nci_jit_sub_t)(PARROT_INTERP, PMC *, char *);
 
             nci_jit_sub_t jit_func = (nci_jit_sub_t) D2FPTR(nci_info->func);
 
+            /* XXX: Some i386 jit code depends on this.  If t/pmc/nci.t passes
+             * without it, the next line is safe to remove. */
+            PMC_struct_val(SELF) = nci_info->orig_func;
+
             /* Parrot_eprintf(interp, "JITTED %S\n", nci_info->signature); */
             jit_func(INTERP, SELF,
                 (char *) nci_info->pcc_params_signature->strstart);

Modified: trunk/tools/build/nativecall.pl
==============================================================================
--- trunk/tools/build/nativecall.pl	Sat Feb 21 05:32:25 2009	(r36918)
+++ trunk/tools/build/nativecall.pl	Sat Feb 21 08:35:42 2009	(r36919)
@@ -195,6 +195,7 @@
 #include "parrot/parrot.h"
 #include "parrot/hash.h"
 #include "parrot/oplib/ops.h"
+#include "pmc/pmc_nci.h"
 #include "nci.str"
 
 /* HEADERIZER HFILE: none */
@@ -428,13 +429,15 @@
 {
     typedef $ret_type (*func_t)($proto);
     func_t pointer;
+    void *orig_func;
     $call_state
     $return_data
     $other_decl
     Parrot_init_arg_nci(interp, &st, \"$sig\");
     $extra_preamble
 
-    pointer =  (func_t)D2FPTR(PMC_struct_val(self));
+    GETATTR_NCI_orig_func(interp, self, orig_func);
+    pointer = (func_t)D2FPTR(orig_func);
     $return_assign ($ret_type)(*pointer)($call_params);
     $final_assign
     $extra_postamble
@@ -451,12 +454,14 @@
 pcf_${return}_(PARROT_INTERP, PMC *self)
 {
     $ret_type (*pointer)(void);
+    void *orig_func;
     $return_data
     $other_decl
     $call_state
     $extra_preamble
 
-    pointer =  ($ret_type (*)(void))D2FPTR(PMC_struct_val(self));
+    GETATTR_NCI_orig_func(interp, self, orig_func);
+    pointer = ($ret_type (*)(void))D2FPTR(orig_func);
     $return_assign ($ret_type)(*pointer)();
     $final_assign
     $extra_postamble


More information about the parrot-commits mailing list