Author: leo
Date: Thu Oct 13 05:30:33 2005
New Revision: 9475

Modified:
   trunk/classes/continuation.pmc
   trunk/classes/coroutine.pmc
   trunk/classes/parrotinterpreter.pmc
   trunk/classes/retcontinuation.pmc
   trunk/classes/sub.pmc
   trunk/imcc/optimizer.c
   trunk/include/parrot/interpreter.h
   trunk/include/parrot/sub.h
   trunk/ops/core.ops
   trunk/src/debug.c
   trunk/src/dod.c
   trunk/src/inter_call.c
   trunk/src/inter_create.c
   trunk/src/inter_run.c
   trunk/src/sub.c
   trunk/src/thread.c
   trunk/src/warnings.c
Log:
Variable-sized reg frames 4b - split interpreter context structure

* interp->ctx consists now of 3 pointers {state, bp, bp_ps}
* typedef'ed parrot_context_t to the state part of the context
* set ctx->bp (and later bp_ps) during context allocation, i.e.
  during a sub call, remember register basepointers in the context
* on sub return or context switch all 3 pointers are set
* get rid of some CONTEXT macro usage by using an explicit ctx var

Tested on linux/x86, linux/x86_64, and OS/X ppc


Modified: trunk/classes/continuation.pmc
==============================================================================
--- trunk/classes/continuation.pmc      (original)
+++ trunk/classes/continuation.pmc      Thu Oct 13 05:30:33 2005
@@ -85,7 +85,7 @@ Marks the continuation as live.
 
     void mark () {
         struct Parrot_cont * cc = PMC_cont(SELF);
-        mark_context(INTERP, &cc->to_ctx);
+        mark_context(INTERP, cc->to_ctx);
     }
 
 /*
@@ -101,8 +101,8 @@ Destroys the continuation.
     void destroy () {
         struct Parrot_cont * cc = PMC_cont(SELF);
         if (cc) {
-            if (cc->from_ctx.bp)
-                Parrot_free_context(interpreter, &cc->from_ctx, 0);
+            if (cc->from_ctx)
+                Parrot_free_context(interpreter, cc->from_ctx, 0);
             if (cc->ctx_copy)
                 mem_sys_free(cc->ctx_copy);
             mem_sys_free(cc);
@@ -209,11 +209,12 @@ destination to continue execution.
     void* invoke (void* next) {
         struct Parrot_cont * cc = PMC_cont(SELF);
         struct parrot_regs_t *caller_regs;
+        parrot_context_t *ctx;
         opcode_t *pc;
 
         /* debug print before context is switched */
         if (Interp_trace_TEST(INTERP, PARROT_TRACE_SUB_CALL_FLAG)) {
-            PMC *sub = CONTEXT(cc->to_ctx)->current_sub;
+            PMC *sub = cc->to_ctx->current_sub;
 
             PIO_eprintf(INTERP, "# Back in sub '%Ss'\n",
                     Parrot_full_sub_name(INTERP, sub));
@@ -222,19 +223,19 @@ destination to continue execution.
         /*
          * set context
          */
-        INTERP->ctx = cc->to_ctx;
+        CONTEXT(INTERP->ctx) = ctx = cc->to_ctx;
+        INTERP->ctx.bp = ctx->bp;
+        INTERP->ctx.bp_ps = ctx->bp_ps;
         if (cc->ctx_copy) {
             /* copy only these parts that are different
              * XXX what else?
              */
-            CONTEXT(INTERP->ctx)->current_results =
-                cc->ctx_copy->current_results;
-            CONTEXT(INTERP->ctx)->current_args =
-                cc->ctx_copy->current_args;
+            ctx->current_results = cc->ctx_copy->current_results;
+            ctx->current_args = cc->ctx_copy->current_args;
         }
         pc = cc->address;
         if (pc) {
-            if (CONTEXT(INTERP->ctx)->current_results) {
+            if (ctx->current_results) {
                 /*
                  * the register pointer is already switched back
                  * to the caller, therefore the registers of the
@@ -272,7 +273,7 @@ Experimental: return caller info as a ST
 */
 
     STRING* get_string() {
-       return Parrot_Context_infostr(INTERP, &PMC_cont(SELF)->to_ctx);
+       return Parrot_Context_infostr(INTERP, PMC_cont(SELF)->to_ctx);
     }
 
 /*
@@ -287,7 +288,7 @@ Experimental: return caller PMC or Undef
 
     METHOD PMC* caller() {
         struct Parrot_cont * cc = PMC_cont(SELF);
-        PMC *caller = CONTEXT(cc->to_ctx)->current_sub;
+        PMC *caller = cc->to_ctx->current_sub;
         if (!caller || !PMC_sub(caller)->address) {
             caller = pmc_new(INTERP, enum_class_Undef);
         }
@@ -306,7 +307,7 @@ Experimental: return continuation PMC of
 
     METHOD PMC* continuation() {
         struct Parrot_cont * cc = PMC_cont(SELF);
-        PMC *cont = CONTEXT(cc->to_ctx)->current_cont;
+        PMC *cont = cc->to_ctx->current_cont;
         if (cont)
             return cont;
         return pmc_new(INTERP, enum_class_Undef);

Modified: trunk/classes/coroutine.pmc
==============================================================================
--- trunk/classes/coroutine.pmc (original)
+++ trunk/classes/coroutine.pmc Thu Oct 13 05:30:33 2005
@@ -93,47 +93,50 @@ Swaps the "context".
 
     void* invoke (void* next) {
         struct Parrot_coro * co = PMC_coro(SELF);
+        struct parrot_regs_t *caller_regs;
         struct PackFile_ByteCode *wanted_seg;
         opcode_t * dest = co->address;
-        parrot_context_t ctx;
+        parrot_context_t *ctx;
         PMC *ccont;
 
-        ctx = INTERP->ctx;
-
-        if (!co->ctx.bp) {
+        if (!co->ctx) {
             PMC *pad;
 
             ccont = INTERP->current_cont;
             if (ccont == NEED_CONTINUATION) {
                 ccont = new_ret_continuation_pmc(interpreter, next);
             }
+            caller_regs = INTERP->ctx.bp;
             /*
              * first time set current sub, cont, object
              */
             Parrot_alloc_context(INTERP);
-            co->ctx = INTERP->ctx;
-            wanted_seg = co->seg;
-            co->caller_seg = INTERP->code;
+            co->ctx = ctx = CONTEXT(INTERP->ctx);
+            PMC_cont(ccont)->from_ctx = ctx;
+            /*
+             * XXX are our coroutines closures?
+             */
             pad = scratchpad_get_current(INTERP);
             if (pad) {
-                stack_push(INTERP, &CONTEXT(co->ctx)->pad_stack, pad,
+                stack_push(INTERP, &ctx->pad_stack, pad,
                         STACK_ENTRY_PMC, STACK_CLEANUP_NULL);
             }
-            CONTEXT(co->ctx)->current_sub = SELF;
-            CONTEXT(co->ctx)->current_cont = ccont;
-            PMC_cont(ccont)->from_ctx = INTERP->ctx;
-            CONTEXT(co->ctx)->current_object = NULL;
+            ctx->current_sub = SELF;
+            ctx->current_cont = ccont;
+            ctx->current_args = INTERP->current_args;
+            ctx->current_object = NULL;
             INTERP->current_object = NULL;
             INTERP->current_cont = NULL;
+            INTERP->current_args = NULL;
 
             PObj_get_FLAGS(SELF) |= SUB_FLAG_CORO_FF;
-            CONTEXT(INTERP->ctx)->current_args = INTERP->current_args;
-            INTERP->current_args = NULL;
+            wanted_seg = co->seg;
+            co->caller_seg = INTERP->code;
             /* copy args from interpreter */
             if (*dest == PARROT_OP_get_params_pc) {
                 INTERP->current_params = dest;
                 dest = parrot_pass_args(INTERP, wanted_seg,
-                        ctx.bp,
+                        caller_regs,
                         PARROT_OP_get_params_pc);
             }
         }
@@ -144,21 +147,25 @@ Swaps the "context".
             /* remember segment of caller */
             co->caller_seg = INTERP->code;
             /* and the recent call context */
-            ccont = CONTEXT(co->ctx)->current_cont;
-            PMC_cont(ccont)->to_ctx = INTERP->ctx;
+            ccont = co->ctx->current_cont;
+            PMC_cont(ccont)->to_ctx = CONTEXT(INTERP->ctx);
             /* set context to coro context */
-            INTERP->ctx = co->ctx;
+            CONTEXT(INTERP->ctx) = ctx = co->ctx;
+            INTERP->ctx.bp = ctx->bp;
+            INTERP->ctx.bp_ps = ctx->bp_ps;
         }
         else {
             PObj_get_FLAGS(SELF) &= ~SUB_FLAG_CORO_FF;
             /* switch back to last remembered code seg and context */
             wanted_seg = co->caller_seg;
-            ccont = CONTEXT(co->ctx)->current_cont;
-            INTERP->ctx = ctx = PMC_cont(ccont)->to_ctx;
+            ccont = co->ctx->current_cont;
+            CONTEXT(INTERP->ctx) = ctx = PMC_cont(ccont)->to_ctx;
+            INTERP->ctx.bp = ctx->bp;
+            INTERP->ctx.bp_ps = ctx->bp_ps;
             /* yield values */
-            if (INTERP->current_returns && CONTEXT(ctx)->current_results)
+            if (INTERP->current_returns && ctx->current_results)
                 parrot_pass_args(INTERP, wanted_seg,
-                        co->ctx.bp,
+                        co->ctx->bp,
                         PARROT_OP_get_results_pc);
         }
 
@@ -187,8 +194,8 @@ Marks the coroutine as live.
         mark_stack(INTERP, c->co_control_base);
         mark_stack(INTERP, c->co_pad_stack);
 #endif
-        if (c && c->ctx.bp)
-            mark_context(INTERP, &c->ctx);
+        if (c && c->ctx)
+            mark_context(INTERP, c->ctx);
     }
 }
 

Modified: trunk/classes/parrotinterpreter.pmc
==============================================================================
--- trunk/classes/parrotinterpreter.pmc (original)
+++ trunk/classes/parrotinterpreter.pmc Thu Oct 13 05:30:33 2005
@@ -454,7 +454,7 @@ Introspection interface. C<key> can be:
         int level = 0;
         PMC* nextkey;
         STRING *item, *s;
-        parrot_context_t ctx;
+        parrot_context_t *ctx;
         PMC *cont;
 
         item =  key_string(interpreter, key);
@@ -464,27 +464,27 @@ Introspection interface. C<key> can be:
         nextkey = key_next(INTERP, key);
         if (nextkey)
             level = key_integer(interpreter, nextkey);
-        ctx = interpreter->ctx;
+        ctx = CONTEXT(interpreter->ctx);
         for (; level; --level) {
-            cont = CONTEXT(ctx)->current_cont;
+            cont = ctx->current_cont;
             if (PMC_IS_NULL(cont) || !PMC_cont(cont)->seg)
                 real_exception(interpreter, NULL, E_ValueError,
                         "No such caller depth");
             ctx = PMC_cont(cont)->to_ctx;
-            if (!CONTEXT(ctx)->current_sub)
+            if (!ctx->current_sub)
                 real_exception(interpreter, NULL, E_ValueError,
                         "No such caller depth");
 
         }
         s = CONST_STRING(interpreter, "sub");
         if (string_equal(interpreter, item, s) == 0)
-            return CONTEXT(ctx)->current_sub;
+            return ctx->current_sub;
         s = CONST_STRING(interpreter, "pad");
         if (string_equal(interpreter, item, s) == 0)
-            return stack_peek(interpreter, CONTEXT(ctx)->pad_stack, NULL);
+            return stack_peek(interpreter, ctx->pad_stack, NULL);
         s = CONST_STRING(interpreter, "continuation");
         if (string_equal(interpreter, item, s) == 0)
-            return VTABLE_clone(interpreter, CONTEXT(ctx)->current_cont);
+            return VTABLE_clone(interpreter, ctx->current_cont);
         return PMCNULL;
     }
 /*

Modified: trunk/classes/retcontinuation.pmc
==============================================================================
--- trunk/classes/retcontinuation.pmc   (original)
+++ trunk/classes/retcontinuation.pmc   Thu Oct 13 05:30:33 2005
@@ -88,12 +88,11 @@ the frame pointer in the stack frame cac
         Stack_Chunk_t *ctr_stack, *stack_now;
         struct Parrot_cont * cc = PMC_cont(SELF);
         struct parrot_regs_t *caller_regs;
-        parrot_context_t ctx;
         /*
          * unwind control stack
          */
         stack_now = CONTEXT(INTERP->ctx)->control_stack;
