librelist archives

« back to archive

py2js - opcodes vs AST experience

py2js - opcodes vs AST experience

Ondřej Čertík
2012-07-01 @ 17:50

I just wanted to share some experience with a Python to Javascript
translator that I started some time ago. First using opcodes:

but I have abandoned the approach, because the opcodes made it really
hard to understand the original Python syntax (it is just too
low-level). So I then wrote py2js using AST:

That works well. I just didn't have time to work on it, but as far as
I know, the approach should allow to translate pretty much any Python
to Javascript.
So you can use it to get ideas how to get things done, as some of it
is not super well documented in the official Python docs.
In the above, I did reuse some codes from other people.