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_deref
value
is a reference-like PMC,
dereference it so we can make an MMD call on the 'real' value.mmd_ensure_writable
pmc
is writable enough for function
.mmd_dispatch_p_ppp
left
,
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_pip
mmd_dispatch_p_pnp
mmd_dispatch_p_psp
mmd_dispatch_v_pp
mmd_dispatch_v_pi
mmd_dispatch_v_pn
mmd_dispatch_v_ps
left <op=> right
.mmd_dispatch_i_pp
mmd_dispatch_p_ppp()
,
only it returns an INTVAL
.
This is used by MMD compare functions.mmd_add_function
func_num
is the number of the new function.
function
is ignored.mmd_expand_x
new_x
.mmd_expand_y
mmd_add_by_class
funcptr
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_register
funcptr
for MMD function table func_num
for classes left_type
and right_type
.
The left and right types are INTVAL
s that represent the class ID numbers.mmd_destroy
mmd_vtfind
Parrot_mmd_sort_candidate_list
mmd_arg_tuple_inline
mmd_arg_tuple_func
mmd_search_default
mmd_search_classes
cl
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_candidates
cl
by Manhattan Distancemmd_search_scopes
arg_tuple
.mmd_is_hidden
cl
.mmd_maybe_candidate
pmc
is a Sub PMC,
push it on the candidate list and return TRUE to stop further search.mmd_search_cur_namespace
mmd_search_builtin
Parrot_mmd_register_table
Parrot_mmd_rebuild_table
type
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
|