[pypy-dev] dist-simpler-multimethods branch

Samuele Pedroni pedronis at strakt.com
Mon Feb 7 18:12:42 CET 2005


The branch Armin and me worked on over the weekend is ready to be merged.

It is a reimplementation of multimethods for standard objspace using 
chained single-dispatch and user-defined precedences
for types and their conversions. This means that it is clear what 
matches will be tried, for example for bools

bool int long float ANY

Although right now precedences and conversions are given in a very 
exhaustive way in std/model.py, more
declarative approaches can be devised for this. Using well-defined 
precedence lists means that it should
be possible, if necessary, to switch to other internal implementations 
strategies for dispatching.

Chained single dispatching is realised by attaching methods to the 
partecipating classes. (*)

Although we are not using it right now, apart for slicing, the approach 
means that is also easy to have fine
control per argument position and per multimethod of what types 
conversions and precedences are allowed.

The branch also reuses gateways instead of its own frame and code 
special classes.

Samuele

(*) to give an idea these are the methods attached with indicated where 
they are put
 plus the generated free-standing entry-point function for the add 
example in test_multimethod,
you can follow what happens with calls like
 __add_perform_call(space, W_IntObject(), W_IntObject())
 __add_perform_call(space, W_BoolObject(), W_IntObject()) ...


 In: W_BoolObject
def __add__W_IntObject(arg1, space, arg0):
    return add__Int_Int(space, arg0, delegate_b2i(arg1))

************************************************************
In: W_IntObject
def __add__W_IntObject(arg1, space, arg0):
    return add__Int_Int(space, arg0, arg1)

************************************************************
In: W_Root
def __add__W_IntObject(arg1, space, arg0):
    return raiseFailedToImplement()

************************************************************
In: W_BoolObject
def __add(arg0, space, arg1):
    return arg1.__add__W_IntObject(space, delegate_b2i(arg0))

************************************************************
In: W_Root
def __add__W_IntObject(arg1, space, arg0):
    return raiseFailedToImplement()

************************************************************
In: W_IntObject
def __add(arg0, space, arg1):
    return arg1.__add__W_IntObject(space, arg0)

************************************************************
In: W_Root
def __add(arg0, space, arg1):
    return raiseFailedToImplement()

************************************************************
Free-standing entry-point:
def __add_perform_call(space, arg0, arg1):
    return arg0.__add(space, arg1)




More information about the Pypy-dev mailing list