[pypy-dev] Re: Dynamic compilation via pyrex?

Michael Hudson mwh at python.net
Sun Mar 13 23:50:56 CET 2005

"Grant Olson" <olsongt at verizon.net> writes:

>> We use Pyrex to statically compile dynamically generated
>> source code. The compiled code is then imported into the
>> process that generated the code.  But surely, this still means
>> we are statically compiling things. 
> Let me guess, this doesn't work on Windows yet? ;-)

No, it does.  We have Christian to beat us up when we break that :)

>> Let me note that with 'dynamic' we usually mean even more dynamic 
>> than your pyasm, in that you could assemble and run inline fragments 
>> of machine code at runtime (for implementing e.g. Psyco in PyPy). 
> There is an api in pyasm that you can use to do this.  You don't need to
> just pass in a monolithic string like I did in the example.  That was just
> easier for most people to understand.  There is a little documentation on
> this and it will be expanded in the next release.  I'm also toying with the
> notion of something similar to a main() function that gets executed
> automatically at runtime instead of forcing you to bind to function names
> and calling the functions.
> That is, unless you're talking about something like:
> def foo(a,b):
>     print a + b
>     MOV EBX, [EBP-4]
>     print EBX
> That I can't do.  I would obviously have to fork CPython to implement
> something like that, and that's not something I'm personally interested in.
> I'm not even sure if this would make sense in an optimized build.

Uh, no, neither of these things.

The way psyco works is that when "compiling" a function like:

def f(a):
    return 1 + 2 + a

it only compiles as far as it can until it needs to know the type of
a; then it stops and "waits" until the function is actually called,
when obviously this is an easy question to answer, then compiles a bit
more, and so on.  If the function is called again with a different
type of argument, a different version of the code is compiled.  Etc.

People don't generally expect this sort of thing when they design
their APIs :)


  What the semicolon's anxious supporters fret about is the tendency
  of contemporary writers to use a dash instead of a semicolon and
  thus precipitate the end of the world.
                               -- Lynne Truss, "Eats, Shoots & Leaves"

More information about the Pypy-dev mailing list