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 (two argument) 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 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.
static void dump_mmd
funcptr_t get_mmd_dispatch_type
static funcptr_t get_mmd_dispatcher
static PMC *mmd_deref
value
is a reference-like PMC,
dereference it so we can make an MMD call on the 'real' value.static void mmd_ensure_writable
pmc
is writable enough for function
.PMC *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.PMC *mmd_dispatch_p_pip
mmd_dispatch_p_ppp
,
right argument is a native INTVAL.PMC *mmd_dispatch_p_pnp
mmd_dispatch_p_ppp
,
right argument is a native FLOATVAL.PMC *mmd_dispatch_p_psp
mmd_dispatch_p_ppp
,
right argument is a native STRING *.void mmd_dispatch_v_pp
left <op=> right
.void mmd_dispatch_v_pi
left <op=> right
.void mmd_dispatch_v_pn
left <op=> right
.void mmd_dispatch_v_ps
left <op=> right
.INTVAL mmd_dispatch_i_pp
mmd_dispatch_p_ppp()
,
only it returns an INTVAL
.
This is used by MMD compare functions.void mmd_add_function
func_num
is the number of the new function.
function
is ignored.static void mmd_expand_x
new_x
.static void mmd_expand_y
void 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.void 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.void mmd_register_sub
void mmd_destroy
PMC *mmd_vtfind
PMC *Parrot_MMD_search_default_infix
PMC *Parrot_mmd_sort_candidate_list
static PMC *mmd_arg_tuple_inline
static PMC *mmd_arg_tuple_func
static PMC *mmd_search_default
static void 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.static INTVAL distance_cmp
static PMC *mmd_cvt_to_types
static UINTVAL mmd_distance
pmc
against given argument types.
0xffff is the maximum distancestatic void mmd_sort_candidates
cl
by Manhattan Distancestatic PMC *mmd_search_scopes
arg_tuple
.static int mmd_is_hidden
cl
.static int mmd_maybe_candidate
pmc
is a Sub PMC,
push it on the candidate list and return TRUE to stop further search.static int mmd_search_cur_namespace
static PMC *mmd_get_ns
static PMC *mmd_make_ns
static void mmd_search_builtin
void mmd_create_builtin_multi_stub
static void mmd_create_builtin_multi_meth_2
static void mmd_create_builtin_multi_meth
void Parrot_mmd_register_table
void 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
|