[svn:parrot] r44531 - in branches/tt1477: include/parrot src/call

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sat Feb 27 02:49:38 UTC 2010


Author: plobsing
Date: Sat Feb 27 02:49:37 2010
New Revision: 44531
URL: https://trac.parrot.org/parrot/changeset/44531

Log:
create function Parrot_pcc_build_sig_object_from_callbacks which is a generalization of Parrot_pcc_build_sig_object_from_varargs

Modified:
   branches/tt1477/include/parrot/call.h
   branches/tt1477/src/call/args.c

Modified: branches/tt1477/include/parrot/call.h
==============================================================================
--- branches/tt1477/include/parrot/call.h	Sat Feb 27 02:38:18 2010	(r44530)
+++ branches/tt1477/include/parrot/call.h	Sat Feb 27 02:49:37 2010	(r44531)
@@ -49,6 +49,19 @@
 #define CALLSIGNATURE_is_exception_SET(o)   CALLSIGNATURE_flag_SET(is_exception, (o))
 #define CALLSIGNATURE_is_exception_CLEAR(o) CALLSIGNATURE_flag_CLEAR(is_exception, (o))
 
+typedef struct Parrot_pcc_sig_object_callback_funcs {
+    INTVAL (*intval_arg)(PARROT_INTERP, void *call_info, int idx);
+    FLOATVAL (*numval_arg)(PARROT_INTERP, void *call_info, int idx);
+    STRING *(*string_arg)(PARROT_INTERP, void *call_info, int idx);
+    PMC *(*pmc_arg)(PARROT_INTERP, void *call_info, int idx);
+
+    INTVAL *(*intval_ret)(PARROT_INTERP, void *call_info, int idx);
+    FLOATVAL *(*numval_ret)(PARROT_INTERP, void *call_info, int idx);
+    STRING *(*string_ret)(PARROT_INTERP, void *call_info, int idx);
+    PMC *(*pmc_ret)(PARROT_INTERP, void *call_info, int idx);
+} Parrot_pcc_sig_object_callback_funcs;
+
+
 /* HEADERIZER BEGIN: src/call/pcc.c */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
@@ -169,6 +182,17 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
+PMC* Parrot_pcc_build_sig_object_from_callbacks(PARROT_INTERP,
+    ARGIN_NULLOK(PMC *obj),
+    ARGIN(const char *sig),
+    Parrot_pcc_sig_object_callback_funcs *cbs,
+    void *call_info)
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(3);
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
 PMC* Parrot_pcc_build_sig_object_from_op(PARROT_INTERP,
     ARGIN_NULLOK(PMC *signature),
     ARGIN(PMC * const raw_sig),
@@ -271,6 +295,10 @@
     , PARROT_ASSERT_ARG(sig_object) \
     , PARROT_ASSERT_ARG(type) \
     , PARROT_ASSERT_ARG(result))
+#define ASSERT_ARGS_Parrot_pcc_build_sig_object_from_callbacks \
+     __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(sig))
 #define ASSERT_ARGS_Parrot_pcc_build_sig_object_from_op \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \

