[svn:parrot] r42196 - in branches/context_auto_attrs: compilers/pirc/src include/parrot src/call src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sat Oct 31 23:25:39 UTC 2009
Author: bacek
Date: Sat Oct 31 23:25:39 2009
New Revision: 42196
URL: https://trac.parrot.org/parrot/changeset/42196
Log:
Split allocating Context from registers
Modified:
branches/context_auto_attrs/compilers/pirc/src/bcgen.h
branches/context_auto_attrs/include/parrot/call.h
branches/context_auto_attrs/include/parrot/extend.h
branches/context_auto_attrs/src/call/context.c
branches/context_auto_attrs/src/pmc/context.pmc
Modified: branches/context_auto_attrs/compilers/pirc/src/bcgen.h
==============================================================================
--- branches/context_auto_attrs/compilers/pirc/src/bcgen.h Sat Oct 31 23:25:07 2009 (r42195)
+++ branches/context_auto_attrs/compilers/pirc/src/bcgen.h Sat Oct 31 23:25:39 2009 (r42196)
@@ -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: branches/context_auto_attrs/include/parrot/call.h
==============================================================================
--- branches/context_auto_attrs/include/parrot/call.h Sat Oct 31 23:25:07 2009 (r42195)
+++ branches/context_auto_attrs/include/parrot/call.h Sat Oct 31 23:25:39 2009 (r42196)
@@ -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: branches/context_auto_attrs/include/parrot/extend.h
==============================================================================
--- branches/context_auto_attrs/include/parrot/extend.h Sat Oct 31 23:25:07 2009 (r42195)
+++ branches/context_auto_attrs/include/parrot/extend.h Sat Oct 31 23:25:39 2009 (r42196)
@@ -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: branches/context_auto_attrs/src/call/context.c
==============================================================================
--- branches/context_auto_attrs/src/call/context.c Sat Oct 31 23:25:07 2009 (r42195)
+++ branches/context_auto_attrs/src/call/context.c Sat Oct 31 23:25:39 2009 (r42196)
@@ -66,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)
@@ -85,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))
@@ -373,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];
@@ -427,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: branches/context_auto_attrs/src/pmc/context.pmc
==============================================================================
--- branches/context_auto_attrs/src/pmc/context.pmc Sat Oct 31 23:25:07 2009 (r42195)
+++ branches/context_auto_attrs/src/pmc/context.pmc Sat Oct 31 23:25:39 2009 (r42196)
@@ -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
@@ -74,7 +74,6 @@
*/
VTABLE void init() {
- PMC_data(SELF) = NULL;
PObj_custom_mark_destroy_SETALL(SELF);
}
@@ -91,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 */
@@ -138,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:
@@ -195,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;
More information about the parrot-commits
mailing list