chromatic wrote:

now, the creation of Parrot::Coroutine becomes (r21929) :

     .local pmc coro
     .const .Sub coro_sub = "enumerate_tree"
     coro_class = get_class 'Parrot::Coroutine'
     coro = coro_class.'new'('initial_sub' => coro_sub)

So, how translate it in PMC ?

I think it's something like:

        STRING *name   = CONST_STRING(INTERP, "Parrot::Coroutine");
        PMC    *sub    = ... ;
        PMC    *_class = Parrot_oo_get_class_str(INTERP, name);
        PMC    *coro;

        if (PMC_IS_NULL(_class))
                real_exception(INTERP, ... );

        coro = VTABLE_instantiate(INTERP, _class, sub);

Aye, your best example to follow is the 'new' opcode defined in src/ops/pmc.ops, which is pretty much exactly that.

You will need to bundle up the 'sub' argument in a hash (the low-level equivalent of named arguments like 'initial_sub'). So, using your existing init_pmc, it'll be something like:

  void init_pmc(PMC* sub) {
    PMC *classobj = Parrot_oo_get_class_str(INTERP,
                         CONST_STRING(INTERP, "Parrot::Coroutine"));

    if (!PMC_IS_NULL(classobj)) {
        PMC *init_args = pmc_new(INTERP, enum_class_Hash);
        VTABLE_set_pmc_keyed_str(INTERP, init_args,
                            CONST_STRING(INTERP, "initial_sub"), sub);
        PMC_pmc_val(SELF) = VTABLE_instantiate(INTERP,
                                               classobj, init_args);
    }
    else
        real_exception(INTERP, NULL, E_Exception,
                       "Parrot::Coroutine not found");

  }

Allison

Reply via email to