[svn:parrot] r40801 - in branches/context_pmc3: include/parrot lib/Parrot/OpTrans src src/pmc src/runcore
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Aug 25 23:29:25 UTC 2009
Author: bacek
Date: Tue Aug 25 23:29:24 2009
New Revision: 40801
URL: https://trac.parrot.org/parrot/changeset/40801
Log:
[core] Add current_pc accessor to Context and use it
Modified:
branches/context_pmc3/include/parrot/context.h
branches/context_pmc3/lib/Parrot/OpTrans/CGP.pm
branches/context_pmc3/src/context.c
branches/context_pmc3/src/debug.c
branches/context_pmc3/src/pmc/exception.pmc
branches/context_pmc3/src/pmc/parrotinterpreter.pmc
branches/context_pmc3/src/pmc/sub.pmc
branches/context_pmc3/src/runcore/cores.c
branches/context_pmc3/src/sub.c
Modified: branches/context_pmc3/include/parrot/context.h
==============================================================================
--- branches/context_pmc3/include/parrot/context.h Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/include/parrot/context.h Tue Aug 25 23:29:24 2009 (r40801)
@@ -117,6 +117,11 @@
__attribute__nonnull__(2);
PARROT_EXPORT
+opcode_t* Parrot_cx_get_pc(PARROT_INTERP, ARGIN(PMC *ctx))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PMC* Parrot_cx_get_pmc_constant(PARROT_INTERP, ARGIN(PMC *ctx), INTVAL idx)
__attribute__nonnull__(1)
@@ -196,6 +201,13 @@
__attribute__nonnull__(3);
PARROT_EXPORT
+void Parrot_cx_set_pc(PARROT_INTERP,
+ ARGIN(PMC *ctx),
+ ARGIN_NULLOK(opcode_t *pc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
void Parrot_cx_set_sub(PARROT_INTERP,
ARGIN(PMC *ctx),
ARGIN_NULLOK(PMC *sub))
@@ -231,6 +243,9 @@
#define ASSERT_ARGS_Parrot_cx_get_outer_ctx __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
+#define ASSERT_ARGS_Parrot_cx_get_pc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(ctx)
#define ASSERT_ARGS_Parrot_cx_get_pmc_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
@@ -270,6 +285,9 @@
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(outer_ctx)
+#define ASSERT_ARGS_Parrot_cx_set_pc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(ctx)
#define ASSERT_ARGS_Parrot_cx_set_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
Modified: branches/context_pmc3/lib/Parrot/OpTrans/CGP.pm
==============================================================================
--- branches/context_pmc3/lib/Parrot/OpTrans/CGP.pm Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/lib/Parrot/OpTrans/CGP.pm Tue Aug 25 23:29:24 2009 (r40801)
@@ -107,7 +107,7 @@
my ( $self, $offset ) = @_;
# this must be a single expression, in case it's in a single-statement if
- return "do {\nCURRENT_CONTEXT_FIELD(interp, current_pc) = CUR_OPCODE + $offset;\n"
+ return "do {\nParrot_cx_set_pc(interp, CONTEXT(interp), CUR_OPCODE + $offset);\n"
. "goto **(void **)(cur_opcode += $offset);\n} while (1)";
}
Modified: branches/context_pmc3/src/context.c
==============================================================================
--- branches/context_pmc3/src/context.c Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/context.c Tue Aug 25 23:29:24 2009 (r40801)
@@ -484,6 +484,44 @@
c->current_sub = sub;
}
+/*
+
+=item C<opcode_t* Parrot_cx_get_pc(PARROT_INTERP, PMC *ctx)>
+
+Get program counter of Sub invocation.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+opcode_t*
+Parrot_cx_get_pc(PARROT_INTERP, ARGIN(PMC *ctx))
+{
+ ASSERT_ARGS(Parrot_cx_get_pc)
+ Parrot_Context *c = Parrot_cx_get_context(interp, ctx);
+ return c->current_pc;
+}
+
+
+/*
+
+=item C<void Parrot_cx_set_pc(PARROT_INTERP, PMC *ctx, opcode_t *pc)>
+
+Set program counter of Sub invocation.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_cx_set_pc(PARROT_INTERP, ARGIN(PMC *ctx), ARGIN_NULLOK(opcode_t *pc))
+{
+ ASSERT_ARGS(Parrot_cx_set_pc)
+ Parrot_Context *c = Parrot_cx_get_context(interp, ctx);
+ c->current_pc = pc;
+}
/*
Modified: branches/context_pmc3/src/debug.c
==============================================================================
--- branches/context_pmc3/src/debug.c Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/debug.c Tue Aug 25 23:29:24 2009 (r40801)
@@ -3520,7 +3520,7 @@
Parrot_io_eprintf(interp, "%Ss", str);
if (interp->code->annotations) {
PMC *annot = PackFile_Annotations_lookup(interp, interp->code->annotations,
- CONTEXT_FIELD(interp, ctx, current_pc) - interp->code->base.data + 1, NULL);
+ Parrot_cx_get_pc(interp, ctx) - interp->code->base.data + 1, NULL);
if (!PMC_IS_NULL(annot)) {
PMC *pfile = VTABLE_get_pmc_keyed_str(interp, annot,
Parrot_str_new_constant(interp, "file"));
@@ -3557,8 +3557,8 @@
/* recursion detection */
if (!PMC_IS_NULL(old) && PMC_cont(old) &&
- CONTEXT_FIELD(interp, PMC_cont(old)->to_ctx, current_pc) ==
- CONTEXT_FIELD(interp, PMC_cont(sub)->to_ctx, current_pc) &&
+ Parrot_cx_get_pc(interp, PMC_cont(old)->to_ctx) ==
+ Parrot_cx_get_pc(interp, PMC_cont(sub)->to_ctx) &&
Parrot_cx_get_sub(interp, PMC_cont(old)->to_ctx) ==
Parrot_cx_get_sub(interp, PMC_cont(sub)->to_ctx)) {
++rec_level;
@@ -3573,7 +3573,7 @@
Parrot_io_eprintf(interp, "%Ss", str);
if (interp->code->annotations) {
PMC *annot = PackFile_Annotations_lookup(interp, interp->code->annotations,
- CONTEXT_FIELD(interp, sub_cont->to_ctx, current_pc) - interp->code->base.data + 1,
+ Parrot_cx_get_pc(interp, sub_cont->to_ctx) - interp->code->base.data + 1,
NULL);
if (!PMC_IS_NULL(annot)) {
Modified: branches/context_pmc3/src/pmc/exception.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/exception.pmc Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/pmc/exception.pmc Tue Aug 25 23:29:24 2009 (r40801)
@@ -782,7 +782,7 @@
PackFile_ByteCode *seg = sub->seg;
opcode_t *pc = cont && cur_ctx == cont->to_ctx
? cont->address
- : CONTEXT_FIELD(interp, cur_ctx, current_pc);
+ : Parrot_cx_get_pc(interp, cur_ctx);
annotations = PackFile_Annotations_lookup(interp,
seg->annotations, pc - seg->base.data,
Modified: branches/context_pmc3/src/pmc/parrotinterpreter.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/parrotinterpreter.pmc Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/pmc/parrotinterpreter.pmc Tue Aug 25 23:29:24 2009 (r40801)
@@ -541,7 +541,7 @@
&& sub_pmc->vtable->base_type == enum_class_Sub) {
Parrot_Sub_attributes *sub;
PackFile_ByteCode *seg;
- opcode_t *pc = CONTEXT_FIELD(interp, ctx, current_pc);
+ opcode_t *pc = Parrot_cx_get_pc(interp, ctx);
PMC_get_sub(interp, sub_pmc, sub);
seg = sub->seg;
Modified: branches/context_pmc3/src/pmc/sub.pmc
==============================================================================
--- branches/context_pmc3/src/pmc/sub.pmc Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/pmc/sub.pmc Tue Aug 25 23:29:24 2009 (r40801)
@@ -283,8 +283,8 @@
* create new context, place it in interpreter */
context = Parrot_set_new_context(INTERP, sub->n_regs_used);
Parrot_cx_set_sub(interp, context, SELF);
- CONTEXT_FIELD(interp, context, caller_ctx) = caller_ctx;
- CONTEXT_FIELD(interp, context, current_pc) = pc;
+ Parrot_cx_set_caller_ctx(interp, context, caller_ctx);
+ Parrot_cx_set_pc(interp, context, pc);
Parrot_cx_set_continuation(interp, context, ccont);
/* check recursion/call depth */
Modified: branches/context_pmc3/src/runcore/cores.c
==============================================================================
--- branches/context_pmc3/src/runcore/cores.c Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/runcore/cores.c Tue Aug 25 23:29:24 2009 (r40801)
@@ -292,7 +292,7 @@
ASSERT_ARGS(runops_fast_core)
/* disable pc */
- CURRENT_CONTEXT_FIELD(interp, current_pc) = NULL;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), NULL);
while (pc) {
if (pc < code_start || pc >= code_end)
@@ -328,7 +328,7 @@
ASSERT_ARGS(runops_cgoto_core)
/* disable pc */
- CURRENT_CONTEXT_FIELD(interp, current_pc) = NULL;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), NULL);
#ifdef HAVE_COMPUTED_GOTO
pc = cg_core(pc, interp);
@@ -407,7 +407,7 @@
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"attempt to access code outside of current code segment");
- CURRENT_CONTEXT_FIELD(interp, current_pc) = pc;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), pc);
DO_OP(pc, interp);
trace_op(interp, code_start, code_end, pc);
@@ -461,7 +461,7 @@
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"attempt to access code outside of current code segment");
- CURRENT_CONTEXT_FIELD(interp, current_pc) = pc;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), pc);
DO_OP(pc, interp);
}
@@ -494,7 +494,7 @@
"attempt to access code outside of current code segment");
Parrot_gc_mark_and_sweep(interp, GC_TRACE_FULL);
- CURRENT_CONTEXT_FIELD(interp, current_pc) = pc;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), pc);
DO_OP(pc, interp);
}
@@ -534,7 +534,7 @@
while (pc) {/* && pc >= code_start && pc < code_end) */
opcode_t cur_op;
- CURRENT_CONTEXT_FIELD(interp, current_pc) = pc;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), pc);
profile->cur_op = cur_op = *pc + PARROT_PROF_EXTRA;
profile->starttime = Parrot_floatval_time();
profile->data[cur_op].numcalls++;
@@ -595,7 +595,7 @@
pc);
}
- CURRENT_CONTEXT_FIELD(interp, current_pc) = pc;
+ Parrot_cx_set_pc(interp, CONTEXT(interp), pc);
DO_OP(pc, interp);
if (interp->pdb->state & PDB_STOPPED) {
Modified: branches/context_pmc3/src/sub.c
==============================================================================
--- branches/context_pmc3/src/sub.c Tue Aug 25 23:17:47 2009 (r40800)
+++ branches/context_pmc3/src/sub.c Tue Aug 25 23:29:24 2009 (r40801)
@@ -291,14 +291,14 @@
}
/* return here if there is no current pc */
- if (CONTEXT_FIELD(interp, ctx, current_pc) == NULL)
+ if (Parrot_cx_get_pc(interp, ctx) == NULL)
return 1;
/* calculate the current pc */
- info->pc = CONTEXT_FIELD(interp, ctx, current_pc) - sub->seg->base.data;
+ info->pc = Parrot_cx_get_pc(interp, ctx) - sub->seg->base.data;
/* determine the current source file/line */
- if (CONTEXT_FIELD(interp, ctx, current_pc)) {
+ if (Parrot_cx_get_pc(interp, ctx)) {
const size_t offs = info->pc;
size_t i, n;
opcode_t *pc = sub->seg->base.data;
More information about the parrot-commits
mailing list