classes/delegate.pmc - Delegate PMC


Delegate each and every function to parrot bytecode.

Almost all methods are auto-generated in lib/Parrot/

Register Save/Restore Functions ^

The following bit is a fast register save/restore pair. They currently count on the registers in the interpreter structure being in the same order as in the regsave struct, and that the registers are at the beginning of the interpreter structure.

Yes, it's damned evil, but it's what we need, since we have to preserve the registers -- vtable methods can't change them.

Also note that if the vtable method clobbers a register that contains a string or PMC not otherwise rooted it could be collected too early.

Functions ^

static PMC *find_meth(Interp *interpreter, PMC *pmc, STRING *name)

Finds and returns the delegated method with string name.

static PMC *find_or_die(Interp *interpreter, PMC *pmc, STRING *name)

Returns the result of calling find_meth() with the arguments, raising an exception if no method is found.

All these functions to run code can leak a full parrot register file, as well as potentially permanently unroot some PMCs or strings, if the vtable method throws an exception. It really ought be caught rather than let flow through.

PARROT_INLINE static void noarg_noreturn(Interp *interpreter, PMC *obj, const char *meth, int die)

Calls the delegated method with no arguments or return value. If die is true then an exception will be raised if the method is not found.

Methods ^

void init()

Calls the delegated __init() method if it exists.

PMC *instantiate()

Calls the delegated __instantiate method if it exists.

XXX Actually the PMC compiler should emit different code, if a method is present in classes/default.pmc. Some defaulted methods like this one have useful defaults and don't throw exceptions.