On Fri, 1 Jul 2005, Leopold Toetsch wrote:
Kevin Tew wrote:
I've been working on a python compiler also, feel free to take a look,,
svn co http://svn.openfoundry.org/pyparrot languages/python/pyparrot
My current boggle is how to handle the self parameter to method functions.
You can do things like this in python
def foobar( arg1, arg2 ):
print arg1, arg2
class A():
self.__add__ = foobar
aa = A()
print aa + 5
Well, the Python translator has to recognice that "__add__" and such has a
special meaning in CPython. Therefore the getattribute (in that case of the
class - but not only) has to check for such special names and in that case
store the Sub object for "foobar" into the "A" namespace under the name
"__add" - that is Parrot's notation for the thingy.
The rest i.e. calling the sub on the last line, is done by Parrot's MMD
implementation.
Hmm. I'm pretty sure this is handled automagically
by the Python pmc's in pirate... Using the + in
pir (or the add op) actually invokes a dispatch
method in the PMC that handles the situation. I'm
not 100% sure if Sam implemented it, but if so it
would be in the pmc's, not the code generator.
Pirate doesn't have to know anything special about
__add__ because foobar is just another pmc - one
that happens to be a callable. The only tricky
part I see is that because foobar doesn't have
the explicit self parameter, it has to be handled
differently by getattr. (In cpython there's a
difference beween a function and a 'bound'
method, and I think the magic happens in
getattr)
Anyway, I *think* the existing pmc's solve all
these problems.
Sincerely,
Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
-------------------------------------