[svn:parrot] r42197 - in trunk: compilers/pirc/src include/parrot lib/Parrot/OpTrans src/call src/pmc src/runcore

bacek at svn.parrot.org bacek at svn.parrot.org
Sat Oct 31 23:51:12 UTC 2009


Author: bacek
Date: Sat Oct 31 23:51:11 2009
New Revision: 42197
URL: https://trac.parrot.org/parrot/changeset/42197

Log:
Merge branch context_auto_attrs back to trunk.

Modified:
   trunk/compilers/pirc/src/bcgen.h
   trunk/include/parrot/call.h
   trunk/include/parrot/context.h
   trunk/include/parrot/extend.h
   trunk/lib/Parrot/OpTrans/C.pm
   trunk/src/call/context.c
   trunk/src/call/context_accessors.c
   trunk/src/pmc/context.pmc
   trunk/src/pmc/multisub.pmc
   trunk/src/runcore/cores.c
   trunk/src/runcore/main.c
   trunk/src/runcore/profiling.c

Modified: trunk/compilers/pirc/src/bcgen.h
==============================================================================
--- trunk/compilers/pirc/src/bcgen.h	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/compilers/pirc/src/bcgen.h	Sat Oct 31 23:51:11 2009	(r42197)
@@ -162,6 +162,7 @@
 emit_opcode(ARGIN(bytecode * const bc), opcode_t op)
         __attribute__nonnull__(1);
 
+int emit_pbc_key(bytecode * const bc, key * const k);
 FLOATVAL get_num_const(ARGIN(bytecode * const bc), unsigned index)
         __attribute__nonnull__(1);
 
@@ -222,6 +223,7 @@
        PARROT_ASSERT_ARG(bc))
 #define ASSERT_ARGS_emit_opcode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(bc))
+#define ASSERT_ARGS_emit_pbc_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_get_num_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(bc))
 #define ASSERT_ARGS_get_pmc_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: trunk/include/parrot/call.h
==============================================================================
--- trunk/include/parrot/call.h	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/include/parrot/call.h	Sat Oct 31 23:51:11 2009	(r42197)
@@ -449,8 +449,9 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
-size_t Parrot_pcc_calculate_context_size(SHIM_INTERP,
-    ARGIN(const UINTVAL *number_regs_used))
+size_t Parrot_pcc_calculate_registers_size(PARROT_INTERP,
+    ARGIN(const INTVAL *number_regs_used))
+        __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
 PARROT_CANNOT_RETURN_NULL
@@ -516,9 +517,10 @@
 #define ASSERT_ARGS_Parrot_alloc_context __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(number_regs_used))
-#define ASSERT_ARGS_Parrot_pcc_calculate_context_size \
+#define ASSERT_ARGS_Parrot_pcc_calculate_registers_size \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(number_regs_used))
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(number_regs_used))
 #define ASSERT_ARGS_Parrot_set_new_context __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(number_regs_used))

Modified: trunk/include/parrot/context.h
==============================================================================
--- trunk/include/parrot/context.h	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/include/parrot/context.h	Sat Oct 31 23:51:11 2009	(r42197)
@@ -13,6 +13,8 @@
 #include "parrot/compiler.h"
 
 struct PackFile_Constant;
+struct Parrot_Context_attributes;
+typedef struct Parrot_Context_attributes Parrot_Context;
 
 typedef union {
     PMC         **regs_p;
@@ -24,47 +26,6 @@
     INTVAL       *regs_i;
 } Regs_ni;
 
