Re: Pyrex without Python (was Re: calling Pyrex results from C)

Discussion in 'Python' started by =?iso-8859-1?Q?Fran=E7ois?= Pinard, Jan 21, 2004.

  1. [Paul Prescod]
    > Jeff Epler wrote:


    > >How close to impossible would it be to make Pyrex emit Python-free code
    > >if there are only 'cdefs'?


    > It will generate a bunch of Python module crap. You could extract the
    > pure-C code from the middle of it.


    Or just provide a module containing many stub routines.

    > I really don't see much benefit to using Pyrex if even _C_'s standard
    > memory management is too extravagant for your needs. What exactly
    > would Pyrex buy you if you can't afford to use its high-level features
    > like memory management, constructors and OO?


    The pleasure of Python-like syntax, of course.

    Maybe the fact that one can build and debug prototypes in Python, with
    the agenda of later transforming them into C, somehow, without rewriting
    so much of them, for environments where the whole of Python, for various
    reasons, is not welcome.

    --
    Fran├žois Pinard http://www.iro.umontreal.ca/~pinard
     
    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Jan 21, 2004
    #1
    1. Advertising

  2. On Tue, 20 Jan 2004 22:15:18 -0500,
    Fran├žois Pinard <> wrote:
    > Maybe the fact that one can build and debug prototypes in Python, with
    > the agenda of later transforming them into C, somehow, without rewriting
    > so much of them, for environments where the whole of Python, for various
    > reasons, is not welcome.


    At work I've done a much simpler version of this. We produce code for
    mathematical algorithms or state machines that runs inside the Linux kernel;
    code can be written either in C or in a tiny subset of Python (basically,
    assignments, if...elif...else and for loops -- I forget if 'while' is
    implemented or not). Instead of using Pyrex, I just use the compiler
    package to get an AST for a chunk of Python code, and then have a code
    generator that walks over the AST and produces C code.

    The nice thing is that the code generator knows the C-level types of
    variables, so if a and b are arrays, a = a + b generates a 'for' loop in the
    C code.

    In theory you could test them in Python, too, letting you debug problems
    before having to compile C code and insert it into the kernel. A long-term
    pipe dream is to look at code and figure out which cases to test; for
    example, if x is an input parameter and you have the statement 'if 0<x<5:
    ....', you should probably test with x=0, 1, 4, 5 to be sure all the edge
    cases are correct.

    --amk
     
    A.M. Kuchling, Jan 21, 2004
    #2
    1. Advertising

  3. [Andrew]
    > I just use the compiler package to get an AST for a chunk of Python code
    > [...]
    > The nice thing is that the code generator knows the C-level types of
    > variables


    How does it know the types? Pyrex adds additional syntax to do this, but
    if you're using the plain vanilla compiler package then presumably you're
    doing something else?

    --
    Richie Hindle
     
    Richie Hindle, Jan 21, 2004
    #3
  4. On Wed, 21 Jan 2004 12:58:26 +0000,
    Richie Hindle <> wrote:
    > How does it know the types? Pyrex adds additional syntax to do this, but
    > if you're using the plain vanilla compiler package then presumably you're
    > doing something else?


    Types are predeclared using a different mechanism; the compiler goes in with
    a list of all the inputs and outputs and a list of internal variables.

    --amk
     
    A.M. Kuchling, Jan 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Lagemann
    Replies:
    8
    Views:
    537
    Mike Wahler
    Jan 10, 2005
  2. tiwy
    Replies:
    0
    Views:
    461
  3. Kyler Laird

    calling Pyrex results from C

    Kyler Laird, Jan 20, 2004, in forum: Python
    Replies:
    10
    Views:
    544
    Greg Ewing (using news.cis.dfn.de)
    Feb 12, 2004
  4. Chris Lambacher
    Replies:
    0
    Views:
    684
    Chris Lambacher
    Jun 8, 2005
  5. Greg Ewing
    Replies:
    2
    Views:
    373
    Dieter Maurer
    Jun 29, 2006
Loading...

Share This Page