Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 869 lines (590 sloc) 22.126 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
/*
Copyright (C) 2001-2012, Parrot Foundation.

=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/dynext.h"
#include "parrot/io.h"
#include "parrot/runcore_api.h"
#include "parrot/thread.h"
#include "pmc/pmc_class.h"
#include "pmc/pmc_sub.h"
#include "pmc/pmc_proxy.h"
#include "pmc/pmc_task.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<PMC * clone_interpreter(Parrot_Interp s, INTVAL flags)>

Clones the interpreter as specified by the flags.

TODO: Move this logic into src/interp/api.c or src/threads.c, as appropriate

=cut

*/

PARROT_CANNOT_RETURN_NULL
PMC *
clone_interpreter(Parrot_Interp s, INTVAL flags)
{
    /* have to pass a parent to allocate_interpreter to prevent PMCNULL from being set to NULL */
    Parrot_Interp d = Parrot_interp_allocate_interpreter(s, flags);
    int stacktop;
    Parrot_GC_Init_Args args;

    PMC * interp_pmc;
    PMC * const s_config_hash = VTABLE_get_pmc_keyed_int(s, s->iglobals, IGLOBALS_CONFIG_HASH);

    memset(&args, 0, sizeof (args));
    args.stacktop = &stacktop;

    /* Set up the memory allocation system */
    Parrot_gc_initialize(d, &args);
    Parrot_block_GC_mark(d);
    Parrot_block_GC_sweep(d);

    d->ctx = PMCNULL;
    d->resume_flag = RESUME_INITIAL;

    d->recursion_limit = RECURSION_LIMIT;

    /* PANIC will fail until this is done */
    d->piodata = NULL;
    Parrot_io_init(d);

    /*
     * Set up the string subsystem
     * This also generates the constant string tables
     * Do this before unsetting parent_interpreter to copy its hash_seed and constant string table
     */
    Parrot_str_init(d);

    /* create caches structure */
    init_object_cache(d);

    d->n_vtable_max = s->n_vtable_max;
    d->vtables = s->vtables;
    d->class_hash = Parrot_thread_create_proxy(s, d, s->class_hash);

    Parrot_cx_init_scheduler(d);

    d->parent_interpreter = NULL;

    /* create the root set registry */
    d->gc_registry = Parrot_pmc_new(d, enum_class_AddrRegistry);

    interp_pmc = Parrot_pmc_new_noinit(d, enum_class_ParrotInterpreter);
    VTABLE_set_pointer(d, interp_pmc, d);

    /* init the interpreter globals array */
    d->iglobals = Parrot_pmc_new_init_int(d, enum_class_FixedPMCArray, (INTVAL)IGLOBALS_SIZE);

    VTABLE_set_pmc_keyed_int(d, d->iglobals, (INTVAL) IGLOBALS_INTERPRETER, interp_pmc);

    /* initialize built-in runcores */
    Parrot_runcore_init(d);

    /* create a proxy for the config_hash */
    VTABLE_set_pmc_keyed_int(d, d->iglobals, (INTVAL) IGLOBALS_CONFIG_HASH,
        Parrot_thread_create_proxy(s, d, s_config_hash));

    /* 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;
    }

    d->root_namespace = Parrot_thread_create_proxy(s, d, s->root_namespace);

    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 */

        /* This used to be proxied:

            d->HLL_info = Parrot_thread_create_proxy(s, d, s->HLL_info);

            But src/hll.c:Parrot_hll_get_HLL_type() pokes directly into the
            PMC attributes which is a problem if we're using a Proxy. Instead,
            clone the structure so direct accesses continue working.
        */
        d->HLL_info = VTABLE_clone(d, s->HLL_info);
        d->HLL_namespace = Parrot_thread_create_proxy(s, d, s->HLL_namespace);
        d->HLL_entries = Parrot_thread_create_proxy(s, d, s->HLL_entries);
    }

    if (flags & (PARROT_CLONE_LIBRARIES | PARROT_CLONE_CLASSES)) {
    }

    if (flags & PARROT_CLONE_LIBRARIES) {
        PMC * const s_pbc_libs = VTABLE_get_pmc_keyed_int(s, s->iglobals, IGLOBALS_PBC_LIBS);
        VTABLE_set_pmc_keyed_int(d, d->iglobals, (INTVAL) IGLOBALS_PBC_LIBS,
            Parrot_thread_create_proxy(s, d, s_pbc_libs));
    }

    create_initial_context(d);

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

    /* setup stdio PMCs */
    Parrot_io_init(d);

    Parrot_unblock_GC_sweep(d);
    Parrot_unblock_GC_mark(d);

    return interp_pmc;
}


