/*
Copyright (C) 2001-2010, Parrot Foundation.
$Id: parrotinterpreter.pmc 47541 2010-06-10 18:38:14Z NotFound $

=head1 NAME

src/pmc/parrotinterpreter.pmc - Parrot Interpreter

=head1 DESCRIPTION

These are the vtable functions for the ParrotInterpreter base class

   getinterp P0
   set P1, P0[.IGLOBALS_*]  # access interpreter globals
   set I0, P0[x]            # interpinfo I0, x
   set I0, P0[-1]           # get interpreter flags
   set P0[-1], x            # set flags on interpreter
                            # NOTE: this doesn't restart

=head2 Functions

=over 4

=cut

*/

#include "parrot/embed.h"
#include "parrot/dynext.h"
#include "parrot/io.h"
#include "parrot/runcore_api.h"
#include "pmc/pmc_class.h"
#include "pmc/pmc_sub.h"

#define PMC_interp(x) ((Parrot_ParrotInterpreter_attributes *)PMC_data(x))->interp
#define PMC_args(x)   ((Parrot_ParrotInterpreter_attributes *)PMC_data(x))->args
#define PMC_sub(x)    ((Parrot_ParrotInterpreter_attributes *)PMC_data(x))->sub

/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */

static void create_interp(
    ARGIN(PMC *self),
    ARGIN_NULLOK(Parrot_Interp parent))
        __attribute__nonnull__(1);

#define ASSERT_ARGS_create_interp __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
       PARROT_ASSERT_ARG(self))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
/* HEADERIZER END: static */

/*

=item C<void clone_interpreter(Parrot_Interp d, Parrot_Interp s, INTVAL flags)>

Clones the interpreter as specified by the flags.

=cut

*/

void
clone_interpreter(Parrot_Interp d, Parrot_Interp s, INTVAL flags)
{
    /* we block GC runs while cloning since C<d> is not yet running */
    Parrot_block_GC_mark(d);

    d->scheduler = Parrot_pmc_new(d, enum_class_Scheduler);
    d->scheduler = VTABLE_share_ro(d, d->scheduler);

    /* can't copy directly, unless you want double-frees */
    if (flags & PARROT_CLONE_RUNOPS)
        Parrot_runcore_switch(d, s->run_core->name);

    if (flags & PARROT_CLONE_INTERP_FLAGS) {
        /* XXX setting of IS_THREAD? */
        d->flags       = s->flags;
        d->debug_flags = s->debug_flags;
    }

    if (flags & PARROT_CLONE_HLL) {
        /* we'd like to share the HLL data. Give it a PMC_sync structure
           if it doesn't have one already */
        d->HLL_info = s->HLL_info;
        Parrot_regenerate_HLL_namespaces(d);
    }

    if (flags & (PARROT_CLONE_LIBRARIES | PARROT_CLONE_CLASSES)) {
        INTVAL i, last_remove;
        const INTVAL start = d->n_vtable_max;

        /* copy type registrations to keep type numbers the same */
        d->class_hash   = Parrot_clone(d, s->class_hash);
        d->n_vtable_max = s->n_vtable_max;

        if (d->n_vtable_max > d->n_vtable_alloced)
            parrot_realloc_vtables(d);

        last_remove = s->n_vtable_max;

        for (i = s->n_vtable_max - 1; i >= start; --i) {
            if (s->vtables[i] && s->vtables[i]->pmc_class &&
                PObj_is_class_TEST(s->vtables[i]->pmc_class)) {
                STRING * const class_name =
                    VTABLE_get_string(s, s->vtables[i]->pmc_class);
                PARROT_ASSERT(VTABLE_exists_keyed_str(d,
                    d->class_hash, class_name));

                VTABLE_delete_keyed_str(d, d->class_hash, class_name);

                if (last_remove == i + 1) {
                    --d->n_vtable_max;
                    last_remove = i;
                }
            }
        }
    }

    if (flags & PARROT_CLONE_LIBRARIES) {
        PMC   * const libs     = VTABLE_get_pmc_keyed_int(s, s->iglobals,
            IGLOBALS_DYN_LIBS);
        PMC   * const lib_iter = VTABLE_get_iter(s, libs);
        const INTVAL n         = VTABLE_elements(s, libs);
        INTVAL i;

        for (i = 0; i < n; ++i) {
            STRING * const key     = VTABLE_shift_string(s, lib_iter);
            PMC    * const lib_pmc = VTABLE_get_pmc_keyed_str(s, libs, key);
            PMC    * const ignored = Parrot_clone_lib_into(d, s, lib_pmc);
            UNUSED(ignored);
        }
    }

    if (flags & PARROT_CLONE_CLASSES) {
        INTVAL i;
        for (i = 0; i < s->n_vtable_max; ++i) {
            if (s->vtables[i] && s->vtables[i]->pmc_class &&
                    PObj_is_class_TEST(s->vtables[i]->pmc_class)) {
                /* Cloning the class into the new interpreter ought
                 * to be sufficient to instantiate the class.  */
                PMC                     * const source       = s->vtables[i]->pmc_class;
                PMC                     * const dest         = Parrot_clone(d, source);
                Parrot_Class_attributes * const source_class = PARROT_CLASS(source);
                Parrot_Class_attributes * const dest_class   = PARROT_CLASS(dest);

                dest_class->name           = source_class->name;
                dest_class->_namespace     = VTABLE_clone(d, source_class->_namespace);
            }
        }
    }

    if (flags & PARROT_CLONE_CODE)
        pt_clone_code(d, s);

    if (flags & PARROT_CLONE_GLOBALS)
        pt_clone_globals(d, s);

    Parrot_unblock_GC_mark(d);
}


