|parrotcode: Multimethod dispatch for binary opcode functions|
|Contents | C|
src/mmd.c - Multimethod dispatch for binary opcode functions
This system is set up to handle type-based dispatching for binary (i.e. two-arg) functions. This includes, though isn't necessarily limited to, binary operators such as addition or subtraction.
The MMD system is straightforward, and currently must be explicitly invoked, for example by a vtable function. (We may reserve the right to use MMD in all circumstances, but currently do not).
For the purposes of the API,
each MMD-able function is assigned a unique number which is used to find the correct function table.
This is the
func_num parameter in the following functions.
While Parrot isn't restricted to a predefined set of functions,
it does set things up so that all the binary vtable functions have a MMD table preinstalled for them,
with default behaviour.
->y are table sizes not highest type in table.
void mmd_dispatch_v_ppp(Interp *interpreter, PMC *left, PMC *right, PMC *dest, INTVAL function)
destare all PMC pointers, while
func_numis the MMD table that should be used to do the dispatching.
rightand call it, passing in
destlike any other binary vtable function.
voidreturn type, like all the "take two PMCs, return a PMC" vtable functions do.
void mmd_dispatch_v_pip(Interp *interpreter, PMC *left, INTVAL right, PMC *dest, INTVAL function)
void mmd_dispatch_v_pnp(Interp *interpreter, PMC *left, FLOATVAL right, PMC *dest, INTVAL function)
void mmd_dispatch_v_psp(Interp *interpreter, PMC *left, STRING *right, PMC *dest, INTVAL function)
INTVAL mmd_dispatch_i_pp(Interp *interpreter, PMC *left, PMC *right, INTVAL function)
mmd_dispatch_v_ppp(), only it returns an
void mmd_add_function(Interp *interpreter, INTVAL funcnum, funcptr_t function)
func_numis the number of the new function, while
default_funcis the function to be called when the system doesn't know which function it should call. (Because, for example, there hasn't been a function installed that matches the left and right types for a call).
static void mmd_expand_x(Interp *interpreter, INTVAL function, INTVAL new_x)
static void mmd_expand_y(Interp *interpreter, INTVAL function, INTVAL new_y)
void mmd_add_by_class(Interp *interpreter, INTVAL functype, STRING *left_class, STRING *right_class, funcptr_t funcptr)
func_numfunction table that will be invoked when the left parameter is of class
left_classand the right parameter is of class
right_class. Both classes are
STRING *s that hold the PMC class names for the left and right sides. If either class isn't yet loaded, Parrot will cache the information such that the function will be installed if at some point in the future both classes are available.
void mmd_register(Interp *interpreter, INTVAL type, INTVAL left_type, INTVAL right_type, funcptr_t funcptr)
funcptrfor MMD function table
right_type. The left and right types are
INTVALs that represent the class ID numbers.
void mmd_destroy(Parrot_Interp interpreter)
PMC *mmd_vtfind(Parrot_Interp interpreter, INTVAL type, INTVAL left, INTVAL right)