-struct Parrot_Context {
-    PMC     *caller_ctx;      /* caller context */
-    Regs_ni  bp;              /* pointers to FLOATVAL & INTVAL */
-    Regs_ps  bp_ps;           /* pointers to PMC & STR */
-
-    /* end common header */
-    UINTVAL  n_regs_used[4];   /* INSP in PBC points to Sub */
-    PMC      *lex_pad;         /* LexPad PMC */
-    PMC      *outer_ctx;       /* outer context, if a closure */
-
-    /* new call scheme and introspective variables */
-    PMC      *current_sub;           /* the Sub we are executing */
-
-    /* for now use a return continuation PMC */
-    PMC      *handlers;              /* local handlers for the context */
-    PMC      *current_cont;          /* the return continuation PMC */
-    PMC      *current_object;        /* current object if a method call */
-    PMC      *current_namespace;     /* The namespace we're currently in */
-    PMC      *results_signature;     /* non-const results signature PMC */
-    opcode_t *current_pc;            /* program counter of Sub invocation */
-    opcode_t *current_results;       /* ptr into code with get_results opcode */
-    PMC      *current_sig;           /* temporary CallSignature PMC for active call */
-
-    /* deref the constants - we need it all the time */
-    struct PackFile_Constant **constants;
-
-    INTVAL                 current_HLL;     /* see also src/hll.c */
-
-    UINTVAL                warns;           /* Keeps track of what warnings
-                                             * have been activated */
-    UINTVAL                errors;          /* fatals that can be turned off */
-    UINTVAL                trace_flags;
-    UINTVAL                recursion_depth; /* Sub call recursion depth */
-
-    /* code->prederefed.code - code->base.data in opcodes
-     * to simplify conversion between code ptrs in e.g. invoke */
-    size_t pred_offset;
-};
-
-typedef struct Parrot_Context Parrot_Context;
-
 /*
  * Macros to make accessing registers more convenient/readable.
  */

