[pypy-dev] genpyrex -> genc ?

Richard Emslie rxe at ukshells.co.uk
Wed Aug 18 00:32:32 CEST 2004

Hi Armin,

On Tue, 17 Aug 2004, Armin Rigo wrote:

> Hello,
> Perhaps generating Pyrex code isn't such a great idea.  The great idea was to
> use CPython as an intermediate target.  But writing C extension modules in C
> instead of in Pyrex is quite possibly much cleaner, because:
> * very basic C code is sufficient;
> * removing yet another intermediate step might not be a bad idea for clarity;
> * reference counting is easy because we know exactly when variables get out of
>  scope: when they reach the end of a basic block and are not sent to the next
>  block;
> * we don't have to work around various Pyrex restrictions (or hack Pyrex to
>  lift them);
> * most importantly, the whole mess with the "class Op" in genpyrex.py can
>  probably be completely omitted, because we can use C macros and generate
>  just a succession of OP_XXX(a,b,c) where XXX is the operation name and
>  a,b,c are the arguments.  Mapping the operations to actual C code is done
>  once and for all in a C header file with macro definitions.
> A quick-test (borring from genpyrex.py) is checked in a branch in
> http://www.codespeak.net/svn/pypy/branch/pypy-genc/ producing (not yet
> compilable) C code that looks like the attached example. It looks much like
> assembler code.  It's quite readable and easy to map to the original flow
> graph, too.
> Not sure what to do now.  Does this look like a good idea?

Not much to add.  It is far easier to understand the C (CPython) code than 
the Pyrex as much closer to basic blocks.  Wasn't looking forward to 
having to dive into the Pyrex source code to try figure out what went 
wrong, when it does go wrong.  :-) Anyways you said that already.  +1 from 

BTW New graphdisplay stuff is v. cool.  Would be nice if we could get a 
popup with the generated C code for that block when mouse lingers over it, 

Just a silly thought off the top of my head - we could generate very basic 
c++ code (pretty much the same as the very basic c code) but with 
reference counted c++ pointers / wrappers and use of C scoping rules 
instead of PyObjects, and using the c++ exceptions mechanism to do pypy 
exceptions.  That probably needs some expanding / rationalization, but you 
get the idea (I might have a play at the weekend.)


More information about the Pypy-dev mailing list