/*

=item C<static void create_interp(PMC *self, Parrot_Interp parent)>

Creates a new child interpreter of C<parent>.

=cut

*/

static void
create_interp(ARGIN(PMC *self), ARGIN_NULLOK(Parrot_Interp parent))
{
    ASSERT_ARGS(create_interp)
    Interp_flags flag  = PARROT_NO_FLAGS;
    Parrot_Interp new_interp;

    if (self->vtable->base_type == enum_class_ParrotThread)
        flag = PARROT_IS_THREAD;

    new_interp       = make_interpreter(parent, (INTVAL)flag);
    PMC_interp(self) = new_interp;

    VTABLE_set_pmc_keyed_int(new_interp, new_interp->iglobals,
        (INTVAL) IGLOBALS_INTERPRETER, self);

    new_interp->current_cont = NEED_CONTINUATION;
}

pmclass ParrotInterpreter no_ro manual_attrs provides invokable {
    ATTR struct parrot_interp_t *interp; /* this PMC's interpreter */
    ATTR INTVAL                  tid;    /* thread id */
    ATTR PMC                    *args;   /* args passed to this thread */
    ATTR PMC                    *sub;    /* this thread's sub */

/*

=back

=head2 Methods

=over 4

=item C<yield>

Yield the current thread

=item C<recursion_limit(INTVAL l :optional, INTVAL has_l :opt_flag )>

Gets the recursion limit of the interpreter, optionally setting it to something
new.

=cut

*/

    METHOD yield() {
        pt_thread_yield();
    }

    METHOD recursion_limit(INTVAL l :optional, INTVAL has_l :opt_flag) {
        const INTVAL ret = INTERP->recursion_limit;
        if (has_l)
            INTERP->recursion_limit = l;
        RETURN(INTVAL ret);
    }

/*

=item C<void init()>

Initializes the interpreter.

=cut

*/

    VTABLE void init() {
        /*
         * init/init_pmc may be called internally (from thread creation in
         * ParrotThread::init_pmc() or stand-alone
         * so we check, if the interpreter is already set up
         */
        if (!PMC_data(SELF)) {
            Parrot_ParrotInterpreter_attributes * const attrs =
                mem_gc_allocate_zeroed_typed(INTERP, Parrot_ParrotInterpreter_attributes);
            PMC_data(SELF) = attrs;
        }
        if (!PMC_interp(SELF)) {
            create_interp(SELF, INTERP);
        }
        PObj_custom_destroy_SET(SELF);
    }

/*

=item C<void init_pmc(PMC *parent)>

Initializes a child interpreter with C<*parent> if C<parent> is
a ParrotInterpreter instance. Otherwise takes the thread ID from
C<parent> and uses that thread.

=cut

*/

    VTABLE void init_pmc(PMC *parent) {
        /* XXX Can this be moved inside the block where it's used */
        Parrot_Interp p = PMC_interp(parent);

        if (!PMC_data(SELF)) {
            Parrot_ParrotInterpreter_attributes * const attrs =
                mem_gc_allocate_zeroed_typed(INTERP, Parrot_ParrotInterpreter_attributes);
            PMC_data(SELF) = attrs;
        }
        if (!PMC_interp(SELF)) {
            create_interp(SELF, p);
        }
        PObj_custom_destroy_SET(SELF);
    }


/*

=item C<void destroy()>

Destroys the PMC.

=cut

*/

    VTABLE void destroy() {
        if (PMC_data(SELF)) {
            mem_gc_free(INTERP, PMC_data(SELF));
            PMC_data(SELF) = NULL;
        }
    }


/*

=item C<void set_pointer(void *value)>

Sets C<struct_val> to C<*value>.

=cut

*/

    VTABLE void set_pointer(void *value) {

        /* XXX: init_world in src/global_setup.c needs to create a
         * ParrotInterpreter through Parrot_pmc_new_noinit.  If this PMC hasn't been
         * initialized, cheat by initializing instead. */
        if (!PMC_data(SELF)) {
            Parrot_ParrotInterpreter_attributes * const attrs =
                mem_gc_allocate_zeroed_typed(INTERP, Parrot_ParrotInterpreter_attributes);
            PMC_data(SELF) = attrs;
            PObj_custom_destroy_SET(SELF);
        }
        PMC_interp(SELF) = (struct parrot_interp_t *)value;
    }

/*

=item C<void *get_pointer()>

Returns C<struct_val>.

=cut

*/

    VTABLE void *get_pointer() {
        return PMC_interp(SELF);
    }

/*

=item C<INTVAL get_integer()>

Returns the thread id of the interpreter.

=cut

*/

    VTABLE INTVAL get_integer() {
        const Parrot_Interp i = PMC_interp(SELF);
        if (i->thread_data)
          return (INTVAL)i->thread_data->tid;
        return 0;
    }

/*

=item C<opcode_t *invoke(void *next)>

Runs the interpreter's byte code.

=cut

*/

    VTABLE opcode_t *invoke(void *next) {
        Interp * const new_interp = PMC_interp(SELF);

        /* setup code */
        pt_thread_prepare_for_run(new_interp, INTERP);

        /* TODO pass arguments from parent (interp) to child (new_interp) by
         * possibly clone of share the arguments r/o args can be passed as is */

        /* calculate offset and run */
        runops(new_interp, (size_t)((opcode_t *)PMC_sub(SELF) -
            (opcode_t *)INTERP->code->base.data));

        return (opcode_t *)next;
    }

/*

=item C<PMC *get_pmc()>

Return this Thread's args.

=cut

*/

    VTABLE PMC *get_pmc() {
        return PMC_args(SELF);
    }

/*

=item C<void set_pmc(PMC *args)>

Set this Thread's args.

=cut

*/

    VTABLE void set_pmc(PMC *args) {
        PMC_args(SELF) = args;
    }


/*

=item C<PMC *get_pmc_keyed_int(INTVAL key)>

Returns the PMC global value for C<key>.

=cut

*/

    VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
        Interp * const new_interp = PMC_interp(SELF);

        if (key >= 0 && key < IGLOBALS_SIZE)
            return VTABLE_get_pmc_keyed_int(new_interp,
                new_interp->iglobals, key);

        /* quick hack to get the global stash */
        if (key == -1)
            return new_interp->root_namespace;

        return PMCNULL;
    }

