Matt Fowles wrote: > I am trying to find a reasonable path towards direct bytecode > generation. My current setup has a hand rolled java dom that I then > serialize to java code which I compile using javac. I have found that > I can replace my java dom with the jdt.core one and still do the > serialize/compile trick. But, I would really like to be able to skip > the serialize step and go directly some AST to a .class file. > > This approach is fairly nice in that it allows me to inspect the > generated code easily and find bugs that way. Thus I would like to > maintain the ability to generate the java code, even if I only use it > for debugging. > > I looked into jdt.core.dom which is the AST that eclipse uses when > refactoring code, but couldn't figure out a way to make it emit > bytecode. Does anyone know of any such targetable ASTs? Another > approach, how stable is the internal AST used by ECJ or javac?
The gnu.expr AST used by Kawa is used for a number of different languages: Scheme, Common Lisp, Emacs Lisp, XQuery, XSLT subset, Nice, and possibly others. gnu.expr in turns is based on the lower-level gnu.bytecode package. (Once it's posted, I'll add a link to Elliott Hughes's blogging about his experience comparing ASM and gnu.bytecode.) http://www.gnu.org/software/kawa/internals/index.html http://www.gnu.org/software/kawa/api/gnu/expr/package-summary.html http://www.gnu.org/software/kawa/api/gnu/bytecode/package-summary.html It generates very efficient code - Kawa Scheme with some judicious type annotations may be the most efficient "scripting language" (if defined as a language with eval and a repl) on the JVM. It can't emit Java code, but it does have a pretty-printer for the internal AST, which does intelligent indentation while minimizing line-breaks: $ kawa --debug-print-expr #|kawa:1|# (define (foo x) (+ x 10)) [Module:atInteractiveLevel$1 (Module/atInteractiveLevel$1/1/ (Declarations: foo/15/fl:8c2::gnu.mapping.Procedure) (Define line:1:1 /Declaration[foo/15] (Lambda/foo/5/fl:0 line:1:9 (x/16/fl:40) (Apply line:1:17 (Ref/6/Declaration[applyToArgs/1]) (Ref/4/Declaration[+/17]) (Ref/5/Declaration[x/16]) (Quote 10)))))] #|kawa:2|# -- --Per Bothner [EMAIL PROTECTED] http://per.bothner.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en -~----------~----~----~----~------~----~------~--~---
