[svn:parrot] r44897 - trunk/src/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Fri Mar 12 06:30:38 UTC 2010


Author: chromatic
Date: Fri Mar 12 06:30:37 2010
New Revision: 44897
URL: https://trac.parrot.org/parrot/changeset/44897

Log:
[PMC] Tidied Sub PMC; no functional changes.

Modified:
   trunk/src/pmc/sub.pmc

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc	Fri Mar 12 06:02:26 2010	(r44896)
+++ trunk/src/pmc/sub.pmc	Fri Mar 12 06:30:37 2010	(r44897)
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2009, Parrot Foundation.
+Copyright (C) 2001-2010, Parrot Foundation.
 $Id$
 
 =head1 NAME
@@ -24,9 +24,9 @@
 static void
 print_sub_name(PARROT_INTERP, ARGIN_NULLOK(PMC *sub))
 {
-    Interp * const tracer = (interp->pdb && interp->pdb->debugger) ?
-        interp->pdb->debugger :
-        interp;
+    Interp * const tracer = (interp->pdb && interp->pdb->debugger)
+                          ? interp->pdb->debugger
+                          : interp;
 
     /* sub was located via globals */
     Parrot_io_eprintf(tracer, "# Calling sub '%Ss'\n# ",
@@ -89,7 +89,7 @@
      */
     VTABLE void init() {
         Parrot_Sub_attributes * const attrs =
-            (Parrot_Sub_attributes *) PMC_data(SELF);
+            PMC_data_typed(SELF, Parrot_Sub_attributes *);
 
         attrs->seg             = INTERP->code;
         attrs->outer_sub       = PMCNULL;
@@ -99,6 +99,7 @@
         PObj_custom_mark_destroy_SETALL(SELF);
     }
 
+
 /*
 
 =item C<void init_pmc()>
@@ -112,10 +113,9 @@
 
     VTABLE void init_pmc(PMC* init) {
         Parrot_Sub_attributes * const attrs =
-            (Parrot_Sub_attributes *) PMC_data(SELF);
-        STRING *field;
+            PMC_data_typed(SELF, Parrot_Sub_attributes *);
+        STRING *field = CONST_STRING(INTERP, "start_offs");
 
-        field = CONST_STRING(INTERP, "start_offs");
         if (VTABLE_exists_keyed_str(INTERP, init, field))
             attrs->start_offs = VTABLE_get_integer_keyed_str(INTERP, init, field);
 
@@ -199,15 +199,13 @@
             attrs->arg_info->named_slurpy = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "named_slurpy"));
         }
 
-
-        /*
-        C<eval_pmc> and C<ctx> are not handled here. And shouldn't be handled
-        here at all because of run-time nature.
-        */
+        /* C<eval_pmc> and C<ctx> are not handled here, and shouldn't be,
+         * because of run-time nature.  */
 
         PObj_custom_mark_destroy_SETALL(SELF);
     }
 
+
 /*
 
 =item C<void destroy()>
@@ -221,12 +219,11 @@
     VTABLE void destroy() {
         Parrot_Sub_attributes *sub = PARROT_SUB(SELF);
 
-        if (sub) {
-            if (sub->arg_info)
-                mem_gc_free(INTERP, sub->arg_info);
-        }
+        if (sub && sub->arg_info)
+            mem_gc_free(INTERP, sub->arg_info);
     }
 
+
 /*
 
 =item C<STRING *get_string()>
@@ -242,7 +239,6 @@
 */
 
     VTABLE STRING *get_string() {
-        STRING *name;
         Parrot_Sub_attributes *sub;
         PMC_get_sub(INTERP, SELF, sub);
 
@@ -252,12 +248,14 @@
         return NULL;
     }
 
+
     VTABLE void set_string_native(STRING *subname) {
         Parrot_Sub_attributes *sub;
         PMC_get_sub(INTERP, SELF, sub);
         sub->name = Parrot_str_copy(INTERP, subname);
     }
 
+
 /*
 
 =item C<void set_pointer(void *value)>
@@ -276,6 +274,7 @@
             "Don't set the address of a sub\nuse .const 'Sub' instead");
     }
 
+
 /*
 
 =item C<void *get_pointer()>
@@ -292,6 +291,7 @@
         return sub->seg->base.data + sub->start_offs;
     }
 
+
 /*
 
 =item C<INTVAL get_integer_keyed(PMC *key)>
@@ -312,6 +312,7 @@
         return (INTVAL) (sub->seg->base.data);
     }
 
+
 /*
 
 =item C<INTVAL defined()>
@@ -332,6 +333,7 @@
         return 1;
     }
 
+
 /*
 
 =item C<opcode_t *invoke(void *next)>
@@ -343,10 +345,14 @@
 */
 
     VTABLE opcode_t *invoke(void *next) {
+        PMC *caller_ctx = CURRENT_CONTEXT(interp);
+        PMC *ccont      = INTERP->current_cont;
+
+        /* plain subroutine call
+         * create new context, place it in interpreter */
+        PMC *context    = Parrot_pcc_get_signature(INTERP, caller_ctx);
+
         Parrot_Sub_attributes *sub;
-        PMC                   *caller_ctx;
-        PMC                   *context;
-        PMC                   *ccont;
         opcode_t              *pc;
 
         PMC_get_sub(INTERP, SELF, sub);
@@ -376,8 +382,6 @@
          *
          */
         pc                   = sub->seg->base.data + sub->start_offs;
-        caller_ctx           = CURRENT_CONTEXT(interp);
-        ccont                = INTERP->current_cont;
         INTERP->current_cont = NULL;
 
         if (ccont == NEED_CONTINUATION)
@@ -385,11 +389,9 @@
 
         PARROT_ASSERT(!PMC_IS_NULL(ccont));
 
-        /* plain subroutine call
-         * create new context, place it in interpreter */
-        context = Parrot_pcc_get_signature(INTERP, caller_ctx);
         if (PMC_IS_NULL(context))
             context = Parrot_pmc_new(INTERP, enum_class_CallContext);
+
         CURRENT_CONTEXT(INTERP) = context;
         Parrot_pcc_set_caller_ctx(INTERP, context, caller_ctx);
         Parrot_pcc_allocate_registers(INTERP, context, sub->n_regs_used);
@@ -432,17 +434,17 @@
             VTABLE_set_pointer(INTERP, Parrot_pcc_get_lex_pad(interp, context), context);
         }
 
-        if (!PMC_IS_NULL(sub->outer_ctx)) {
-            /* set outer context */
+        /* set outer context */
+        if (!PMC_IS_NULL(sub->outer_ctx))
             Parrot_pcc_set_outer_ctx(interp, context, sub->outer_ctx);
-        }
         else {
             /* autoclose */
-            PMC *c = context;
+            PMC *c       = context;
             PMC *outer_c = Parrot_pcc_get_outer_ctx(interp, c);
+
             for (c = context; PMC_IS_NULL(outer_c); c = outer_c) {
 
-                PMC         *outer_pmc;
+                PMC *outer_pmc;
                 Parrot_Sub_attributes *current_sub, *outer_sub;
 
                 PMC_get_sub(INTERP, Parrot_pcc_get_sub(interp, c), current_sub);
@@ -459,14 +461,19 @@
                     Parrot_pcc_set_sub(interp, dummy, outer_pmc);
 
                     if (!PMC_IS_NULL(outer_sub->lex_info)) {
-                        Parrot_pcc_set_lex_pad(interp, dummy, Parrot_pmc_new_init(INTERP,
-                               Parrot_get_ctx_HLL_type(interp, enum_class_LexPad),
-                               outer_sub->lex_info));
-                        VTABLE_set_pointer(INTERP, Parrot_pcc_get_lex_pad(interp, dummy), dummy);
+                        Parrot_pcc_set_lex_pad(interp, dummy,
+                            Parrot_pmc_new_init(INTERP,
+                                Parrot_get_ctx_HLL_type(interp,
+                                    enum_class_LexPad), outer_sub->lex_info));
+
+                        VTABLE_set_pointer(INTERP,
+                            Parrot_pcc_get_lex_pad(interp, dummy), dummy);
                     }
 
                     if (!PMC_IS_NULL(outer_sub->outer_ctx))
-                        Parrot_pcc_set_outer_ctx(interp, dummy, outer_sub->outer_ctx);
+                        Parrot_pcc_set_outer_ctx(interp, dummy,
+                            outer_sub->outer_ctx);
+
                     outer_sub->ctx = dummy;
                 }
 
@@ -480,8 +487,8 @@
             Parrot_switch_to_cs(INTERP, sub->seg, 1);
 
         if (PObj_get_FLAGS(ccont) & SUB_FLAG_TAILCALL) {
-            if (!(*pc == PARROT_OP_get_params_pc
-            ||    (*pc    == PARROT_OP_push_eh_ic
+            if (!(*pc    == PARROT_OP_get_params_pc
+            ||   (*pc    == PARROT_OP_push_eh_ic
             &&     pc[2] == PARROT_OP_get_params_pc))) {
 
                 /* TODO keep it or resize it */
@@ -496,6 +503,7 @@
         return pc;
     }
 
+
 /*
 
 =item C<PMC *clone()>
@@ -507,7 +515,8 @@
 */
 
     VTABLE PMC *clone() {
-        PMC        * const ret = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
+        PMC * const ret = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
+
         Parrot_Sub_attributes *dest_sub;
         Parrot_Sub_attributes *sub;
 
@@ -530,6 +539,7 @@
         return ret;
     }
 
+
 /*
 
 =item C<void assign_pmc(PMC *other)>
@@ -566,6 +576,7 @@
                 "Can't assign a non-Sub type to a Sub");
     }
 
+
 /*
 
 =item C<void mark()>
@@ -583,17 +594,18 @@
             return;
 
         Parrot_gc_mark_STRING_alive(INTERP, sub->name);
+        Parrot_gc_mark_STRING_alive(INTERP, sub->subid);
         Parrot_gc_mark_STRING_alive(INTERP, sub->method_name);
         Parrot_gc_mark_STRING_alive(INTERP, sub->ns_entry_name);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->namespace_name);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->namespace_stash);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->multi_signature);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->lex_info);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->outer_sub);
-        Parrot_gc_mark_PMC_alive(INTERP, sub->eval_pmc);
-        Parrot_gc_mark_STRING_alive(INTERP, sub->subid);
+
         Parrot_gc_mark_PMC_alive(interp, sub->ctx);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->eval_pmc);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->lex_info);
         Parrot_gc_mark_PMC_alive(interp, sub->outer_ctx);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->outer_sub);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->namespace_name);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->multi_signature);
+        Parrot_gc_mark_PMC_alive(INTERP, sub->namespace_stash);
     }
 
 /*
@@ -607,8 +619,7 @@
 */
 
     MULTI INTVAL is_equal(PMC *value) {
-        Parrot_Sub_attributes *my_sub;
-        Parrot_Sub_attributes *value_sub;
+        Parrot_Sub_attributes *my_sub, *value_sub;
 
         PMC_get_sub(INTERP, SELF, my_sub);
         PMC_get_sub(INTERP, value, value_sub);
@@ -618,6 +629,7 @@
         &&     (my_sub)->seg        == (value_sub)->seg;
     }
 
+
 /*
 
 =item C<void visit(PMC *info)>
@@ -634,9 +646,7 @@
 
     VTABLE void visit(PMC *info) {
         VISIT_PMC_ATTR(INTERP, info, SELF, Sub, namespace_name);
-
         VISIT_PMC_ATTR(INTERP, info, SELF, Sub, multi_signature);
-
         VISIT_PMC_ATTR(INTERP, info, SELF, Sub, outer_sub);
 
         /*
@@ -652,6 +662,7 @@
         SUPER(info);
     }
 
+
     VTABLE void freeze(PMC *info) {
         Parrot_Sub_attributes *sub;
         STRING                *hll_name;
@@ -705,9 +716,11 @@
 
         if (!sub->subid)
             sub->subid = CONST_STRING(INTERP, "");
+
         VTABLE_push_string(INTERP, info, sub->subid);
     }
 
+
 /*
 
 =item C<void thaw(PMC *info)>
@@ -748,6 +761,7 @@
         sub->subid        = VTABLE_shift_string(INTERP, info);
     }
 
+
 /*
 
 =item C<PMC *inspect()>
@@ -760,8 +774,8 @@
 
     VTABLE PMC *inspect()
     {
-        /* Create a hash, then use inspect_str to get all of the data to
-         * fill it up with. */
+        /* Create a hash, then use inspect_str to get all of its data */
+
         PMC    * const metadata           = Parrot_pmc_new(interp, enum_class_Hash);
         STRING * const pos_required_str   = CONST_STRING(interp, "pos_required");
         STRING * const pos_optional_str   = CONST_STRING(interp, "pos_optional");
@@ -791,6 +805,7 @@
         return metadata;
     }
 
+
 /*
 
 =item C<PMC *inspect_str(STRING *what)>
@@ -849,16 +864,14 @@
 
             /* If the first instruction is a get_params... */
             if (*pc == PARROT_OP_get_params_pc) {
-                PMC    *sig;
-                int     i, sig_length;
-
                 /* Get the signature (the next thing in the bytecode). */
-                pc++;
-                sig = PF_CONST(sub->seg, *pc)->u.key;
-                ASSERT_SIG_PMC(sig);
+                PMC    *sig        = PF_CONST(sub->seg, *(++pc))->u.key;
 
                 /* Iterate over the signature and compute argument counts. */
-                sig_length = VTABLE_elements(INTERP, sig);
+                INTVAL  sig_length = VTABLE_elements(INTERP, sig);
+                int     i;
+
+                ASSERT_SIG_PMC(sig);
 
                 for (i = 0; i < sig_length; i++) {
                     int sig_item = VTABLE_get_integer_keyed_int(INTERP, sig, i);;
@@ -886,7 +899,7 @@
             }
         }
 
-        /* Return the argument information that was requested. */
+        /* Return the requested argument information */
         if (Parrot_str_equal(interp, what, CONST_STRING(interp, "pos_required"))) {
             count_found = (INTVAL)sub->arg_info->pos_required;
         }
@@ -905,16 +918,17 @@
         else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "named_slurpy"))) {
             count_found = (INTVAL)sub->arg_info->named_slurpy;
         }
-        else {
-            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+        else
+            Parrot_ex_throw_from_c_args(interp, NULL,
+                EXCEPTION_INVALID_OPERATION,
                 "Unknown introspection value '%S'", what);
-        }
 
         retval = Parrot_pmc_new(INTERP, enum_class_Integer);
         VTABLE_set_integer_native(INTERP, retval, count_found);
         return retval;
     }
 
+
 /*
 
 =back
@@ -925,33 +939,33 @@
 
 =item C<INTVAL start_offs()>
 
-Return the start offset of the Sub.
+Returns the start offset of the Sub.
 
 =item C<INTVAL end_offs()>
 
-Return the end offset of the Sub.
+Returns the end offset of the Sub.
 
 =item C<PMC *get_namespace()>
 
-Return the namespace PMC, where the Sub is defined.
+Returns the namespace PMC, where the Sub is defined.
 
 TODO return C<namespace_stash> instead.
 
 =item C<INTVAL __get_regs_used(char *kind)>
 
-Return amount of used registers for register kinds "I", "S", "P", "N".
+Returns the number of used registers for register kinds "I", "S", "P", "N".
 
 =item C<PMC *get_lexinfo()>
 
-Return the LexInfo PMC, if any or a Null PMC.
+Returns the LexInfo PMC, if any or a Null PMC.
 
 =item C<PMC *get_multisig()>
 
-Return the MMD signature PMC, if any or a Null PMC.
+Returns the MMD signature PMC, if any, or a Null PMC.
 
 =item C<PMC *get_outer()>
 
-Gets the sub that is the outer of this one, if any or a Null PMC.
+Gets the sub that is the outer of this one, if any, or a Null PMC.
 
 =item C<void set_outer(PMC *outer)>
 
@@ -959,7 +973,7 @@
 
 =item C<INTVAL arity()>
 
-Return the arity of the Sub (the number of arguments, excluding optional and
+Returns the arity of the Sub (the number of arguments, excluding optional and
 slurpy arguments).
 
 =cut
@@ -968,11 +982,13 @@
     METHOD start_offs() {
         Parrot_Sub_attributes  *sub;
         INTVAL                  start_offs;
+
         PMC_get_sub(INTERP, SELF, sub);
         start_offs = sub->start_offs;
         RETURN(INTVAL start_offs);
     }
 
+
     METHOD end_offs() {
         Parrot_Sub_attributes  *sub;
         INTVAL                  end_offs;
@@ -981,9 +997,11 @@
         RETURN(INTVAL end_offs);
     }
 
+
     METHOD get_namespace() {
-        PMC *_namespace;
+        PMC                   *_namespace;
         Parrot_Sub_attributes *sub;
+
         PMC_get_sub(INTERP, SELF, sub);
         /*
         XXX Rakudo's failing with with this code on ASSERT. Why???
@@ -994,8 +1012,8 @@
         RETURN(PMC *_namespace);
     }
 
-    METHOD __get_regs_used(STRING *reg) {
 
+    METHOD __get_regs_used(STRING *reg) {
         /* TODO switch to canonical NiSP order
          * see also imcc/reg_alloc.c */
         STRING                *types = CONST_STRING(INTERP, "INSP");
@@ -1006,33 +1024,35 @@
         PMC_get_sub(INTERP, SELF, sub);
         PARROT_ASSERT(sub->n_regs_used);
 
-        if (!reg || Parrot_str_length(INTERP, reg) != 1) {
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
+        if (!reg || Parrot_str_length(INTERP, reg) != 1)
+            Parrot_ex_throw_from_c_args(INTERP, NULL,
+                EXCEPTION_INVALID_OPERATION,
                 "illegal register kind '%Ss'", reg);
-        }
 
         kind = Parrot_str_find_index(INTERP, types, reg, 0);
 
         if (kind == -1)
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
-                "illegal register kind '%Ss'", reg);
+            Parrot_ex_throw_from_c_args(INTERP, NULL,
+               EXCEPTION_INVALID_OPERATION, "illegal register kind '%Ss'", reg);
 
         regs_used = sub->n_regs_used[kind];
         RETURN(INTVAL regs_used);
     }
 
