| 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.

binop_mmd_funcs->x and ->y are table sizes not highest type in table.

mmd_derefvalue is a reference-like PMC,
dereference it so we can make an MMD call on the 'real' value.mmd_ensure_writablepmc is writable enough for function.mmd_dispatch_p_pppleft,
right,
and dest are all PMC pointers,
while func_num is the MMD table that should be used to do the dispatching.
If the dest pointer is NULL,
it dispatches two a two-argument function that returns a new dest always.left and right and call it,
passing in left,
right,
and possibly dest like any other binary vtable function.mmd_dispatch_p_pipmmd_dispatch_p_pnpmmd_dispatch_p_pspmmd_dispatch_v_ppmmd_dispatch_v_pimmd_dispatch_v_pnmmd_dispatch_v_psleft <op=> right.mmd_dispatch_i_ppmmd_dispatch_p_ppp(),
only it returns an INTVAL.
This is used by MMD compare functions.mmd_add_functionfunc_num is the number of the new function.
function is ignored.mmd_expand_xnew_x.mmd_expand_ymmd_add_by_classfuncptr to the func_num function table that will be invoked when the left parameter is of class left_class and 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.mmd_registerfuncptr for MMD function table func_num for classes left_type and right_type.
The left and right types are INTVALs that represent the class ID numbers.mmd_destroymmd_vtfindParrot_mmd_sort_candidate_listmmd_arg_tuple_inlinemmd_arg_tuple_funcmmd_search_defaultmmd_search_classescl and return a list of all candidates.
start_at_parent is 0 to start at the class itself or 1 to search from the first parent class.mmd_sort_candidatescl by Manhattan Distancemmd_search_scopesarg_tuple.mmd_is_hiddencl.mmd_maybe_candidatepmc is a Sub PMC,
push it on the candidate list and return TRUE to stop further search.mmd_search_cur_namespacemmd_search_builtinParrot_mmd_register_tableParrot_mmd_rebuild_tabletype is negative all classes are rebuilt.
If func_nr is negative all MMD functions are rebuilt.
include/parrot/mmd.h, http://svn.perl.org/perl6/doc/trunk/design/apo/A12.pod, http://svn.perl.org/perl6/doc/trunk/design/syn/S12.pod
|  |   |