Question

Is it possible to create a new language for the Python Virtual Machine? I was reading over http://late.am/post/2012/03/26/exploring-python-code-objects , where the blogger discusses Python code objects. In it, he discusses a disassembly of a code object into bytecode and what the symbols in it mean.

This made me think there could be alternative ways to construct this bytecode. I was curious about the ability to create a sandboxed language within Python bytecode so that Python could load it up. Using Python itself for sandboxing seems darn near impossible, but this appears to make a pathway for another implementation language.

Where would I start if I wanted to pursue this venture? What might be a better approach, and where would I find more on other approaches?

Was it helpful?

Solution

Why the lucky stiff once hacked together a script that would compile Ruby code into Python bytecode. I remember that it worked well for simple Ruby scripts. You can look at the sources to see how he did it.

EDIT: So what he does is let the Ruby VM generate Ruby bytecode, than translate that bytecode to Python. Could still be interesting to see how the Python bytecode is assembled :)

OTHER TIPS

I think a good place to start would be ply, here's a Lisp implementation using ply: http://www.juanjoconti.com.ar/files/python/mini-lisp/

I'm not sure if ply can generate syntax trees using Python's ast module, but it should be possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top