Modified: branches/tt1477/src/call/args.c
==============================================================================
--- branches/tt1477/src/call/args.c	Sat Feb 27 02:38:18 2010	(r44530)
+++ branches/tt1477/src/call/args.c	Sat Feb 27 02:49:37 2010	(r44531)
@@ -862,12 +862,13 @@
 
 /*
 
-=item C<PMC* Parrot_pcc_build_sig_object_from_varargs(PARROT_INTERP, PMC *obj,
-const char *sig, va_list args)>
+=item C<PMC* Parrot_pcc_build_sig_object_from_callbacks(PARROT_INTERP, PMC *obj,
+const char *sig, Parrot_pcc_sig_object_callback_funcs *cbs, void *call_info)>
 
-Converts a varargs list into a CallContext PMC. The CallContext stores the
-original short signature string and an array of integer types to pass on to the
-multiple dispatch search.
+Build a CallContext PMC from a signature and a set of callbacks.
+
+The CallContext stores the original short signature string and an array of
+integer types to pass on to the multiple dispatch search.
 
 =cut
 
@@ -877,10 +878,10 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 PMC*
-Parrot_pcc_build_sig_object_from_varargs(PARROT_INTERP, ARGIN_NULLOK(PMC *obj),
-        ARGIN(const char *sig), va_list args)
+Parrot_pcc_build_sig_object_from_callbacks(PARROT_INTERP, ARGIN_NULLOK(PMC *obj),
+        ARGIN(const char *sig), Parrot_pcc_sig_object_callback_funcs *cbs, void *call_info)
 {
-    ASSERT_ARGS(Parrot_pcc_build_sig_object_from_varargs)
+    ASSERT_ARGS(Parrot_pcc_build_sig_object_from_callbacks)
     PMC         *type_tuple         = PMCNULL;
     PMC         *arg_flags     = PMCNULL;
     PMC         *return_flags  = PMCNULL;
@@ -908,19 +909,19 @@
             switch (type) {
               case 'I':
                 csr_push_pointer(interp, call_object,
-                            (void *)va_arg(args, INTVAL *), PARROT_ARG_INTVAL);
+                            (void *)cbs->intval_ret(interp, call_info, i), PARROT_ARG_INTVAL);
                 break;
               case 'N':
                 csr_push_pointer(interp, call_object,
-                            (void *)va_arg(args, FLOATVAL *), PARROT_ARG_FLOATVAL);
+                            (void *)cbs->numval_ret(interp, call_info, i), PARROT_ARG_FLOATVAL);
                 break;
               case 'S':
                 csr_push_pointer(interp, call_object,
-                            (void *)va_arg(args, STRING **), PARROT_ARG_STRING);
+                            (void *)cbs->string_ret(interp, call_info, i), PARROT_ARG_STRING);
                 break;
               case 'P':
                 csr_push_pointer(interp, call_object,
-                            (void *)va_arg(args, PMC **), PARROT_ARG_PMC);
+                            (void *)cbs->pmc_ret(interp, call_info, i), PARROT_ARG_PMC);
                 break;
               default:
                 Parrot_ex_throw_from_c_args(interp, NULL,
@@ -932,18 +933,18 @@
             /* Regular arguments just set the value */
             switch (type) {
               case 'I':
-                VTABLE_push_integer(interp, call_object, va_arg(args, INTVAL));
+                VTABLE_push_integer(interp, call_object, cbs->intval_arg(interp, call_info, i));
                 break;
               case 'N':
-                VTABLE_push_float(interp, call_object, va_arg(args, FLOATVAL));
+                VTABLE_push_float(interp, call_object, cbs->numval_arg(interp, call_info, i));
                 break;
               case 'S':
-                VTABLE_push_string(interp, call_object, va_arg(args, STRING *));
+                VTABLE_push_string(interp, call_object, cbs->string_arg(interp, call_info, i));
                 break;
               case 'P':
                 {
                     const INTVAL type_lookahead = sig[i+1];
-                    PMC * const pmc_arg = va_arg(args, PMC *);
+                    PMC * const pmc_arg = cbs->pmc_arg(interp, call_info, i);
                     if (type_lookahead == 'f') {
                          dissect_aggregate_arg(interp, call_object, pmc_arg);
                         i++; /* skip 'f' */
@@ -983,6 +984,43 @@
 
 /*
 
+=item C<PMC* Parrot_pcc_build_sig_object_from_varargs(PARROT_INTERP, PMC *obj,
+const char *sig, va_list args)>
+
+Converts a varargs list into a CallContext PMC. The CallContext stores the
+original short signature string and an array of integer types to pass on to the
+multiple dispatch search.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+PMC*
+Parrot_pcc_build_sig_object_from_varargs(PARROT_INTERP, ARGIN_NULLOK(PMC *obj),
+        ARGIN(const char *sig), va_list args)
+{
+    ASSERT_ARGS(Parrot_pcc_build_sig_object_from_varargs)
+
+    static Parrot_pcc_sig_object_callback_funcs function_pointers = {
+        (intval_func_t)intval_arg_from_c_args,
+        (numval_func_t)numval_arg_from_c_args,
+        (string_func_t)string_arg_from_c_args,
+        (pmc_func_t)pmc_arg_from_c_args,
+
+        (intval_ptr_func_t)intval_param_from_c_args,
+        (numval_ptr_func_t)numval_param_from_c_args,
+        (string_ptr_func_t)string_param_from_c_args,
+        (pmc_ptr_func_t)pmc_param_from_c_args,
+    };
+
+    return Parrot_pcc_build_sig_object_from_callbacks(interp, obj, sig, &function_pointers, args);
+}
+
+/*
+
 =item C<static void fill_params(PARROT_INTERP, PMC *call_object, PMC *raw_sig,
 void *arg_info, struct pcc_set_funcs *accessor)>
 


More information about the parrot-commits mailing list