/*

=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;

    new_interp = Parrot_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);
}

pmclass ParrotInterpreter no_ro manual_attrs provides invokable {
    ATTR struct parrot_interp_t *interp; /* this PMC's interpreter */
    ATTR INTVAL tid; /* thread id. Unused, see get_integer() */
    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 recursion_limit(INTVAL l :optional, INTVAL has_l :opt_flag) {
        const INTVAL ret = INTERP->recursion_limit;
        UNUSED(SELF)
        if (has_l)
            INTERP->recursion_limit = l;
        RETURN(INTVAL ret);
    }

/*

=item C<void init()>

Initializes the interpreter.

=cut

*/

    VTABLE void init() {
        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) {
        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, PMC_interp(parent));
        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() {
        UNUSED(INTERP)
        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);
        UNUSED(INTERP)
        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);

        /* 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() {
        UNUSED(INTERP)
        return PMC_args(SELF);
    }

/*

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

Set this Thread's args.

=cut

*/

    VTABLE void set_pmc(PMC *args) {
        UNUSED(INTERP)
        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) {
        UNUSED(INTERP)
        Interp * const new_interp = PMC_interp(SELF);

        if (key >= 0 && key < IGLOBALS_SIZE) {
            PMC * const val = VTABLE_get_pmc_keyed_int(new_interp,
                    new_interp->iglobals, key);
            return val == NULL ? PMCNULL : val;
        }

        /* 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) {
        UNUSED(SELF)
        PMC *nextkey;
        STRING *outer = NULL;
        STRING *item = Parrot_key_string(INTERP, key);
        int level = 0;

        PMC *ctx;

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "globals")))
            return INTERP->root_namespace;

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "packfile")))
            return Parrot_pf_get_current_packfile(INTERP);

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "outer"))) {
            outer = item;
            nextkey = Parrot_key_next(INTERP, key);

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

        nextkey = Parrot_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, EXCEPTION_INVALID_OPERATION,
                "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,
                        EXCEPTION_INVALID_OPERATION, "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,
                        EXCEPTION_INVALID_OPERATION, "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,
                        EXCEPTION_INVALID_OPERATION, "No such caller depth");
            }
        }

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

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "context")))
            return ctx;

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "sub")))
            return Parrot_pcc_get_sub(INTERP, ctx);

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "lexpad")))
            return Parrot_pcc_get_lex_pad(INTERP, ctx);

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "namespace")))
            return Parrot_pcc_get_namespace(INTERP, ctx);

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "continuation")))
            return VTABLE_clone(INTERP, Parrot_pcc_get_continuation(INTERP, ctx));

        if (STRING_equal(INTERP, item, CONST_STRING(INTERP, "annotations"))) {
            PMC * const 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 * const 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) {
        UNUSED(INTERP)
        Interp * const new_interp = PMC_interp(SELF);

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

        return Parrot_interp_info(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) {
        UNUSED(INTERP)
        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_interp_clear_flag(new_interp, allowed);
            Parrot_interp_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() {
        UNUSED(INTERP)
        PMC * const dest = clone_interpreter(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) {
        UNUSED(INTERP)
        Parrot_Interp self = PMC_interp(SELF);
        Parrot_Interp other = PMC_interp(val);
        return self == other;
    }

    MULTI INTVAL is_equal(DEFAULT value) {
        UNUSED(SELF)
        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 freeze(PMC *info) {
        UNUSED(SELF)
        UNUSED(info)
        Parrot_ex_throw_from_c_args(INTERP, NULL, 0,
                "Attempt to freeze interpreter");
    }

    METHOD run_gc() {
        UNUSED(INTERP)
        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));
        UNUSED(SELF)
        Parrot_hll_register_HLL_type(INTERP, hll_id, core_type_id, hll_type_id);
    }

/*

=item METHOD stdin_handle(PMC *newhandle :optional)

If a PMC object is provided, the standard input handle for this interpreter
is set to that PMC, and the new PMC handle is returned.

If no PMC object is provided, the current standard input handle is returned.

=cut

*/

    METHOD stdin_handle(PMC *newhandle :optional) {
        PMC * const handle = Parrot_io_stdhandle(INTERP, PIO_STDIN_FILENO, newhandle);
        UNUSED(SELF)
        RETURN(PMC *handle);
    }

/*

=item METHOD stdout_handle(PMC *newhandle :optional)

If a PMC object is provided, the standard output handle for this interpreter
is set to that PMC, and the new PMC handle is returned.

If no PMC object is provided, the current standard output handle is returned.

=cut

*/

    METHOD stdout_handle(PMC *newhandle :optional) {
        PMC * const handle = Parrot_io_stdhandle(INTERP, PIO_STDOUT_FILENO, newhandle);
        RETURN(PMC *handle);
    }

/*

=item METHOD stderr_handle(PMC *newhandle :optional)

If a PMC object is provided, the standard error handle for this interpreter
is set to that PMC, and the new PMC handle is returned.

If no PMC object is provided, the current standard error handle is returned.

=cut

*/

    METHOD stderr_handle(PMC *newhandle :optional) {
        PMC * const handle = Parrot_io_stdhandle(INTERP, PIO_STDERR_FILENO, newhandle);
        RETURN(PMC *handle);
    }

/*

=item METHOD getpid()

Returns the pid of the current process, 0 in platforms that doesn't
support it.

=cut

*/

    METHOD getpid() {
        const INTVAL id = Parrot_getpid();
        RETURN(INTVAL id);
    }

/*

=item METHOD current_task()

Returns the task currently executed by this interpreter.

=cut

*/

    METHOD current_task() {
        Interp * const this_interp = PMC_interp(SELF);
        PMC * const current_task = this_interp->cur_task;
        RETURN(PMC *current_task);
    }

/*

=item METHOD schedule(PMC *task)

Schedules the given task on this interpreter.

=cut

*/

    METHOD schedule(PMC *task) {
        Interp * const this_interp = PMC_interp(SELF);
        Parrot_cx_schedule_immediate(this_interp, task);
    }

/*

=item METHOD schedule_proxied(PMC *task, PMC *proxy)

Schedules the given task on the proxy's interpreter.

=cut

*/

    METHOD schedule_proxied(PMC *task, PMC *proxy) {
        Parrot_Proxy_attributes * const core_struct = PARROT_PROXY(proxy);
        Interp * const proxied_interp = core_struct->interp;
        UNUSED(SELF)

#ifdef PARROT_HAS_THREADS
        /* don't run GC from the wrong thread since GC involves stack walking and we
         * don't want the foreign GC to find our objects */
        Parrot_block_GC_mark_locked(proxied_interp);

        Parrot_cx_schedule_immediate(proxied_interp,
            Parrot_thread_create_local_task(INTERP, proxied_interp, task));

        Parrot_unblock_GC_mark_locked(proxied_interp);
#else
        Parrot_cx_schedule_immediate(interp, task);
#endif
    }

}

/*

=back

=cut

*/

/*
 * Local variables:
 * c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
 */
Something went wrong with that request. Please try again.