[svn:parrot] r41895 - in branches/pcc_reapply: include/parrot src/call src/ops

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Sat Oct 17 12:38:17 UTC 2009


Author: whiteknight
Date: Sat Oct 17 12:38:15 2009
New Revision: 41895
URL: https://trac.parrot.org/parrot/changeset/41895

Log:
[pcc] start fixing tailcalls. This resolves 1 subtest failure in t/op/calling.t and has the potential to fix others with some tweaks. Tailcalls should share information about expected returns with the parent call frame.

Modified:
   branches/pcc_reapply/include/parrot/call.h
   branches/pcc_reapply/src/call/args.c
   branches/pcc_reapply/src/ops/core.ops

Modified: branches/pcc_reapply/include/parrot/call.h
==============================================================================
--- branches/pcc_reapply/include/parrot/call.h	Sat Oct 17 03:13:10 2009	(r41894)
+++ branches/pcc_reapply/include/parrot/call.h	Sat Oct 17 12:38:15 2009	(r41895)
@@ -326,6 +326,15 @@
         __attribute__nonnull__(4)
         FUNC_MODIFIES(*call_object);
 
+void Parrot_pcc_merge_signature_for_tailcall(PARROT_INTERP,
+    ARGMOD(PMC * parent),
+    ARGMOD(PMC * tailcall))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3)
+        FUNC_MODIFIES(* parent)
+        FUNC_MODIFIES(* tailcall);
+
 #define ASSERT_ARGS_Parrot_pcc_build_sig_object_from_op \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
@@ -364,6 +373,11 @@
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(raw_sig) \
     , PARROT_ASSERT_ARG(raw_returns))
+#define ASSERT_ARGS_Parrot_pcc_merge_signature_for_tailcall \
+     __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(parent) \
+    , PARROT_ASSERT_ARG(tailcall))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: src/call/args.c */
 

Modified: branches/pcc_reapply/src/call/args.c
==============================================================================
--- branches/pcc_reapply/src/call/args.c	Sat Oct 17 03:13:10 2009	(r41894)
+++ branches/pcc_reapply/src/call/args.c	Sat Oct 17 12:38:15 2009	(r41895)
@@ -2278,10 +2278,33 @@
 
 /*
 
-Get the appropriate argument value from the continuation
+=item C<void Parrot_pcc_merge_signature_for_tailcall(PARROT_INTERP, PMC *
+parent, PMC * tailcall)>
 
-=item C<static INTVAL intval_arg_from_continuation(PARROT_INTERP, PMC *cs,
-INTVAL arg_index)>
+=cut
+
+*/
+
+void
+Parrot_pcc_merge_signature_for_tailcall(PARROT_INTERP, ARGMOD(PMC * parent), ARGMOD(PMC * tailcall))
+{
+    ASSERT_ARGS(Parrot_pcc_merge_signature_for_tailcall)
+    if (PMC_IS_NULL(parent) || PMC_IS_NULL(tailcall))
+        return;
+    else {
+        const STRING * const results_s = CONST_STRING(interp, "results");
+        const STRING * const return_flag_s = CONST_STRING(interp, "return_flags");
+        PMC * const results = VTABLE_get_attr_str(interp, parent, results_s);
+        PMC * const return_flags = VTABLE_get_attr_str(interp, parent, return_flag_s);
+        VTABLE_set_attr_str(interp, tailcall, results_s, results);
+        VTABLE_set_attr_str(interp, tailcall, return_flag_s, return_flags);
+    }
+}
+
+/*
+
+=item C<void Parrot_pcc_merge_signature_for_tailcall(PARROT_INTERP, PMC *parent,
+PMC *tailcall)>
 
 =item C<static FLOATVAL numval_arg_from_continuation(PARROT_INTERP, PMC *cs,
 INTVAL arg_index)>
@@ -2292,7 +2315,6 @@
 =item C<static PMC* pmc_arg_from_continuation(PARROT_INTERP, PMC *cs, INTVAL
 arg_index)>
 
-
 Get the appropriate argument value from the op.
 
 =item C<static INTVAL intval_arg_from_op(PARROT_INTERP, opcode_t *raw_args,

Modified: branches/pcc_reapply/src/ops/core.ops
==============================================================================
--- branches/pcc_reapply/src/ops/core.ops	Sat Oct 17 03:13:10 2009	(r41894)
+++ branches/pcc_reapply/src/ops/core.ops	Sat Oct 17 12:38:15 2009	(r41895)
@@ -457,10 +457,14 @@
 }
 
 inline op tailcall(invar PMC) :flow {
-    PMC * const p        = $1;
-    opcode_t   *dest     = expr NEXT();
-    interp->current_cont = Parrot_pcc_get_continuation(interp,
-                                CURRENT_CONTEXT(interp));
+    PMC * const p               = $1;
+    opcode_t   *dest            = expr NEXT();
+    PMC * const ctx             = CURRENT_CONTEXT(interp);
+    PMC * const parent_ctx      = Parrot_pcc_get_caller_ctx(interp, ctx);
+    PMC * const this_call_sig   = Parrot_pcc_get_signature(interp, ctx);
+    PMC * const parent_call_sig = Parrot_pcc_get_signature(interp, parent_ctx);
+    interp->current_cont        = Parrot_pcc_get_continuation(interp, ctx);
+    Parrot_pcc_merge_signature_for_tailcall(interp, parent_call_sig, this_call_sig);
 
     SUB_FLAG_TAILCALL_SET(interp->current_cont);
     dest = VTABLE_invoke(interp, p, dest);


More information about the parrot-commits mailing list