compiling to python byte codes

Maurice LING mauriceling at acm.org
Mon Sep 6 00:22:27 EDT 2004


> I'm not sure if you feel I'm treating you as an idiot, or if you mean that
> literally. Regardless, it isn't my intent. It is challenging because we
> end up unable to share vocabulary.
> 

Figurative speech intended here. I wish to maintain the thought that 
python users are helpful. :)

> 
> It implements a simple calculator interpreter. It is an "interpreter"
> because as it encounters the input, it is dynamically executing it. A
> "compiler" would actually just store it as a tree, then later output it
> into some other format without execution, which is what a C++ compiler
> does, outputting the opcodes for the CPU.

I'm looking at generating either python source or MA (intermediate 
representation in assembly-like form) on the fly (as the lines are being 
interpreted). The design of MA (2-operands code) works pretty much like 
functions themselves, as in, each "opcode" can be represented by a 
function in python (or any other language, I presume) and the "operands" 
are like parameters. When MA was thought of, it was meant to target to 
Java, but I suppose it is possible to target to python.

So I think the "MA virtual machine" is like a python library.

> 
> Because of that extra step in the middle, "building a tree", a compiler is
> typically harder to write than an interpreter. Getting the output right
> can also be tricky, and a challenge to debug.

I can see this coming. It may be tricky to isolate the error to 
tree-building or the test codes.



More information about the Python-list mailing list