+
     METHOD get_lexinfo() {
-        PMC        *lexinfo;
+        PMC                   *lexinfo;
         Parrot_Sub_attributes *sub;
         PMC_get_sub(INTERP, SELF, sub);
 
-        lexinfo = sub->lex_info ? sub->lex_info: PMCNULL;
+        lexinfo = sub->lex_info ? sub->lex_info : PMCNULL;
 
         RETURN(PMC *lexinfo);
     }
 
+
     METHOD get_subid() {
-        STRING     *subid;
+        STRING                *subid;
         Parrot_Sub_attributes *sub;
         PMC_get_sub(INTERP, SELF, sub);
 
@@ -1041,6 +1061,7 @@
         RETURN(STRING *subid);
     }
 
+
     METHOD get_outer() {
         PMC                   *outersub;
         Parrot_Sub_attributes *sub;
@@ -1051,10 +1072,11 @@
         RETURN(PMC *outersub);
     }
 
+
     METHOD set_outer(PMC *outer) {
         /* Set outer sub. */
         Parrot_Sub_attributes *sub;
-        PMC *tmp1;
+        PMC                   *outer_ctx;
         PMC_get_sub(INTERP, SELF, sub);
 
         sub->outer_sub = outer;
@@ -1071,18 +1093,20 @@
 
         /* If we've got a context around for the outer sub, set it as the
          * outer context. */
-        tmp1 = CURRENT_CONTEXT(interp);
-        while (!PMC_IS_NULL(tmp1)) {
-            if (Parrot_pcc_get_sub(interp, tmp1) == outer) {
-                sub->outer_ctx = tmp1;
+        outer_ctx = CURRENT_CONTEXT(interp);
+
+        while (!PMC_IS_NULL(outer_ctx)) {
+            if (Parrot_pcc_get_sub(interp, outer_ctx) == outer) {
+                sub->outer_ctx = outer_ctx;
                 break;
             }
-            tmp1 = Parrot_pcc_get_caller_ctx(interp, tmp1);
+            outer_ctx = Parrot_pcc_get_caller_ctx(interp, outer_ctx);
         }
     }
 
+
     METHOD get_multisig() {
-        PMC                 *multisig;
+        PMC                   *multisig;
         Parrot_Sub_attributes *sub;
         PMC_get_sub(INTERP, SELF, sub);
 
@@ -1091,17 +1115,19 @@
         RETURN(PMC *multisig);
     }
 
+
     METHOD arity() {
         PMC * const pos_required   = VTABLE_inspect_str(interp, SELF, CONST_STRING(interp, "pos_required"));
         PMC * const named_required = VTABLE_inspect_str(interp, SELF, CONST_STRING(interp, "named_required"));
 
-        const INTVAL arity = VTABLE_get_integer(INTERP, pos_required) +
-            VTABLE_get_integer(INTERP, named_required);
+        const INTVAL arity = VTABLE_get_integer(INTERP, pos_required)
+                           + VTABLE_get_integer(INTERP, named_required);
 
         RETURN(INTVAL arity);
     }
 }
 
+
 /*
  * Local variables:
  *   c-file-style: "parrot"


More information about the parrot-commits mailing list