[Python-ideas] Register based interpreter

Antoine Pitrou solipsis at pitrou.net
Sat Feb 21 00:01:37 CET 2009


Greg Ewing <greg.ewing at ...> writes:
> 
> Perhaps there is room for a hybrid approach where you
> take sequences of instructions such as
> 
>     LOAD_LOCAL x
>     LOAD_LOCAL y
>     BINARY_ADD
>     STORE_GLOBAL z
> 
> and turn them into 3-operand macroinstructions
> 
>     TRINARY_ADD LOCAL(x), LOCAL(y), GLOBAL(z)

I was thinking of something like that, although in a simpler form of 2-operand
macroinstructions:

BINARY_ADD 5, 8

where 5 and 8 are indices into a "super array" which would be equal to:
[local variables] + [code object constants]
(fast random access to the array would imply copying the constants table each
time a new frame is created for the given code object, but it would hopefully
remain quite cheap)

We can keep the current instruction format and address up to 256 local variables
and constants by splitting the 16-bit operand in two bytes.

The result would be stored on top of stack.
(if we want to access the top of the stack using the macroinstructions, we could
reserve 255 as a special index value for popping the top of the stack...)

Regards

Antoine.





More information about the Python-ideas mailing list