/*

=item C<PMC *get_pmc_keyed(PMC *key)>

Introspection interface. C<key> can be:

  "context"                 ... return Context PMC
  "sub"                     ... return Sub object of this subroutine
  "continuation"            ... return Continuation PMC
  "lexpad"                  ... return lexpad PMC for this sub
  "namespace"               ... return namespace PMC for this sub
  "outer"                   ... return outer sub of this closure
  "<item>"; level           ... same for caller <level>
  "annotations"; level > 0  ... annotations at point of call <level>s down
  "outer"; "<item>"         ... same for outer level 1
  "outer"; "<item>"; level  ... same for outer <level>
  "globals"                 ... return global stash

=cut

*/

    VTABLE PMC *get_pmc_keyed(PMC *key) {
        PMC    *nextkey;
        STRING *outer = NULL;
        STRING *item  = key_string(INTERP, key);
        STRING *name  = CONST_STRING(INTERP, "globals");
        int     level = 0;

        PMC *ctx;

        if (Parrot_str_equal(INTERP, item, name))
            return INTERP->root_namespace;

        name  = CONST_STRING(INTERP, "outer");

        if (Parrot_str_equal(INTERP, item, name)) {
            outer   = item;
            nextkey = key_next(INTERP, key);

            if (nextkey && (PObj_get_FLAGS(nextkey) & KEY_string_FLAG)) {
                key  = nextkey;
                item = VTABLE_get_string(INTERP, key);
            }
        }

        nextkey = key_next(INTERP, key);

        if (nextkey)
            level = VTABLE_get_integer(INTERP, nextkey);
        else if (outer)
            level = 1;

        if (level < 0)
            Parrot_ex_throw_from_c_args(INTERP, NULL, CONTROL_ERROR,
                "No such caller depth");

        ctx = CURRENT_CONTEXT(INTERP);

        if (outer) {
            for (; level; --level) {
                ctx = Parrot_pcc_get_outer_ctx(INTERP, ctx);
                if (PMC_IS_NULL(ctx))
                    Parrot_ex_throw_from_c_args(INTERP, NULL,
                        CONTROL_ERROR, "No such outer depth");
            }
        }
        else {
            for (; level; --level) {
                PMC * const cont = Parrot_pcc_get_continuation(INTERP, ctx);

                if (PMC_IS_NULL(cont) || !PARROT_CONTINUATION(cont)->seg)
                    Parrot_ex_throw_from_c_args(INTERP, NULL,
                        CONTROL_ERROR, "No such caller depth");

                ctx = PARROT_CONTINUATION(cont)->to_ctx;

                if (PMC_IS_NULL(Parrot_pcc_get_sub(INTERP, ctx)))
                    Parrot_ex_throw_from_c_args(INTERP, NULL,
                        CONTROL_ERROR, "No such caller depth");
            }
        }

        if (item == outer)
            return Parrot_pcc_get_sub(INTERP, ctx);

        name = CONST_STRING(INTERP, "context");

        if (Parrot_str_equal(INTERP, item, name))
            return ctx;

        name = CONST_STRING(INTERP, "sub");

        if (Parrot_str_equal(INTERP, item, name))
            return Parrot_pcc_get_sub(INTERP, ctx);

        name = CONST_STRING(INTERP, "lexpad");

        if (Parrot_str_equal(INTERP, item, name))
            return Parrot_pcc_get_lex_pad(INTERP, ctx);

        name = CONST_STRING(INTERP, "namespace");

        if (Parrot_str_equal(INTERP, item, name))
            return Parrot_pcc_get_namespace(INTERP, ctx);

        name = CONST_STRING(INTERP, "continuation");

        if (Parrot_str_equal(INTERP, item, name))
            return VTABLE_clone(INTERP, Parrot_pcc_get_continuation(INTERP, ctx));

        name = CONST_STRING(INTERP, "annotations");

        if (Parrot_str_equal(INTERP, item, name)) {
            PMC        *sub_pmc = Parrot_pcc_get_sub(INTERP, ctx);
            if (ctx == CURRENT_CONTEXT(INTERP)) {
                /* We can't know the current program counter for the currently
                 * executing sub, so can't return annotations for that. */
                Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
                        "Cannot get annotations at depth 0; use annotations op instead.");
            }
            if (!PMC_IS_NULL(sub_pmc)
            &&   sub_pmc->vtable->base_type == enum_class_Sub) {
                Parrot_Sub_attributes *sub;
                PackFile_ByteCode     *seg;
                opcode_t              *pc  = Parrot_pcc_get_pc(INTERP, ctx);

                PMC_get_sub(INTERP, sub_pmc, sub);
                seg = sub->seg;

                if (sub->seg->annotations)
                    return PackFile_Annotations_lookup(INTERP, seg->annotations,
                        pc - seg->base.data, NULL);
            }

            return Parrot_pmc_new(INTERP, enum_class_Hash);
        }

        Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
                "No such item %Ss", item);
    }

