[Python-Dev] Parrot -- should life imitate satire?
Dan Sugalski
dan@sidhe.org
Wed, 01 Aug 2001 00:16:43 -0400
At 12:03 AM 8/1/2001 -0400, Guido van Rossum wrote:
> > >The vtable looks a lot like Python's type object. Is Perl's vtable an
> > >object in its own right?
> >
> > Depends on your definition of object, I suppose. There is a mapping from
> > the low-level bits the interpreter needs to interpreted-language level
> > things--while the vtable won't actually be directly manipulatable at the
> > HLL level, manipulating HLL constructs will alter the vtable, so it's
> > effectively the same thing.
>
>In Python, the type pointer really does point to a full-fledged
>object. Which probably means something quite different than it means
>in Perl. :-)
Ah. There's going to be a level of indirection there with Parrot. That'll
introduce some speed hits, but only when altering the behaviour of the
objects. It's been my experience that altering behaviour happens rather
less frequently than the behaviour itself happens, so it makes sense to
optimize both ends (the interface presented to the HLL programmer and the
interface presented to the interpreter engine) and let the middle layer be
a bit slower.
In this case, the vtable interface doesn't cover general method calls
(except to the extent that a variable will have a vtable entry to handle
method calls, in case you want to override the inheritance behaviour on a
per-object basis, or enable multimethod dispatch for some objects), which
are another beast entirely. The vtable interface, at the moment, covers the
operators you'd expect to be able to override--assignment, simple math,
most string operations, conversion duties, and suchlike things. So this code:
a = b + c
would call the add vtable method for b, and the assign vtable method for a,
while this:
a.foo()
would make a generic method call on a looking for the foo method, and the
vtables generally wouldn't be involved other than handling the (possibly
cached) lookup of foo.
The point is to put the commonly called things in the vtable in a way that
you can avoid as much conditional code as possible, while less common
things get dealt with in ways you'd generally expect. (Dynamic lookups with
caching and suchlike things)
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
dan@sidhe.org have teddy bears and even
teddy bears get drunk