J
John Nagle
David said:There are efficient implementations of dynamic programming languages
which do not rely on declaration (if by declaration you mean typing
declaration), even when available:
http://strongtalk.googlecode.com/svn/web site/history.html
See also:
http://www.avibryant.com/2008/05/those-who-misre.html
Yes, that's my point.
Psyco was a good first step. The big win with Psyco is that it
generally can recognize when a variable is an integer or floating
point number, and generate hard code for that. It doesn't do much
for the rest of the language. Psyco is really a kind of JIT compiler.
Those are useful, but in some ways limited.
To go beyond that, global analysis is needed. A big bottleneck
in Python is that too much time is spent doing dictionary lookups
for things that could be bound at compile time. So the next big
win is figuring out which classes definitely don't have any hidden
dynamism. A global check is needed to see if any external code
messes with the attributes of a class or its functions from outside
the function. Most of the time, this is the case. Once that's
been done, the class's module can be analyzed for optimization.
If the class doesn't use "setattr", etc. to add attributes to
itself, then the class can be "slotted", with a C++ like structure for
the class members and functions.
Global analysis also has to determine the class hierarchy; what inherits
from what. It may be necessary to implement "object" as an abstract class
with a huge number of virtual functions, so that "duck typing" will work.
That's a space cost, but not a time cost.
Caller/callee type inference is useful to determine the potential types
of parameters. Often, analysis of all the calls to a function will determine
the types of many of the paraeters. Then, those parameters can be hard-typed
at compile time.
You can go this far without the restrictions Shed Skin imposes, such as
the restriction that lists must be homogeneous. If you do impose that
restriction, array processing becomes much faster. Type inference for
array elements is hard when arrays are computed from other arrays, so
that's a huge simplification.
Yes, you can't use "eval" to get at existing variables. But in Python,
you don't really need to.
John Nagle