/*

=item C<INTVAL get_integer_keyed_int(INTVAL key)>

Returns the interpreter info for C<key>.

=cut

*/

    VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
        Interp * const new_interp = PMC_interp(SELF);

        if (key == -1)
            return (INTVAL)new_interp->flags;

        return interpinfo(new_interp, key);
    }

/*

=item C<void set_integer_keyed_int(INTVAL key, INTVAL val)>

Sets the interpreter info for C<key> to C<val>.

=cut

*/

    VTABLE void set_integer_keyed_int(INTVAL key, INTVAL val) {
        Interp * const new_interp = PMC_interp(SELF);

        /* set interpreter flags */
        if (key == -1) {
            const INTVAL allowed = PARROT_BOUNDS_FLAG | PARROT_PROFILE_FLAG |
                             PARROT_GC_DEBUG_FLAG;
            Parrot_clear_flag(new_interp, allowed);
            Parrot_set_flag(new_interp, val & allowed);
        }
    }

/*

=item C<PMC *clone()>

First attempt to make things running, and to see, where problems may
arise. Only minimal items are done yet.

XXX this should of course call C<Parrot_clone()> and use freeze/thaw.

=cut

*/

    VTABLE PMC *clone() {
        PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);

        clone_interpreter(PMC_interp(dest),
                          PMC_interp(SELF), PARROT_CLONE_DEFAULT);

        return dest;
    }

