[Types-sig] Low-hanging fruit: recognizing builtins
Guido van Rossum
Wed, 15 Dec 1999 14:21:40 -0500
> What is the proposed framework for these sorts of experiments? Perhaps
> the first project should be an interpreter that can be extended with new
> bytecodes perhaps through a registration mechanism...and a hook to call
> Python code between parsing and generating bytecodes. You have
> specifically commissioned this experiment so it has a good chance of
> being "rolled in" but in the more general case...
Dynamic bytecode registration would slow the PVM too much. Just hack
a few special cases into ceval.c and then go hack on the bytecode.
Note that the bytecode hacking could conceivably be done entirely in
Python. I think Skip Montanaro may have tools to do this already.
A first approximation would be to go hunt through all existing code
objects in a module for LOAD_GLOBAL and STORE_GLOBAL opcodes with
built-in names; for all such built-in names that have no STORE_GLOBAL
anywhere, it's "safe enough" to use the special opcode. Then of
course you will have to hunt through the bytecode for sequences of
LOAD_GLOBAL(<name>), followed by arbitrary code to load an object,
followed by CALL_FUNCTION(1).
--Guido van Rossum (home page: http://www.python.org/~guido/)