[Compiler-sig] More Jython progress

Jeremy Hylton jeremy@zope.com
Mon, 22 Apr 2002 00:31:53 -0400


>>>>> "FB" == Finn Bock <bckfnn@worldonline.dk> writes:

  FB> Hi, Based on the current AST tree and a modified CodeCompiler, I
  FB> can now generate javabytecode. I'm sure there are still a few
  FB> bugs in the generated code but it passes our initial (rather
  FB> small) test suite.

  FB> The patch to current jython CVS is available here:

  FB> :
  FB> http://sourceforge.net/tracker/?func=detail&atid=312867&aid=546737&group_id=12867

  FB> The next phase for Jython is to port jythonc (the java
  FB> sourcecode generator) to use the new AST tree.

I had hoped to look over your code this weekend, but didn't get to
it.  The subtleties of converting list comprehensions delayed me <0.6
wink>.  Is it your intent to re-do the compiler(s) in Jython?  In
hindsight, it seems clear that you weren't doing this just to kill
time, but I didn't realize that both Pythons were in for a compiler
overhaul at the same time.

  FB> Some observations about the AST:

I'll have to think about these tomorrow.  I hope it's not too much
trouble that I changed Dict.

  FB> The ListComp and the way I uses it bugs me a little. I'll admit
  FB> it is a clever way of representing a listcomp but I have been
  FB> reusing the visitFor() and visitIf() methods to generate the
  FB> loop and branching code. Since I wanted to continue to do that I
  FB> builds a series of For() and If() statements from the listcomp:

I just looked at the compiler package and saw that it's visitFor() and
visitListFor() are quite similar.  The visitIf() and visitListIf()
aren't very similar, presumably because a lot of logic is in the
visitListComp() method.

    The compiler package uses a ListComp() object with two children --
    a binding expression and a list of ListCompFor and ListCompIf
    nodes.)

I'd need to think harder about how the two kinds of fors and ifs could
be merged here.  Perhaps you could accomplish this with helper methods
instead of creating throwaway nodes?  _visit_generic_for() that could
be called be either visitFor() or visitlistcomp()?

Jeremy