[svn:parrot] r44640 - in branches/pcc_hackathon_6Mar10/src: call ops pmc

allison at svn.parrot.org allison at svn.parrot.org
Fri Mar 5 11:54:17 UTC 2010


Author: allison
Date: Fri Mar  5 11:54:15 2010
New Revision: 44640
URL: https://trac.parrot.org/parrot/changeset/44640

Log:
[pcc] Rework set_returns and get_results to use the same code paths as
set_args and get_params (with variations for the context level, since
set_args and get_results operate from the caller's context, while
get_params and set_returns operate from the called sub's context).
This change sucessfully makes basic PASM and PIR subroutine calls with
the new opcode order.

Modified:
   branches/pcc_hackathon_6Mar10/src/call/args.c
   branches/pcc_hackathon_6Mar10/src/ops/core.ops
   branches/pcc_hackathon_6Mar10/src/pmc/callcontext.pmc

Modified: branches/pcc_hackathon_6Mar10/src/call/args.c
==============================================================================
--- branches/pcc_hackathon_6Mar10/src/call/args.c	Fri Mar  5 07:09:12 2010	(r44639)
+++ branches/pcc_hackathon_6Mar10/src/call/args.c	Fri Mar  5 11:54:15 2010	(r44640)
@@ -574,8 +574,10 @@
 
     if (PMC_IS_NULL(signature))
         call_object = Parrot_pmc_new(interp, enum_class_CallContext);
-    else
+    else {
         call_object = signature;
+        VTABLE_morph(interp, call_object, PMCNULL);
+    }
 
     /* this macro is much, much faster than the VTABLE STRING comparisons */
     SETATTR_CallContext_arg_flags(interp, call_object, raw_sig);

Modified: branches/pcc_hackathon_6Mar10/src/ops/core.ops
==============================================================================
--- branches/pcc_hackathon_6Mar10/src/ops/core.ops	Fri Mar  5 07:09:12 2010	(r44639)
+++ branches/pcc_hackathon_6Mar10/src/ops/core.ops	Fri Mar  5 11:54:15 2010	(r44640)
@@ -509,21 +509,6 @@
     goto OFFSET(argc + 2);
 }
 
-op get_results(inconst PMC) :flow {
-    opcode_t * const raw_returns = CUR_OPCODE;
-    PMC * const signature = $1;
-    PMC * call_sig;
-    INTVAL argc;
-
-    call_sig = Parrot_pcc_build_sig_object_returns_from_op(interp,
-            Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp)),
-            signature, raw_returns);
-    Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), call_sig);
-
-    argc = VTABLE_elements(interp, signature);
-    goto OFFSET(argc + 2);
-}
-
 op get_params(inconst PMC) :flow {
     opcode_t * const raw_params = CUR_OPCODE;
     PMC *caller_ctx, *ctx;
@@ -550,17 +535,34 @@
 }
 
 op set_returns(inconst PMC) :flow {
-    opcode_t * const raw_returns = CUR_OPCODE;
-    PMC      *signature          = $1;
-    PMC      *ctx                = CURRENT_CONTEXT(interp);
-    PMC      *caller_ctx         = Parrot_pcc_get_caller_ctx(interp, ctx);
-    PMC      *call_object        = Parrot_pcc_get_signature(interp, caller_ctx);
-    INTVAL    argc               = VTABLE_elements(interp, signature);
+    opcode_t * const raw_args = CUR_OPCODE;
+    PMC * const signature = $1;
+    PMC *call_sig, *old_sig;
+    INTVAL argc;
+ 
+    old_sig = CURRENT_CONTEXT(interp);
+    call_sig = Parrot_pcc_build_sig_object_from_op(interp,
+            old_sig, signature, raw_args);
 
-    Parrot_pcc_fill_returns_from_op(interp, call_object, signature, raw_returns);
+    argc = VTABLE_elements(interp, signature);
+    goto OFFSET(argc + 2);
+}
 
-    Parrot_pcc_set_signature(interp, ctx, NULL);
+op get_results(inconst PMC) :flow {
+    opcode_t * const raw_params = CUR_OPCODE;
+    PMC *caller_ctx, *ctx;
+    PMC *ccont, *call_object;
+    PMC * const signature = $1;
+    INTVAL argc;
 
+    ctx     = CURRENT_CONTEXT(interp);
+    ccont   = Parrot_pcc_get_continuation(interp, ctx);
+
+    call_object = Parrot_pcc_get_signature(interp, ctx);
+
+    Parrot_pcc_fill_params_from_op(interp, call_object, signature, raw_params);
+
+    argc = VTABLE_elements(interp, signature);
     goto OFFSET(argc + 2);
 }
 

Modified: branches/pcc_hackathon_6Mar10/src/pmc/callcontext.pmc
==============================================================================
--- branches/pcc_hackathon_6Mar10/src/pmc/callcontext.pmc	Fri Mar  5 07:09:12 2010	(r44639)
+++ branches/pcc_hackathon_6Mar10/src/pmc/callcontext.pmc	Fri Mar  5 11:54:15 2010	(r44640)
@@ -549,6 +549,59 @@
 
     }
 
+/*
+
+=item C<void morph(PMC *type)>
+
+Morph the call signature into a return signature. (Currenly ignores
+the type passed in, and resets the named and positional arguments
+stored.)
+
+=cut
+
+*/
+    VTABLE void morph(PMC *type) {
+        INTVAL  num_positionals;
+        Hash   *hash;
+
+        if (!PMC_data(SELF))
+            return;
+
+        GET_ATTR_hash(INTERP, SELF, hash);
+        GET_ATTR_num_positionals(INTERP, SELF, num_positionals);
+
+        if (num_positionals) {
+            Pcc_cell *c;
+
+            GET_ATTR_positionals(INTERP, SELF, c);
+
+            while (c) {
+                Pcc_cell *to_free = c;
+                c = NEXT_CELL(c);
+                FREE_CELL(INTERP, to_free);
+            }
+            SET_ATTR_num_positionals(INTERP, SELF, 0);
+            SET_ATTR_positionals(interp, SELF, NULL);
+        }
+
+
+        if (hash) {
+            UINTVAL i;
+
+            for (i = 0; i <= hash->mask; i++) {
+                HashBucket *b = hash->bi[i];
+
+                while (b) {
+                    FREE_CELL(INTERP, (Pcc_cell *)b->value);
+                    b = b->next;
+                }
+            }
+
+            parrot_hash_destroy(INTERP, hash);
+            SET_ATTR_hash(interp, SELF, NULL);
+        }
+    }
+
     VTABLE void destroy() {
         INTVAL    num_positionals, returns_resize_threshold;
         Hash     *hash;


More information about the parrot-commits mailing list