Since I'm monkeying around in the relevant code anyway, this might be
a good task for the next calling_conventions branch. Or, if you
prefer, we could create a second branch for this conversion and do the
work there.

--Andrew Whitworth

On Sun, Nov 16, 2008 at 2:02 AM, via RT Allison Randal
<[EMAIL PROTECTED]> wrote:
> # New Ticket Created by  Allison Randal
> # Please include the string:  [perl #60564]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60564 >
>
>
> This ticket contains the partial conversion of contexts to PMCs that I
> did at YAPC::NA 2008. We found a quicker solution to the immediate
> problem, but this is still a change we'd like to make.
>
> - The patch probably won't apply cleanly (we've removed some code since
> then).
> - The patch itself includes merge conflicts in 3 files, should be easily
> resolved (I ran the diff on an old checkout of a branch that doesn't
> exist anymore).
> - The Context PMC is pretty far along, needs some more work.
> - The conversions from direct struct access to indirect access through a
> macro are right, but many more of these conversions need to be made.
>
> Allison
>
> /*
> Copyright (C) 2008, The Perl Foundation.
> $Id: parrotcontext.pmc 27598 2008-05-17 19:37:56Z allison $
>
> =head1 NAME
>
> src/pmc/parrotcontext.pmc - Context
>
> =head1 DESCRIPTION
>
> This class implements the Context PMC, a core PMC used to represent an
> execution context.
>
>
> =head2 Structure
>
> The Context PMC structure (C<Parrot_Context>) consists of five items:
>
> =over 4
>
> =item C<one>
>
> =back
>
> =cut
>
> */
>
> #include "parrot/parrot.h"
>
> /*
>
> =head2 Functions
>
> =over 4
>
> =cut
>
> */
>
> pmclass Context need_ext {
>
>    /* common header with Interp_Context */
>    ATTR PMC          *caller_ctx;    /* caller context */
>    ATTR Regs_ni       bp;            /* pointers to FLOATVAL & INTVAL */
>    ATTR Regs_ps       bp_ps;         /* pointers to PMC & STR */
>    /* end common header */
>    ATTR INTVAL       *n_regs_used;   /* INSP in PBC points to Sub */
>    ATTR size_t        regs_mem_size; /* memory occupied by registers */
>    ATTR void         *regs_mem;      /* a pointer to the allocated register 
> memory */
>    ATTR int           ref_count;     /* how often refered to [deprecated]*/
>
>    ATTR PMC          *lex_pad;       /* LexPad PMC */
>    ATTR PMC          *outer_ctx;     /* outer context, if a closure */
>    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 */
>    /*
>     * new call scheme and introspective variables
>     */
>    ATTR PMC          *current_sub;     /* the Sub we are executing */
>    /*
>     * for now use a return continuation PMC
>     */
>    ATTR PMC          *current_cont;    /* the return continuation PMC */
>    ATTR PMC          *current_object;  /* current object if a method call */
>    ATTR opcode_t     *current_pc;      /* program counter of Sub invocation */
>    ATTR PMC          *current_namespace; /* The namespace we're currently in 
> */
>    ATTR INTVAL        current_HLL;     /* see also src/hll.c */
>    ATTR opcode_t     *current_results; /* ptr into code with get_results 
> opcode */
>    ATTR PMC          *results_signature; /* results signature pmc if it is 
> non-const */
>    ATTR PMC          *handlers;        /* local handlers for the context */
>    /* deref the constants - we need it all the time */
>    ATTR struct PackFile_Constant ** constants;
>    /* code->prederefed.code - code->base.data in opcodes
>     * to simplify conversio between code ptrs in e.g. invoke
>     */
>    ATTR size_t pred_offset;
>
> /*
>
> =item C<void init()>
>
> Initializes a Context PMC.
>
> =cut
>
> */
>
>    VTABLE void init() {
>        Parrot_Context * const ctx_struct = 
> mem_allocate_zeroed_typed(Parrot_Context);
>
>        /* Set flags for custom DOD mark and destroy. */
>        PObj_custom_mark_SET(SELF);
>        PObj_active_destroy_SET(SELF);
>
>        /* Set up the context. */
>        PMC_data(SELF)         = ctx_struct;
>        ctx_struct->ref_count         = 0;
>        ctx_struct->current_HLL       = 0;
>        ctx_struct->current_results   = NULL;
>        ctx_struct->results_signature = NULL;
>        ctx_struct->regs_mem          = NULL;
>        ctx_struct->caller_ctx        = PMCNULL;
>        ctx_struct->outer_ctx         = PMCNULL;
>        ctx_struct->lex_pad           = PMCNULL;
>        ctx_struct->current_sub       = PMCNULL;
>        ctx_struct->current_cont      = PMCNULL;
>        ctx_struct->current_object    = PMCNULL;
>        ctx_struct->current_namespace = PMCNULL;
>        ctx_struct->results_signature = PMCNULL;
>        ctx_struct->handlers          = PMCNULL;
>    }
>
> /*
>
> =item C<void set_pointer(void *value)>
>
> Sets C<struct_val> to C<*value>.
>
> =cut
>
> */
>
>    VTABLE void set_pointer(void *num_regs_used) {
>        Parrot_alloc_context_registers(interp, SELF, (INTVAL *)num_regs_used);
>    }
>
> /*
>
> =item C<void destroy()>
>
> Free the memory associated with the object's underlying struct.
>
> =cut
>
> */
>
>    VTABLE void destroy() {
>        Parrot_Context *context = PARROT_CONTEXT(SELF);
>
>        if (context->n_regs_used)
>            mem_sys_free(context->n_regs_used);
>
>        if (context->regs_mem)
>            mem_sys_free(context->regs_mem);
>
>        mem_sys_free(context);
>    }
>
> /*
>
> =item C<void mark()>
>
> Mark referenced strings and PMCs in the structure as live.
>
> =cut
>
> */
>
>    VTABLE void mark() {
>        Parrot_Context * const ctx_struct = PARROT_CONTEXT(SELF);
>
>        if (ctx_struct->current_sub)
>            pobject_lives(interp, (PObj *)ctx_struct->current_sub);
>        if (ctx_struct->current_object)
>            pobject_lives(interp, (PObj *)ctx_struct->current_object);
>
>        /* the current continuation in the interpreter has
>         * to be marked too in the call sequence currently
>         * as e.g. a MMD search could need resources
>         * and GC the continuation
>         */
>        if (interp->current_cont) {
>            PObj *cont_obj = (PObj *)interp->current_cont;
>            if (cont_obj != (PObj *)NEED_CONTINUATION)
>                pobject_lives(interp, cont_obj);
>        }
>
>        if (ctx_struct->current_cont)
>            pobject_lives(interp, (PObj *)ctx_struct->current_cont);
>
>        if (ctx_struct->caller_ctx)
>            pobject_lives(interp, (PObj *)ctx_struct->caller_ctx);
>
>        if (ctx_struct->current_namespace)
>            pobject_lives(interp, (PObj *)ctx_struct->current_namespace);
>
>        if (ctx_struct->lex_pad)
>            pobject_lives(interp, (PObj *)ctx_struct->lex_pad);
>
>        if (ctx_struct->results_signature)
>            pobject_lives(interp, (PObj *)ctx_struct->results_signature);
>
>        if (ctx_struct->handlers)
>            pobject_lives(interp, (PObj *)ctx_struct->handlers);
>
>
>        if (!ctx_struct->n_regs_used)
>            return;
>
>        for (i = 0; i < ctx_struct->n_regs_used[REGNO_PMC]; ++i) {
>            obj = (PObj *)CTX_REG_PMC(ctx, i);
>            if (obj)
>                pobject_lives(interp, obj);
>        }
>
>        for (i = 0; i < ctx_struct->n_regs_used[REGNO_STR]; ++i) {
>            obj = (PObj *)CTX_REG_STR(ctx, i);
>            if (obj)
>                pobject_lives(interp, obj);
>        }
>    }
>
> /*
>
> =item C<PMC *clone()>
>
> Creates and returns a clone of the context.
>
> =cut
>
> */
>
>    VTABLE PMC *clone() {
>        PMC * const cloned = pmc_new(INTERP, SELF->vtable->base_type);
>        Parrot_Context *cloned_struct, *old_struct;
>        old_struct    = PARROT_CONTEXT(SELF);
>        cloned_struct = PARROT_CONTEXT(cloned);
>
>        /* some items should better be COW copied */
>        cloned_struct->constants         = old_struct->constants;
>        cloned_struct->warns             = old_struct->warns;
>        cloned_struct->errors            = old_struct->errors;
>        cloned_struct->trace_flags       = old_struct->trace_flags;
>        cloned_struct->pred_offset       = old_struct->pred_offset;
>        cloned_struct->current_HLL       = old_struct->current_HLL;
>        cloned_struct->current_namespace = old_struct->current_namespace;
>             /* end COW */
>        cloned_struct->recursion_depth   = old_struct->recursion_depth;
>
>        Parrot_alloc_context_registers(interp, cloned, 
> old_struct->n_regs_used);
>
>        return cloned;
>    }
>
>
> } /* end pmclass Context */
>
>
> /*
>
> =back
>
> =cut
>
> */
>
> /*
>  * Local variables:
>  *   c-file-style: "parrot"
>  * End:
>  * vim: expandtab shiftwidth=4:
>  */
>
>

Reply via email to