/*

=item C<INTVAL is_equal(PMC *val)>

Returns whether the interpreter is equal to C<*val>.

Two interpreters (threads) are equal if both are non-threaded or they
have the same thread id.

=cut

*/

    MULTI INTVAL is_equal(ParrotInterpreter val) {
        Parrot_Interp self  = PMC_interp(SELF);
        Parrot_Interp other = PMC_interp(val);

        if (!self->thread_data && !other->thread_data)
            return 1;

        if (self->thread_data && other->thread_data &&
            self->thread_data->tid == other->thread_data->tid)
            return 1;

        return 0;
    }

    MULTI INTVAL is_equal(ParrotThread value) {
        Parrot_Interp self  = PMC_interp(SELF);

        if (!self->thread_data)
            return 0;

        return self->thread_data->tid == (UINTVAL) VTABLE_get_integer(INTERP, value);
    }

    MULTI INTVAL is_equal(DEFAULT value) {
        Parrot_ex_throw_from_c_args(INTERP, NULL,
                EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
                "ParrotInterpreter: no multiple dispatch variant 'is_equal' for %Ss",
                VTABLE_name(INTERP, value));
    }

/*

=item C<void visit(PMC *info)>

This is used by freeze/thaw to visit the contents of the interpreter.

C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).

=item C<void freeze(PMC *info)>

Used to archive the interpreter. Actually not the whole interpreter is
frozen but the state of the interpreter, which includes everything that
has changes since creating an empty interpreter.

=item C<void thaw(PMC *info)>

Used to unarchive the interpreter. This merges the changes into this
interpreter instance.

=item C<void thawfinish(PMC *info)>

Finish thawing.

=cut

*/

    VTABLE void visit(PMC *info) {
        /*
         * the information frozen here is part of all PBCs
         * we probably need to freeze all dynamic extensible
         * mappings (or at least the dynamic part)
         * e.g.
         *    charsets   idx - name
         *    encodings  idx - name
         *    pmc types  idx - name
         *    dynamic oplibs    opcode nr - opname
         *
         * The machine thawing this info still needs to load
         * these extensions, but the order of loading could be
         * relaxed.
         *
         * creating all these info as standard PMCs would vastly
         * simplify this process
         *
         * thaw would then need a merge operation:
         *  - compare existing for sanity
         *  - extend new
         */

        /*  HLL_info */
        if (VTABLE_get_integer(INTERP, info) == VISIT_THAW_NORMAL ||
            VTABLE_get_integer(INTERP, info) == VISIT_THAW_CONSTANTS) {
            VISIT_PMC(INTERP, info, PMC_args(SELF));
        }
        else
            VISIT_PMC(INTERP, info, INTERP->HLL_info);

    }

    VTABLE void thaw(PMC *info) {
        if (!PMC_data(SELF)) {
            Parrot_ParrotInterpreter_attributes * const attrs =
                mem_gc_allocate_zeroed_typed(INTERP, Parrot_ParrotInterpreter_attributes);
            PMC_data(SELF) = attrs;
            PObj_custom_destroy_SET(SELF);
        }

        PMC_interp(SELF) = INTERP;
    }

    VTABLE void thawfinish(PMC *info) {
        PMC * const new_info = PMC_args(SELF);
        const INTVAL  m      = VTABLE_elements(INTERP, new_info);
        INTVAL  i;
        UNUSED(info)

        PMC_args(SELF) = NULL;

        /* merge new_info */
        /* TODO compare old entries */

        for (i = 0; i < m; ++i) {
            PMC * const entry    = VTABLE_get_pmc_keyed_int(INTERP, new_info, i);
            PMC * const lib_pmc  = VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_lib);
            PMC * const name_pmc = VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_name);
            PMC * const typemap  = VTABLE_get_pmc_keyed_int(INTERP, entry, e_HLL_typemap);
            INTVAL hll_id = - 1;

            if (!PMC_IS_NULL(name_pmc)) {
                STRING * const hll_name = VTABLE_get_string(INTERP, name_pmc);

                hll_id           = Parrot_register_HLL(INTERP, hll_name);
            }

            if (!PMC_IS_NULL(lib_pmc)) {
                STRING * const lib_name = VTABLE_get_string(INTERP, lib_pmc);

                if (!STRING_IS_EMPTY(lib_name)) {
                    PMC * const ignored = Parrot_load_lib(INTERP, lib_name, NULL);
                    const INTVAL id     = Parrot_register_HLL_lib(INTERP, lib_name);
                    UNUSED(id);
                }
            }

            if (hll_id >= 0 && !PMC_IS_NULL(typemap)) {
                PMC   * const iter = VTABLE_get_iter(INTERP, typemap);
                const INTVAL e     = VTABLE_get_integer(INTERP, typemap);
                INTVAL i;

                for (i = 0; i < e; ++i) {
                    PMC * const key        = VTABLE_shift_pmc(INTERP, iter);
                    const INTVAL core_type = VTABLE_get_integer(INTERP, key);
                    const INTVAL hll_type  =
                        VTABLE_get_integer_keyed_int(INTERP, typemap, core_type);

                    Parrot_register_HLL_type(INTERP, hll_id,
                        core_type, hll_type);
                }
            }
        }
    }

    METHOD run_gc() {
        Parrot_gc_mark_and_sweep(PMC_interp(SELF), 0);
    }

/*

=item METHOD hll_map(PMC core_type,PMC hll_type)

Map core_type to hll_type.

=cut

*/

    METHOD hll_map(PMC *core_type, PMC *hll_type) {
        const INTVAL core_type_id = VTABLE_type(INTERP, core_type);
        const INTVAL hll_type_id  = VTABLE_type(INTERP, hll_type);
        const INTVAL hll_id       = Parrot_pcc_get_HLL(INTERP, CURRENT_CONTEXT(INTERP));
        Parrot_register_HLL_type(INTERP, hll_id, core_type_id, hll_type_id);
    }

/*

=item METHOD stdhandle(INTVAL fileno, PMC *newhandle :optional)

Returns the standard parrot handler associated with the interpreter.
The valid values for fileno are listed in include/stdio.pasm

Optionally sets the parrot handler passed as second argument
as the specified standard handler.

This method is experimental. See TT #264.

=cut

*/

    METHOD stdhandle(INTVAL fileno, PMC *newhandle :optional) {
        PMC * const handle = Parrot_io_stdhandle(INTERP, fileno, newhandle);
        Parrot_warn_deprecated(INTERP, "stdhandle method is experimental");
        RETURN(PMC *handle);
    }


}

/*

=back

=cut

*/

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
