开发者

What parser do JRuby and Jython use for generating JVM bytecode?

Do you guys know what parser JRuby and Jython use for开发者_JAVA技巧 generating JVM bytecode? Is it ANTLR or JavaCC or are they using some other parser in their implementation?


JRuby seems to be answered already, so I'll add what I know about Jython.

Jython uses an ANTLRv3 generated parser to generate an AST that conforms to the spec for the one you can get from Pythons built in compile function (if you ask for AST Jython will just return after this stage). This is then fed through a custom compiler that uses the ASM Java bytecode generation library to generate Java bytecode that is then loaded and executed. Jython does not (in contrast to JRuby) have an initial interpreted stage, but compiles directly to Java bytecode and lets the JVM handle it from there. Because of this I've never liked it when people describe Jython as a Python interpreter written in Java, I'd much rather call it a Python implementation for Java.


JRuby uses a custom compiler that compile Ruby functions as needed. This is written in Java. This is described very well in this blog post.

Jython probably has a similar approach. Google searches didn't lead me to any one good document for describing how things are accomplished, but several documents mention that Jython is a Python interpreter written in Java, indicating to me that they create bytecode by compiling Java code with the compiler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