-        ctr_stack = CONTEXT(cc->to_ctx)->control_stack;
+        ctr_stack = cc->to_ctx->control_stack;
         while (stack_now != ctr_stack) {
             if (!stack_now || !ctr_stack)
                 internal_exception(1, "Control stack damaged");
@@ -108,15 +107,17 @@ the frame pointer in the stack frame cac
 
         /* debug print before context is switched */
         if (Interp_trace_TEST(INTERP, PARROT_TRACE_SUB_CALL_FLAG)) {
-            PMC *to_sub = CONTEXT(cc->to_ctx)->current_sub;
-            PMC *from_sub = CONTEXT(cc->from_ctx)->current_sub;
+            PMC *to_sub = cc->to_ctx->current_sub;
+            PMC *from_sub = cc->from_ctx->current_sub;
 
             PIO_eprintf(INTERP, "# Back in sub '%Ss' from '%Ss\n",
                     Parrot_full_sub_name(INTERP, to_sub),
                     Parrot_full_sub_name(INTERP, from_sub));
         }
         caller_regs = INTERP->ctx.bp;
-        INTERP->ctx = cc->to_ctx;
+        CONTEXT(INTERP->ctx) = cc->to_ctx;
+        INTERP->ctx.bp = CONTEXT(INTERP->ctx)->bp;
+        INTERP->ctx.bp_ps = CONTEXT(INTERP->ctx)->bp_ps;
         next = cc->address;
         if (next) {
             if (CONTEXT(INTERP->ctx)->current_results) {
@@ -135,8 +136,8 @@ the frame pointer in the stack frame cac
             }
             INTERP->current_returns = NULL;
         }
-        Parrot_free_context(INTERP, &cc->from_ctx, 1);
-        cc->from_ctx.bp = NULL;
+        Parrot_free_context(INTERP, cc->from_ctx, 1);
+        cc->from_ctx = NULL;
         INTERP->current_args = NULL;
         /* no address and no segment */
         if (!cc->seg) {

Modified: trunk/classes/sub.pmc
==============================================================================
--- trunk/classes/sub.pmc       (original)
+++ trunk/classes/sub.pmc       Thu Oct 13 05:30:33 2005
@@ -340,7 +340,7 @@ create_ctx:
                     PARROT_OP_get_params_pc);
         }
 
