[pypy-dev] Re: Greetings
arigo at tunes.org
Thu Jul 10 15:49:15 CEST 2003
On Wed, Jul 09, 2003 at 03:40:21PM -0500, Jonathan David Riehl wrote:
> I actually didn't bother to schedule the DAG's (I didn't know anything
> about that topic at the time) and ended up emitting the basic blocks by
> simply inlining calls to the Python API.
This looks similar to what we want to do here, and have started working on in
the annotation object space. We build information about the code by
interpreting it somehow. What is nice with having a whole interpreter already
here in the first place is that we can reuse it for this analysis. Constant
folding is indeed completely trivial.
> thing about the representation was it's functional representation
> (iterative loops would translate to recursive functions), since I still
> don't know much about elimination of recursion on the back end.
This too is the point here. The analysis essentially produces a functional
representation. It is probably a good thing to have. Modern compilers tend to
use this representation too (they call it SSA, Single-Step Assignment), which
is that disregarding a source code variable name all assignments essentially
create a new variable. The remaining question is how you close loops, i.e. how
the new variable created by assignment inside the loop should be identified
with the old variable of the same name when we jump back. At this point using
recursive functions is only one solution; if you are targeting a low-level
language (like C with gotos) all you need to do is copy values back into the
original variables (i.e. merge the end-of-loop state with the start-of-loop
state), and jump back.
As we plan to target Pyrex first we will need to think about this, as Pyrex
has neither gotos nor good (tail-end) recursion. If someone comes up with an
algorithm to translate an arbitrary bunch of code with gotos back into nested
ifs and while loops he's most welcome :-)
More information about the Pypy-dev