[pypy-dev] RE: Interfacing Python Code with Autogenerated C code

Rocco Moretti roccomoretti at netscape.net
Fri Jan 24 03:14:49 CET 2003


"Gerald S. Williams" <gsw at agere.com> wrote:

>Rocco Moretti wrote:
>> How would the interface between the two work if the hand translated sections differ
>> from the C version?
>
>I can give general answers from past experience.
>
>> Simplest example is basic types. A Python version would presumably be represented as a
>> class with member functions. But the C code uses calls to accessor functions. How could
>> we redirect the automatically generated code to call member functions as opposed to
>> free floating functions?
>
>One answer: provide such functions, which call the member
>functions as needed.
>
>> A more difficult problem lies when we we start to reorganize the object/structure
>> internals. Good case of this is the frame object. The C version has an array with
>> multiple pointers to internal objects. Once you reorganize the internals, how do
>> you tell the C->Python translator that f_stacktop isn't a PyObject pointer anymore,
>> but an index off of another list?
>
>If the class was providing public attributes, you may not
>want to change their meaning. f_stacktop could provide an
>accessor for the old representation. The new representation
>would be in _f_stacktop or something.
>
>-Jerry

In short, if we use C->Python autogeneration, we need to maintain legacy interfaces in any C code we hand translate to Python. - Sounds fair enough.

One thought I had since posting is that it may be possible to build intellegence into the translator, such that it can massage calls from one function into another (perhaps multiple) call(s) to another function, reorganize functions into members, and map attribute accesses into member function calls, as the case may be. I'd anticipate you would need to feed the translator a file describing the mapping of the [C language interface of the hand translated code] onto the Python language interface.

Something to the effect of:

guido(a,b,c) --> n = guido_1(a,b); guido_2(n,c)
tim(d,e) --> e._tim(d)
F_bot.g = X --> F_bot.set_g(X)

You may even be able to use this technique to map the C standard library functions onto their Python equivalents.

-Rocco (Avoiding f**, b*r and b*z)

__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp 

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


More information about the Pypy-dev mailing list