-        PMC_cont(ccont)->from_ctx = INTERP->ctx;
+        PMC_cont(ccont)->from_ctx = CONTEXT(INTERP->ctx);
         if (!PMC_IS_NULL(INTERP->current_object)) {
             context->current_object = INTERP->current_object;
             INTERP->current_object = NULL;
@@ -601,7 +601,7 @@ Return amount of used registers for regi
 
     METHOD INTVAL __get_regs_used(char *kind) {
         struct Parrot_sub * sub = PMC_sub(SELF);
-        /* TODO switch to canonical NiSP order 
+        /* TODO switch to canonical NiSP order
          * see also imcc/reg_alloc.c
          */
         const char *types = "INSP";

Modified: trunk/imcc/optimizer.c
==============================================================================
--- trunk/imcc/optimizer.c      (original)
+++ trunk/imcc/optimizer.c      Thu Oct 13 05:30:33 2005
@@ -85,7 +85,7 @@ int
 pre_optimize(Interp *interpreter, IMC_Unit * unit)
 {
     int changed = 0;
-    
+
     if (IMCC_INFO(interpreter)->optimizer_level & OPT_PRE) {
         IMCC_info(interpreter, 2, "pre_optimize\n");
         /* TODO integrate all in one pass */
@@ -673,7 +673,7 @@ IMCC_subst_constants(Interp *interpreter
     char b[128], fmt[64], op[20];
     const char *debug_fmt;
     int found, branched;
-    parrot_context_t ctx;
+    parrot_context_t *ctx;
 
 
     /* construct a FLOATVAL_FMT with needed precision */
@@ -756,7 +756,7 @@ IMCC_subst_constants(Interp *interpreter
         return NULL;
     }
     /* preserve registers */
-    ctx = interpreter->ctx;
+    ctx = CONTEXT(interpreter->ctx);
     Parrot_alloc_context(interpreter);
 
     IMCC_debug(interpreter, DEBUG_OPT1, debug_fmt, name);
@@ -807,8 +807,10 @@ IMCC_subst_constants(Interp *interpreter
     /*
      * restore and recycle register frame
      */
-    Parrot_free_context(interpreter, &interpreter->ctx, 1);
-    interpreter->ctx = ctx;
+    Parrot_free_context(interpreter, CONTEXT(interpreter->ctx), 1);
+    CONTEXT(interpreter->ctx) = ctx;
+    interpreter->ctx.bp = ctx->bp;
+    interpreter->ctx.bp_ps = ctx->bp_ps;
     return tmp;
 }
 

Modified: trunk/include/parrot/interpreter.h
==============================================================================
--- trunk/include/parrot/interpreter.h  (original)
+++ trunk/include/parrot/interpreter.h  Thu Oct 13 05:30:33 2005
@@ -169,9 +169,16 @@ struct parrot_regs_t {
     struct PReg pmc_reg;
 };
 
-struct Parrot_Context {
+typedef union {
+    PMC         **regs_p;
+    STRING      **regs_s;
+} Regs_ps;
+
+typedef struct Parrot_Context {
     struct Parrot_Context *prev;
     INTVAL ref_count;                   /* how often refered to */
+    struct parrot_regs_t  *bp;          /* register base pointer */
+    Regs_ps               *bp_ps;       /* yet unused */
     struct Stack_Chunk *int_reg_stack;  /* register frame stacks */
     struct Stack_Chunk *num_reg_stack;
     struct Stack_Chunk *string_reg_stack;
@@ -203,7 +210,7 @@ struct Parrot_Context {
     INTVAL current_HLL;         /* see also src/hll.c */
     opcode_t *current_args;      /* ptr into code with set_args opcode */
     opcode_t *current_results;   /* ptr into code with get_results opcode */
-};
+} parrot_context_t;
 
 #define ALIGNED_CTX_SIZE ( ((sizeof(struct Parrot_Context) + NUMVAL_SIZE - 1) \
         / NUMVAL_SIZE) * NUMVAL_SIZE )
@@ -224,12 +231,13 @@ typedef struct _Prederef {
 } Prederef;
 
 
-typedef union All_Context {
-    struct parrot_regs_t *bp;           /* register base pointer */
-    struct Parrot_Context *rctx;        /* context is at rctx[-1] */
-} parrot_context_t;
+struct All_Context {
+    struct parrot_regs_t  *bp;          /* register base pointer */
+    Regs_ps               *bp_ps;       /* yet unused */
+    struct Parrot_Context *state;       /* ontext  */
+};
 
-#define CONTEXT(ctx) ((ctx).rctx -1)
+#define CONTEXT(ctx) ((ctx).state)
 
 typedef struct _context_mem {
     char *data;                     /* ctx + register store */
@@ -241,7 +249,7 @@ typedef struct _context_mem {
  * The actual interpreter structure
  */
 struct parrot_interp_t {
-    parrot_context_t ctx;
+    struct All_Context ctx;
     context_mem ctx_mem;                /* ctx memory managment */
 
     struct Stash *globals;              /* Pointer to the global variable

Modified: trunk/include/parrot/sub.h
==============================================================================
--- trunk/include/parrot/sub.h  (original)
+++ trunk/include/parrot/sub.h  Thu Oct 13 05:30:33 2005
@@ -90,7 +90,7 @@ typedef struct Parrot_coro {
 
     /* - end common */
 
-    parrot_context_t ctx;          /* coroutine context */
+    struct Parrot_Context  *ctx;          /* coroutine context */
     struct PackFile_ByteCode *caller_seg;  /* bytecode segment */
 } * parrot_coro_t;
 
@@ -101,10 +101,10 @@ typedef struct Parrot_cont {
     /* continuation destination */
     struct PackFile_ByteCode *seg;   /* bytecode segment */
     opcode_t *address;               /* start of bytecode, addr to continue */
-    parrot_context_t to_ctx;         /* pointer to dest context */
-    struct Parrot_Context *ctx_copy; /* full continuation only */
+    struct Parrot_Context *to_ctx;   /* pointer to dest context */
     /* a Continuation keeps the from_ctx alive */
-    parrot_context_t from_ctx;       /* the sub, this cont is returning from */
+    struct Parrot_Context *from_ctx;  /* sub, this cont is returning from */
+    struct Parrot_Context *ctx_copy; /* full continuation only */
 } * parrot_cont_t;
 
 #define PMC_cont(pmc)            ((parrot_cont_t)PMC_struct_val(pmc))

Modified: trunk/ops/core.ops
==============================================================================
--- trunk/ops/core.ops  (original)
+++ trunk/ops/core.ops  Thu Oct 13 05:30:33 2005
@@ -515,7 +515,7 @@ op get_params(inconst PMC) {
     interpreter->current_params = this;
     cont_pmc = CONTEXT(interpreter->ctx)->current_cont;
 
-    caller_regs = PMC_cont(cont_pmc)->to_ctx.bp;
+    caller_regs = PMC_cont(cont_pmc)->to_ctx->bp;
     pc = parrot_pass_args(interpreter, sub->seg, caller_regs,
            PARROT_OP_get_params_pc);
     goto ADDRESS(pc);

Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c   (original)
+++ trunk/src/debug.c   Thu Oct 13 05:30:33 2005
@@ -2954,33 +2954,33 @@ PDB_backtrace(Interp *interpreter)
     PMC *sub;
     PMC *old = PMCNULL;
     int rec_level = 0;
-    parrot_context_t ctx;
+    parrot_context_t *ctx;
 
     /* information about the current sub */
     sub = interpinfo_p(interpreter, CURRENT_SUB);
+    ctx = CONTEXT(interpreter->ctx);
     if (!PMC_IS_NULL(sub)) {
-       str = Parrot_Context_infostr(interpreter, &interpreter->ctx);
+       str = Parrot_Context_infostr(interpreter, ctx);
        if (str)
            PIO_eprintf(interpreter, "%Ss", str);
     }
 
     /* backtrace: follow the continuation chain */
-    ctx = interpreter->ctx;
     while (1) {
-        sub = CONTEXT(ctx)->current_cont;
+        sub = ctx->current_cont;
         if (!sub)
             break;
         str = Parrot_Context_infostr(interpreter,
-                   &PMC_cont(sub)->to_ctx);
+                   PMC_cont(sub)->to_ctx);
         if (!str)
             break;
 
        /* recursion detection */
        if (!PMC_IS_NULL(old) && PMC_cont(old) &&
-           CONTEXT(PMC_cont(old)->to_ctx)->current_pc ==
-            CONTEXT(PMC_cont(sub)->to_ctx)->current_pc &&
-           CONTEXT(PMC_cont(old)->to_ctx)->current_sub ==
-            CONTEXT(PMC_cont(sub)->to_ctx)->current_sub) {
+           PMC_cont(old)->to_ctx->current_pc ==
+            PMC_cont(sub)->to_ctx->current_pc &&
+           PMC_cont(old)->to_ctx->current_sub ==
+            PMC_cont(sub)->to_ctx->current_sub) {
             ++rec_level;
        } else if (rec_level != 0) {
            PIO_eprintf(interpreter, "... call repeated %d times\n", rec_level);
@@ -2994,7 +2994,7 @@ PDB_backtrace(Interp *interpreter)
        /* get the next Continuation */
         ctx = PMC_cont(sub)->to_ctx;
        old = sub;
-        if (!ctx.rctx || !CONTEXT(ctx)->prev)
+        if (!ctx || !ctx->prev)
             break;
     }
     if (rec_level != 0) {

Modified: trunk/src/dod.c
==============================================================================
--- trunk/src/dod.c     (original)
+++ trunk/src/dod.c     Thu Oct 13 05:30:33 2005
@@ -357,7 +357,7 @@ Parrot_dod_trace_root(Interp *interprete
         pobject_lives(interpreter, (PObj *)interpreter->DOD_registry);
 
     /* Walk all stacks */
-    mark_context(interpreter, &interpreter->ctx);
+    mark_context(interpreter, CONTEXT(interpreter->ctx));
 
     /* Walk the iodata */
     Parrot_IOData_mark(interpreter, interpreter->piodata);

Modified: trunk/src/inter_call.c
==============================================================================
--- trunk/src/inter_call.c      (original)
+++ trunk/src/inter_call.c      Thu Oct 13 05:30:33 2005
@@ -59,7 +59,7 @@ Parrot_init_ret_nci(Interp *interpreter,
         const char *sig)
 {
     PMC *current_cont;
-    parrot_context_t ctx;
+    struct Parrot_Context *ctx;
     struct PackFile_ByteCode *seg;
     /*
      * if this NCI call was a taicall, return results to caller's get_results
@@ -72,14 +72,14 @@ Parrot_init_ret_nci(Interp *interpreter,
         seg = PMC_cont(current_cont)->seg;
     }
     else {
-        ctx = interpreter->ctx;
+        ctx = CONTEXT(interpreter->ctx);
         seg = interpreter->code;
     }
     /* TODO simplify all */
     Parrot_init_arg_sig(interpreter, interpreter->code, interpreter->ctx.bp,
             sig, NULL, &st->src);
-    Parrot_init_arg_op(interpreter, seg, ctx.bp,
-            CONTEXT(ctx)->current_results, &st->dest);
+    Parrot_init_arg_op(interpreter, seg, ctx->bp,
+            ctx->current_results, &st->dest);
     next_arg(interpreter, &st->src);
     next_arg(interpreter, &st->dest);
     return 1;
@@ -497,14 +497,20 @@ clone_key_arg(Interp *interpreter, struc
         }
 
         if (any_registers) {
-            parrot_context_t new_ctx = interpreter->ctx;
+            parrot_context_t new_ctx;
+
+            new_ctx.bp = interpreter->ctx.bp;
+            new_ctx.bp_ps = interpreter->ctx.bp_ps;
             /* need old = src context
              * clone sets key values according to refered
              * register items
+             *
+             * XXX
              */
             interpreter->ctx.bp = st->src.regs;
             p_arg = VTABLE_clone(interpreter, p_arg);
-            interpreter->ctx = new_ctx;
+            interpreter->ctx.bp = new_ctx.bp;
+            interpreter->ctx.bp_ps = new_ctx.bp_ps;
             UVal_pmc(st->val) = p_arg;
         }
     }
@@ -693,7 +699,6 @@ parrot_pass_args(Interp *interpreter, st
         struct parrot_regs_t *caller_regs, int what)
 {
     const char *action;
-    parrot_context_t old_ctx;
     struct call_state st;
     int todo;
     opcode_t *src_pc, *dst_pc;

Modified: trunk/src/inter_create.c
==============================================================================
--- trunk/src/inter_create.c    (original)
+++ trunk/src/inter_create.c    Thu Oct 13 05:30:33 2005
@@ -82,13 +82,11 @@ static void setup_default_compreg(Parrot
  *    +----------+--------------------------+
  *    | context  | registers                +
  *    +----------+--------------------------+
- *               ^
- *               |
- *               ctx.bp pointer
+ *    ^          ^
+ *    |          |
+ *    ctx.state  ctx.bp pointer
  *
  * Registers are addressed as usual via the register base pointer ctx.bp.
- * Context variables are to the "left" of the pointer and accessible with
- * the ctx union member ctx.rctx e.g. ctx.rctx[-1].current_sub
  *
  * The macro CONTEXT() hides these details
  *
@@ -186,15 +184,16 @@ static void
 create_initial_context(Interp *interpreter)
 {
     size_t to_alloc = sizeof(struct parrot_regs_t) + ALIGNED_CTX_SIZE;
-    char *p;
+    void *p;
 
-    p = mem_sys_allocate(to_alloc);
-    LVALUE_CAST(char *, interpreter->ctx.bp) = p + ALIGNED_CTX_SIZE;
+    p = mem_sys_allocate_zeroed(to_alloc);
 #if CTX_LEAK_DEBUG
-    fprintf(stderr, "alloc %p\n", interpreter->ctx.bp);
+    fprintf(stderr, "alloc %p\n", p);
 #endif
+    CONTEXT(interpreter->ctx) = p;
+    p = (void *) ((char *)p + ALIGNED_CTX_SIZE);
+    interpreter->ctx.bp = CONTEXT(interpreter->ctx)->bp = p;
     interpreter->ctx_mem.free = NULL;
-    memset(CONTEXT(interpreter->ctx), 0, sizeof(struct Parrot_Context));
     CONTEXT(interpreter->ctx)->prev = NULL;
 }
 
@@ -238,15 +237,14 @@ parrot_gc_context(Interp *interpreter)
 }
 
 static void
-init_context(Interp *interpreter, parrot_context_t *oldp)
+init_context(Interp *interpreter, struct Parrot_Context *old_state)
 {
     struct parrot_regs_t *bp;
-    parrot_context_t old = *oldp;
     int i;
 
     memcpy(CONTEXT(interpreter->ctx),
-           CONTEXT(old), sizeof(struct Parrot_Context));
-    CONTEXT(interpreter->ctx)->prev = old.rctx;
+           old_state, sizeof(struct Parrot_Context));
+    CONTEXT(interpreter->ctx)->prev = old_state;
     CONTEXT(interpreter->ctx)->ref_count = 0;
     CONTEXT(interpreter->ctx)->current_results = NULL;
     CONTEXT(interpreter->ctx)->current_args = NULL;
@@ -256,7 +254,7 @@ init_context(Interp *interpreter, parrot
      * if the architecture has 0x := NULL and 0.0 we could memset too
      *
      */
-    bp = interpreter->ctx.bp;
+    CONTEXT(interpreter->ctx)->bp = bp = interpreter->ctx.bp;
     for (i = 0; i < NUM_REGISTERS; i++) {
         BP_REG_PMC(bp, i) = PMCNULL;
         BP_REG_STR(bp, i) = NULL;
@@ -387,9 +385,8 @@ void
 Parrot_alloc_context(Interp *interpreter)
 {
 
-    parrot_context_t ctx;
-    struct Parrot_Context *p;
-    void *ptr;
+    struct Parrot_Context *old;
+    void *ptr, *p;
 
     ptr = interpreter->ctx_mem.free;
     if (ptr) {
@@ -401,13 +398,13 @@ Parrot_alloc_context(Interp *interpreter
         *(void **) ptr = NULL;
     }
     p = (void *) ((char *)ptr + ALIGNED_CTX_SIZE);
-    p[-1].prev = NULL;
-    ctx = interpreter->ctx;
-    interpreter->ctx.rctx = p;
+    old = CONTEXT(interpreter->ctx);
+    CONTEXT(interpreter->ctx) = ptr;
 #if CTX_LEAK_DEBUG
     fprintf(stderr, "alloc %p\n", p);
 #endif
-    init_context(interpreter, &ctx);
+    interpreter->ctx.bp = p;
+    init_context(interpreter, old);
 }
 
 void
@@ -425,13 +422,12 @@ Parrot_free_context(Interp *interpreter,
      * (turn CTX_LEAK_DEBUG on)
      *
      */
-    if (re_use || --CONTEXT(*ctxp)->ref_count == 0) {
-        ptr = ctxp->bp;
-        ptr = (char *)ptr - ALIGNED_CTX_SIZE;
+    if (re_use || --ctxp->ref_count == 0) {
+        ptr = ctxp;
         *(void **)ptr = interpreter->ctx_mem.free;
         interpreter->ctx_mem.free = ptr;
 #if CTX_LEAK_DEBUG
-        fprintf(stderr, "free  %p\n", ctxp->rctx);
+        fprintf(stderr, "free  %p\n", ctxp);
 #endif
     }
 }

Modified: trunk/src/inter_run.c
==============================================================================
--- trunk/src/inter_run.c       (original)
+++ trunk/src/inter_run.c       Thu Oct 13 05:30:33 2005
@@ -143,7 +143,7 @@ runops_args(Parrot_Interp interpreter, P
 {
     opcode_t offset, *dest;
     struct parrot_regs_t *bp;
-    parrot_context_t old_ctx;
+    parrot_context_t *old_ctx;
     int i;
     /*
      * FIXME argument count limited - check strlen of sig
@@ -151,7 +151,7 @@ runops_args(Parrot_Interp interpreter, P
     char new_sig[10];
     const char *sig_p;
 
-    old_ctx = interpreter->ctx;
+    old_ctx = CONTEXT(interpreter->ctx);
     interpreter->current_cont  = new_ret_continuation_pmc(interpreter, NULL);
     interpreter->current_object = obj;
     dest = VTABLE_invoke(interpreter, sub, NULL);
@@ -173,7 +173,7 @@ runops_args(Parrot_Interp interpreter, P
     }
     if (*sig_p) {
         dest = parrot_pass_args_fromc(interpreter, sig_p, dest,
-                &old_ctx, ap);
+                old_ctx, ap);
     }
 
     bp = interpreter->ctx.bp;

Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c     (original)
+++ trunk/src/sub.c     Thu Oct 13 05:30:33 2005
@@ -33,24 +33,23 @@ Marks the context C<*ctx>.
 */
 
 void
-mark_context(Interp* interpreter, parrot_context_t* ctxp)
+mark_context(Interp* interpreter, parrot_context_t* ctx)
 {
     PObj *obj;
-    parrot_context_t ctx = *ctxp;
     int i, n;
     struct parrot_regs_t *regs;
 
-    mark_stack(interpreter, CONTEXT(ctx)->pad_stack);
-    mark_stack(interpreter, CONTEXT(ctx)->user_stack);
-    mark_stack(interpreter, CONTEXT(ctx)->control_stack);
-    mark_register_stack(interpreter, CONTEXT(ctx)->int_reg_stack);
-    mark_register_stack(interpreter, CONTEXT(ctx)->num_reg_stack);
-    mark_string_register_stack(interpreter, CONTEXT(ctx)->string_reg_stack);
-    mark_pmc_register_stack(interpreter, CONTEXT(ctx)->pmc_reg_stack);
-    obj = (PObj*)CONTEXT(ctx)->current_sub;
+    mark_stack(interpreter, ctx->pad_stack);
+    mark_stack(interpreter, ctx->user_stack);
+    mark_stack(interpreter, ctx->control_stack);
+    mark_register_stack(interpreter, ctx->int_reg_stack);
+    mark_register_stack(interpreter, ctx->num_reg_stack);
+    mark_string_register_stack(interpreter, ctx->string_reg_stack);
+    mark_pmc_register_stack(interpreter, ctx->pmc_reg_stack);
+    obj = (PObj*)ctx->current_sub;
     if (obj)
         pobject_lives(interpreter, obj);
-    obj = (PObj*)CONTEXT(ctx)->current_object;
+    obj = (PObj*)ctx->current_object;
     if (obj)
         pobject_lives(interpreter, obj);
     /* the current continuation in the interpreter has
@@ -61,16 +60,16 @@ mark_context(Interp* interpreter, parrot
     obj = (PObj*)interpreter->current_cont;
     if (obj && obj != NEED_CONTINUATION)
         pobject_lives(interpreter, obj);
-    obj = (PObj*)CONTEXT(ctx)->current_cont;
+    obj = (PObj*)ctx->current_cont;
     if (obj && !PObj_live_TEST(obj))
         pobject_lives(interpreter, obj);
-    obj = (PObj*)CONTEXT(ctx)->current_method;
+    obj = (PObj*)ctx->current_method;
     if (obj)
         pobject_lives(interpreter, obj);
-    obj = (PObj*)CONTEXT(ctx)->current_package;
+    obj = (PObj*)ctx->current_package;
     if (obj)
         pobject_lives(interpreter, obj);
-    regs = ctx.bp;
+    regs = ctx->bp;
     for (i = 0; i < NUM_REGISTERS; ++i) {
         obj = (PObj*) BP_REG_PMC(regs, i);
         if (obj)
@@ -145,11 +144,11 @@ struct Parrot_cont *
 new_continuation(Interp *interp, struct Parrot_cont *to)
 {
     struct Parrot_cont *cc = mem_sys_allocate(sizeof(struct Parrot_cont));
-    parrot_context_t to_ctx = to ? to->to_ctx : interp->ctx;
+    struct Parrot_Context *to_ctx = to ? to->to_ctx : CONTEXT(interp->ctx);
 
     cc->to_ctx = to_ctx;
-    cc->from_ctx = interp->ctx;
-    CONTEXT(cc->from_ctx)->ref_count++;
+    cc->from_ctx = CONTEXT(interp->ctx);
+    CONTEXT(interp->ctx)->ref_count++;
     if (to) {
         cc->seg = to->seg;
         cc->address = to->address;
@@ -159,7 +158,7 @@ new_continuation(Interp *interp, struct 
         cc->address = NULL;
     }
     cc->ctx_copy = mem_sys_allocate(sizeof(struct Parrot_Context));
-    memcpy(cc->ctx_copy, CONTEXT(to_ctx), sizeof(struct Parrot_Context));
+    memcpy(cc->ctx_copy, to_ctx, sizeof(struct Parrot_Context));
     return cc;
 }
 
@@ -168,7 +167,7 @@ new_continuation(Interp *interp, struct 
 =item C<struct Parrot_cont *
 new_ret_continuation(Interp *interp)>
 
-Returns a new C<Parrot_cont> with its own copy of the current context.
+Returns a new C<Parrot_cont> pointing to the current context.
 
 =cut
 
@@ -178,9 +177,8 @@ struct Parrot_cont *
 new_ret_continuation(Interp *interp)
 {
     struct Parrot_cont *cc = mem_sys_allocate(sizeof(struct Parrot_cont));
-    cc->to_ctx = interp->ctx;
-    cc->from_ctx.bp = NULL;      /* ret continuations should be created later
-                                   in the subroutine if needed */
+    cc->to_ctx = CONTEXT(interp->ctx);
+    cc->from_ctx = NULL;    /* filled in during a call */
     cc->seg = interp->code;
     cc->ctx_copy = NULL;
     cc->address = NULL;
@@ -207,7 +205,7 @@ new_coroutine(Interp *interp)
         mem_sys_allocate_zeroed(sizeof(struct Parrot_coro));
 
     co->seg = interp->code;
-    co->ctx.bp = NULL;
+    co->ctx = NULL;
     return co;
 }
 
@@ -245,9 +243,9 @@ Make true Continuation from all RetConti
 void
 invalidate_retc_context(Interp *interpreter, PMC *cont)
 {
-    parrot_context_t ctx = PMC_cont(cont)->from_ctx;
+    struct Parrot_Context *ctx = PMC_cont(cont)->from_ctx;
 
-    Parrot_set_context_threshold(interpreter, &ctx);
+    Parrot_set_context_threshold(interpreter, ctx);
     while (1) {
         /*
          * We  stop if we encounter a true continuation, because
@@ -257,8 +255,8 @@ invalidate_retc_context(Interp *interpre
         if (cont->vtable != Parrot_base_vtables[enum_class_RetContinuation])
             break;
         cont->vtable = Parrot_base_vtables[enum_class_Continuation];
-        CONTEXT(ctx)->ref_count++;
-        cont = CONTEXT(ctx)->current_cont;
+        ctx->ref_count++;
+        cont = ctx->current_cont;
         ctx = PMC_cont(cont)->from_ctx;
     }
 
@@ -302,11 +300,10 @@ Parrot_full_sub_name(Interp* interpreter
 }
 
 int
-Parrot_Context_info(Interp *interpreter, parrot_context_t *ctxp,
+Parrot_Context_info(Interp *interpreter, parrot_context_t *ctx,
        struct Parrot_Context_info *info)
 {
     struct Parrot_sub *sub;
-    parrot_context_t ctx = *ctxp;
 
     /* set file/line/pc defaults */
     info->file = "(unknown file)";
@@ -317,7 +314,7 @@ Parrot_Context_info(Interp *interpreter,
     info->fullname = NULL;
 
     /* is the current sub of the specified context valid? */
-    if (PMC_IS_NULL(CONTEXT(ctx)->current_sub)) {
+    if (PMC_IS_NULL(ctx->current_sub)) {
        info->subname = string_from_cstring(interpreter, "???", 3);
        info->nsname = info->subname;
        info->fullname = string_from_cstring(interpreter, "??? :: ???", 10);
@@ -326,21 +323,21 @@ Parrot_Context_info(Interp *interpreter,
     }
 
     /* make sure there is a sub (not always the case, e.g in pasm code) */
-    if (CONTEXT(ctx)->current_sub->vtable->base_type == enum_class_Undef ||
-           PMC_sub(CONTEXT(ctx)->current_sub)->address == 0) {
+    if (ctx->current_sub->vtable->base_type == enum_class_Undef ||
+           PMC_sub(ctx->current_sub)->address == 0) {
        /* XXX: is this correct? (try with load_bytecode) */
        /* use the current interpreter's bytecode as start address */
-       if (CONTEXT(ctx)->current_pc != NULL)
-           info->pc = CONTEXT(ctx)->current_pc - interpreter->code->base.data;
+       if (ctx->current_pc != NULL)
+           info->pc = ctx->current_pc - interpreter->code->base.data;
        return 1;
     }
 
     /* fetch struct Parrot_sub of the current sub in the given context */
-    if (!VTABLE_isa(interpreter, CONTEXT(ctx)->current_sub,
+    if (!VTABLE_isa(interpreter, ctx->current_sub,
                 const_string(interpreter, "Sub")))
         return 1;
 
-    sub = PMC_sub(CONTEXT(ctx)->current_sub);
+    sub = PMC_sub(ctx->current_sub);
     /* set the sub name */
     info->subname = sub->name;
 
@@ -357,14 +354,14 @@ Parrot_Context_info(Interp *interpreter,
     }
 
     /* return here if there is no current pc */
-    if (CONTEXT(ctx)->current_pc == NULL)
+    if (ctx->current_pc == NULL)
        return 1;
 
     /* calculate the current pc */
-    info->pc = CONTEXT(ctx)->current_pc - sub->seg->base.data;
+    info->pc = ctx->current_pc - sub->seg->base.data;
 
     /* determine the current source file/line */
-    if (CONTEXT(interpreter->ctx)->current_pc) {
+    if (ctx->current_pc) {
        size_t offs = info->pc;
        size_t i, n;
        /* XXX: interpreter->code->cur_cs is not correct, is it? */
@@ -394,7 +391,7 @@ STRING*
 Parrot_Context_infostr(Interp *interpreter, parrot_context_t *ctx)
 {
     struct Parrot_Context_info info;
-    const char* msg = (&interpreter->ctx == ctx) ?
+    const char* msg = (CONTEXT(interpreter->ctx) == ctx) ?
        "current instr.:":
        "called from Sub";
 

Modified: trunk/src/thread.c
==============================================================================
--- trunk/src/thread.c  (original)
+++ trunk/src/thread.c  Thu Oct 13 05:30:33 2005
@@ -118,7 +118,7 @@ pt_thread_prepare_for_run(Parrot_Interp 
      * are working - create it in the new interpreters mem space
      */
     ret_c = pmc_new(d, enum_class_RetContinuation);
-    PMC_cont(ret_c)->from_ctx = d->ctx;
+    PMC_cont(ret_c)->from_ctx = CONTEXT(d->ctx);
     INTERP_REG_PMC(d, 1) =      /* XXX remove when done pdd03 */
         CONTEXT(d->ctx)->current_cont = ret_c;
 }

Modified: trunk/src/warnings.c
==============================================================================
--- trunk/src/warnings.c        (original)
+++ trunk/src/warnings.c        Thu Oct 13 05:30:33 2005
@@ -34,7 +34,8 @@ Prints the bytecode location of the warn
 void
 print_pbc_location(Parrot_Interp inter)
 {
-    PIO_eprintf(inter, "%Ss", Parrot_Context_infostr(inter, &inter->ctx));
+    PIO_eprintf(inter, "%Ss",
+            Parrot_Context_infostr(inter, CONTEXT(inter->ctx)));
 }
 
 /*

Reply via email to