Author: leo
Date: Fri Mar 10 02:48:09 2006
New Revision: 11850

Modified:
   trunk/include/parrot/register.h
   trunk/src/register.c

Log:
PBC, context handling - 1

* create new API Parrot_{push,pop}_context
* will be used during compilation of code so that state changes during
  compiling don't effect the running program


Modified: trunk/include/parrot/register.h
==============================================================================
--- trunk/include/parrot/register.h     (original)
+++ trunk/include/parrot/register.h     Fri Mar 10 02:48:09 2006
@@ -74,8 +74,11 @@
 PARROT_API void Parrot_clear_n(Interp *);
 
 struct Parrot_Context;        /* parrot/interpreter.h */
+
 struct Parrot_Context * Parrot_alloc_context(Interp *, INTVAL *n_regs_used);
 struct Parrot_Context * Parrot_dup_context(Interp *, struct Parrot_Context 
*old);
+struct Parrot_Context * Parrot_push_context(Interp *, INTVAL *n_regs_used);
+void   Parrot_pop_context(Interp *);
 PARROT_API void Parrot_free_context(Interp *, struct Parrot_Context *, int 
re_use);
 PARROT_API void Parrot_set_context_threshold(Interp *, struct Parrot_Context 
*);
 void parrot_gc_context(Interp *);

Modified: trunk/src/register.c
==============================================================================
--- trunk/src/register.c        (original)
+++ trunk/src/register.c        Fri Mar 10 02:48:09 2006
@@ -145,6 +145,11 @@
 usage C<n_regs_used> is not copied, just the pointer is stored.
 The function returns the new context.
 
+=item C<parrot_context_t* Parrot_push_context(Interp *, INTVAL *n_regs_used)>
+
+Like above, remember old context in C<caller_ctx>, suitable to use with
+C<Parrot_pop_context>.
+
 =item C<parrot_context_t* Parrot_dup_context(Interp *, parrot_context_t*)>
 
 Like above but duplicate the passed context.
@@ -158,6 +163,11 @@
 Free the context. If C<re_use> is true, this function is called by a
 return continuation invoke, else from the destructur of a continuation.
 
+=item C<void Parrot_pop_context(Interp *)>
+
+Free the context created with C<Parrot_push_context> and restore the previous
+context.
+
 =cut
 
 */
@@ -241,6 +251,7 @@
         ctx->trace_flags = old->trace_flags;
         ctx->runloop_level = old->runloop_level;
        ctx->pred_offset = old->pred_offset;
+        ctx->current_HLL = old->current_HLL;
         /* end COW */
         ctx->recursion_depth = old->recursion_depth;
     }
@@ -277,6 +288,31 @@
 }
 
 struct Parrot_Context *
+Parrot_push_context(Interp *interpreter, INTVAL *n_regs_used)
+{
+    struct Parrot_Context *old, *ctx;
+
+    old = CONTEXT(interpreter->ctx);
+    ctx = Parrot_alloc_context(interpreter, n_regs_used);
+    ctx->caller_ctx = old;
+    return ctx;
+}
+
+void
+Parrot_pop_context(Interp *interpreter)
+{
+    struct Parrot_Context *old, *ctx;
+    ctx = CONTEXT(interpreter->ctx);
+    old = ctx->caller_ctx;
+
+    Parrot_free_context(interpreter, ctx, 1);
+    /* restore old, set cached interpreter base pointers */
+    CONTEXT(interpreter->ctx) = old;
+    interpreter->ctx.bp = old->bp;
+    interpreter->ctx.bp_ps = old->bp_ps;
+}
+
+struct Parrot_Context *
 Parrot_alloc_context(Interp *interpreter, INTVAL *n_regs_used)
 {
     struct Parrot_Context *old, *ctx;

Reply via email to