Modified: trunk/include/parrot/extend.h
==============================================================================
--- trunk/include/parrot/extend.h	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/include/parrot/extend.h	Sat Oct 31 23:51:11 2009	(r42197)
@@ -96,7 +96,7 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
-void* Parrot_call_sub(PARROT_INTERP,
+void * Parrot_call_sub(PARROT_INTERP,
     Parrot_PMC sub_pmc,
     ARGIN(const char *signature),
     ...)

Modified: trunk/lib/Parrot/OpTrans/C.pm
==============================================================================
--- trunk/lib/Parrot/OpTrans/C.pm	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/lib/Parrot/OpTrans/C.pm	Sat Oct 31 23:51:11 2009	(r42197)
@@ -52,6 +52,8 @@
 sub defines {
     my $type = __PACKAGE__;
     return <<END;
+#include "../pmc/pmc_context.h"
+
 /* defines - $0 -> $type */
 #undef CONST
 #define REL_PC     ((size_t)(cur_opcode - (opcode_t *)interp->code->base.data))

Modified: trunk/src/call/context.c
==============================================================================
--- trunk/src/call/context.c	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/call/context.c	Sat Oct 31 23:51:11 2009	(r42197)
@@ -15,6 +15,7 @@
 #include "parrot/parrot.h"
 #include "parrot/call.h"
 #include "../pmc/pmc_sub.h"
+#include "../pmc/pmc_context.h"
 
 /*
 
@@ -65,6 +66,17 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
+static void allocate_registers(PARROT_INTERP,
+    ARGIN(PMC *pmcctx),
+    ARGIN(const INTVAL *number_regs_used))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
+
+static size_t calculate_registers_size(SHIM_INTERP,
+    ARGIN(const INTVAL *number_regs_used))
+        __attribute__nonnull__(2);
+
 static void clear_regs(PARROT_INTERP, ARGMOD(PMC *pmcctx))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
@@ -84,6 +96,12 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*pmcctx);
 
+#define ASSERT_ARGS_allocate_registers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(pmcctx) \
+    , PARROT_ASSERT_ARG(number_regs_used))
+#define ASSERT_ARGS_calculate_registers_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(number_regs_used))
 #define ASSERT_ARGS_clear_regs __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(pmcctx))
@@ -372,50 +390,59 @@
 
 /*
 
-=item C<size_t Parrot_pcc_calculate_context_size(PARROT_INTERP, const UINTVAL
+=item C<static size_t calculate_registers_size(PARROT_INTERP, const INTVAL
 *number_regs_used)>
 
-Calculate size of Context.
+Calculate memory size required for registers.
 
 =cut
 
 */
-size_t
-Parrot_pcc_calculate_context_size(SHIM_INTERP, ARGIN(const UINTVAL *number_regs_used))
+static size_t
+calculate_registers_size(SHIM_INTERP, ARGIN(const INTVAL *number_regs_used))
 {
-    ASSERT_ARGS(Parrot_pcc_calculate_context_size)
+    ASSERT_ARGS(calculate_registers_size)
 
-    return ALIGNED_CTX_SIZE + ROUND_ALLOC_SIZE(
+    return ROUND_ALLOC_SIZE(
             sizeof (INTVAL)   * number_regs_used[REGNO_INT] +
             sizeof (FLOATVAL) * number_regs_used[REGNO_NUM] +
             sizeof (STRING *) * number_regs_used[REGNO_STR] +
             sizeof (PMC *)    * number_regs_used[REGNO_PMC]);
 }
 
+
 /*
 
-=item C<PMC * Parrot_alloc_context(PARROT_INTERP, const INTVAL
-*number_regs_used, PMC *old)>
+=item C<size_t Parrot_pcc_calculate_registers_size(PARROT_INTERP, const INTVAL
+*number_regs_used)>
 
-Allocates and returns a new context.  Does not set this new context as the
-current context. Note that the register usage C<n_regs_used> is copied.  Use
-the init flag to indicate whether you want to initialize the new context
-(setting its default values and clearing its registers).
+Calculate size of Context.
 
 =cut
 
 */
+size_t
+Parrot_pcc_calculate_registers_size(PARROT_INTERP, ARGIN(const INTVAL *number_regs_used))
+{
+    ASSERT_ARGS(Parrot_pcc_calculate_registers_size)
+    return calculate_registers_size(interp, number_regs_used);
+}
 
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-PMC *
-Parrot_alloc_context(PARROT_INTERP, ARGIN(const INTVAL *number_regs_used),
-    ARGIN_NULLOK(PMC *old))
+/*
+
+=item C<static void allocate_registers(PARROT_INTERP, PMC *pmcctx, const INTVAL
+*number_regs_used)>
+
+Allocate registers inside Context.
+
+=cut
+
+*/
+static void
+allocate_registers(PARROT_INTERP, ARGIN(PMC *pmcctx), ARGIN(const INTVAL *number_regs_used))
 {
-    ASSERT_ARGS(Parrot_alloc_context)
-    PMC            *pmcctx;
-    Parrot_Context *ctx;
-    void *p;
+    ASSERT_ARGS(allocate_registers)
+    Parrot_Context_attributes *ctx = PARROT_CONTEXT(pmcctx);
 
     const size_t size_i = sizeof (INTVAL)   * number_regs_used[REGNO_INT];
     const size_t size_n = sizeof (FLOATVAL) * number_regs_used[REGNO_NUM];
@@ -426,27 +453,45 @@
     const size_t all_regs_size = size_n + size_i + size_p + size_s;
     const size_t reg_alloc     = ROUND_ALLOC_SIZE(all_regs_size);
 
-    const size_t to_alloc = reg_alloc + ALIGNED_CTX_SIZE;
-
-    ctx  = (Parrot_Context *)Parrot_gc_allocate_fixed_size_storage(interp, to_alloc);
+    ctx->registers = (Parrot_Context *)Parrot_gc_allocate_fixed_size_storage(interp, reg_alloc);
 
     ctx->n_regs_used[REGNO_INT] = number_regs_used[REGNO_INT];
     ctx->n_regs_used[REGNO_NUM] = number_regs_used[REGNO_NUM];
     ctx->n_regs_used[REGNO_STR] = number_regs_used[REGNO_STR];
     ctx->n_regs_used[REGNO_PMC] = number_regs_used[REGNO_PMC];
 
-    /* regs start past the context */
-    p   = (void *) ((char *)ctx + ALIGNED_CTX_SIZE);
-
     /* ctx.bp points to I0, which has Nx on the left */
-    ctx->bp.regs_i = (INTVAL *)((char *)p + size_n);
+    ctx->bp.regs_i = (INTVAL *)((char *)ctx->registers + size_n);
 
     /* ctx.bp_ps points to S0, which has Px on the left */
-    ctx->bp_ps.regs_s = (STRING **)((char *)p + size_nip);
+    ctx->bp_ps.regs_s = (STRING **)((char *)ctx->registers + size_nip);
+
+}
+
+/*
+
+=item C<PMC * Parrot_alloc_context(PARROT_INTERP, const INTVAL
+*number_regs_used, PMC *old)>
+
+Allocates and returns a new context.  Does not set this new context as the
+current context. Note that the register usage C<n_regs_used> is copied.  Use
+the init flag to indicate whether you want to initialize the new context
+(setting its default values and clearing its registers).
+
+=cut
+
+*/
 
-    pmcctx = pmc_new(interp, enum_class_Context);
-    VTABLE_set_pointer(interp, pmcctx, ctx);
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PMC *
+Parrot_alloc_context(PARROT_INTERP, ARGIN(const INTVAL *number_regs_used),
+    ARGIN_NULLOK(PMC *old))
+{
+    ASSERT_ARGS(Parrot_alloc_context)
+    PMC            *pmcctx = pmc_new(interp, enum_class_Context);
 
+    allocate_registers(interp, pmcctx, number_regs_used);
     init_context(interp, pmcctx, old);
 
     return pmcctx;

Modified: trunk/src/call/context_accessors.c
==============================================================================
--- trunk/src/call/context_accessors.c	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/call/context_accessors.c	Sat Oct 31 23:51:11 2009	(r42197)
@@ -14,6 +14,7 @@
 
 #include "parrot/parrot.h"
 #include "parrot/call.h"
+#include "../pmc/pmc_context.h"
 
 #ifndef NDEBUG
 

Modified: trunk/src/pmc/context.pmc
==============================================================================
--- trunk/src/pmc/context.pmc	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/pmc/context.pmc	Sat Oct 31 23:51:11 2009	(r42197)
@@ -8,7 +8,7 @@
 
 =head1 DESCRIPTION
 
-Stores context of execution. Currently we store pointer to Parrot_Context
+Stores context of execution. Currently we store pointer to Parrot_Context_attributes
 structure in PMC_data.
 
 =head2 Vtable Functions
@@ -23,7 +23,45 @@
 #include "parrot/packfile.h"
 #include "pmc_sub.h"
 
-pmclass Context {
+pmclass Context auto_attrs {
+    ATTR PMC     *caller_ctx;      /* caller context */
+
+    ATTR void    *registers;       /* pointer to allocated registers */
+    ATTR Regs_ni  bp;              /* pointers to FLOATVAL & INTVAL */
+    ATTR Regs_ps  bp_ps;           /* pointers to PMC & STR */
+
+    /* end common header */
+    ATTR UINTVAL  n_regs_used[4];   /* INSP in PBC points to Sub */
+    ATTR PMC      *lex_pad;         /* LexPad PMC */
+    ATTR PMC      *outer_ctx;       /* outer context, if a closure */
+
+    /* new call scheme and introspective variables */
+    ATTR PMC      *current_sub;           /* the Sub we are executing */
+
+    /* for now use a return continuation PMC */
+    ATTR PMC      *handlers;              /* local handlers for the context */
+    ATTR PMC      *current_cont;          /* the return continuation PMC */
+    ATTR PMC      *current_object;        /* current object if a method call */
+    ATTR PMC      *current_namespace;     /* The namespace we're currently in */
+    ATTR PMC      *results_signature;     /* non-const results signature PMC */
+    ATTR opcode_t *current_pc;            /* program counter of Sub invocation */
+    ATTR opcode_t *current_results;       /* ptr into code with get_results opcode */
+    ATTR PMC      *current_sig;           /* temporary CallSignature PMC for active call */
+
+    /* deref the constants - we need it all the time */
+    ATTR struct PackFile_Constant **constants;
+
+    ATTR INTVAL                 current_HLL;     /* see also src/hll.c */
+
+    ATTR UINTVAL                warns;           /* Keeps track of what warnings
+                                             * have been activated */
+    ATTR UINTVAL                errors;          /* fatals that can be turned off */
+    ATTR UINTVAL                trace_flags;
+    ATTR UINTVAL                recursion_depth; /* Sub call recursion depth */
+
+    /* code->prederefed.code - code->base.data in opcodes
+     * to simplify conversion between code ptrs in e.g. invoke */
+    ATTR size_t pred_offset;
 
 /*
 
@@ -36,7 +74,6 @@
 */
 
     VTABLE void init() {
-        PMC_data(SELF) = NULL;
         PObj_custom_mark_destroy_SETALL(SELF);
     }
 
@@ -53,7 +90,7 @@
 
     VTABLE void mark()
     {
-        Parrot_Context * const ctx = PMC_data_typed(SELF, Parrot_Context*);
+        Parrot_Context_attributes * const ctx = PARROT_CONTEXT(SELF);
         UINTVAL i;
 
         /* If Context wasn't initialised just return */
@@ -100,47 +137,26 @@
 
     VTABLE void destroy() {
         /* We own this pointer */
-        Parrot_Context * const ctx = PMC_data_typed(SELF, Parrot_Context*);
+        Parrot_Context_attributes * const ctx = PARROT_CONTEXT(SELF);
+        size_t reg_size;
 
         if (!ctx)
             return;
 
+        reg_size = Parrot_pcc_calculate_registers_size(INTERP, ctx->n_regs_used);
+        if (!reg_size)
+            return;
+
+        /* Free registers */
         Parrot_gc_free_fixed_size_storage(interp,
-                Parrot_pcc_calculate_context_size(INTERP, ctx->n_regs_used),
-                ctx);
+                Parrot_pcc_calculate_registers_size(INTERP, ctx->n_regs_used),
+                ctx->registers);
 
         PMC_data(SELF) = NULL;
     }
 
 /*
 
-=item C<void *get_pointer()>
-
-Return pointer to underlying Parrot_Context structure.
-
-=cut
-
-*/
-
-    VTABLE void *get_pointer() {
-        return PMC_data(SELF);
-    }
-
-/*
-
-=item C<void set_pointer(void *)>
-
-Set new Parrot_Context structure.
-
-=cut
-
-*/
-    VTABLE void set_pointer(void *context) {
-        PMC_data(SELF) = context;
-    }
-
-/*
-
 =item C<PMC *get_pmc_keyed_str(STRING *key)>
 
 Introspection interface. C<key> can be:
@@ -157,7 +173,7 @@
 
 */
     VTABLE PMC *get_pmc_keyed_str(STRING *key) {
-        Parrot_Context *ctx = PMC_data_typed(SELF, Parrot_Context*);
+        Parrot_Context_attributes *ctx = PARROT_CONTEXT(SELF);
 
         if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "caller_ctx")))
             return ctx->caller_ctx;

Modified: trunk/src/pmc/multisub.pmc
==============================================================================
--- trunk/src/pmc/multisub.pmc	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/pmc/multisub.pmc	Sat Oct 31 23:51:11 2009	(r42197)
@@ -19,6 +19,8 @@
 
 */
 
+#include "pmc_context.h"
+
 pmclass MultiSub extends ResizablePMCArray auto_attrs provides array {
 
     VTABLE void push_pmc(PMC *value) {

Modified: trunk/src/runcore/cores.c
==============================================================================
--- trunk/src/runcore/cores.c	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/runcore/cores.c	Sat Oct 31 23:51:11 2009	(r42197)
@@ -249,6 +249,7 @@
 #include "parrot/dynext.h"
 
 #include "../pmc/pmc_sub.h"
+#include "../pmc/pmc_context.h"
 
 #ifdef HAVE_COMPUTED_GOTO
 #  include "parrot/oplib/core_ops_cg.h"

Modified: trunk/src/runcore/main.c
==============================================================================
--- trunk/src/runcore/main.c	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/runcore/main.c	Sat Oct 31 23:51:11 2009	(r42197)
@@ -46,6 +46,7 @@
 #endif
 #include "parrot/dynext.h"
 #include "../pmc/pmc_parrotlibrary.h"
+#include "../pmc/pmc_context.h"
 
 
 /* HEADERIZER HFILE: include/parrot/runcore_api.h */

Modified: trunk/src/runcore/profiling.c
==============================================================================
--- trunk/src/runcore/profiling.c	Sat Oct 31 23:25:39 2009	(r42196)
+++ trunk/src/runcore/profiling.c	Sat Oct 31 23:51:11 2009	(r42197)
@@ -18,6 +18,7 @@
 #include "profiling.str"
 
 #include "../pmc/pmc_sub.h"
+#include "../pmc/pmc_context.h"
 
 #ifdef WIN32
 #  define getpid _getpid


More information about the parrot-commits mailing list