compiling to python byte codes
jmlai at uci.edu
Fri Sep 3 06:14:00 CEST 2004
Maurice LING wrote:
> Some parts of MA is still undergoing development and cleaning up but I
> certainly do not see why any opcode should cross multiple lines. As far
> as I can see, 70% of the opcodes are able to be represented by multiple
> lines of python codes. I've not thought hard enough on this yet.
> All I can say is that MA looks similar to any assembly is structure,
> with directives.
Well, x86/PPC assembly operates on registers. Python uses a stack.
If you're using registers, I guess you'd have to store the values in
variables, and load/store them through the stack whenever you do an
operation -- maybe with some optimization if you can keep the result on
Python pretty much only lets you run a block of code at once (using exec
or eval). So if you compile it line by line on the fly, your VM would
have to ask Python to run each line, and take care of unstructured jumps
itself. Python doesn't really like arbitrary gotos anyway. I assume if
you were translating to Python code, you'd have to have the whole block
for if, while, etc, ahead of time. Or only jump backwards, since you
can't jump to something that hasn't been written yet.
More information about the Python-list