Compiler C or Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jørgen Hermanrud Fjeld

    Compiler C or Python?

    On Tue, Aug 26, 2003 at 04:33:17PM -0500, Jeff Epler wrote:[color=blue]
    > 4. It's possible to write code so that __import__ uses compiler.compil e
    > instead of the written-in-C compiler, but I don't have this code handy.
    > Also, a test suite is needed, and presumably a written-in-C implementation
    > as well. (option 2: make the compiler.compil e interface the standard
    > compiler, and let the builtin compiler support a Python subset
    > sufficient to bootstrap the written-in-python compiler, or arrange
    > to ship .pyc of the compiler package and completely get rid of the
    > written-in-C compiler)[/color]

    Could you make an effort to locate that code, or give some suggestions to
    where I might locate it myself?

    And in general, if should want to alter the Python compiler, should I start
    with the Python or C version?
    As far as I can see from your email the Python version is easier to modify,
    but why two compilers? Isn't that a lot to maintain?

    Sincerely
    Jørgen

  • John Roth

    #2
    Re: Compiler C or Python?


    "Jørgen Hermanrud Fjeld" <jhf@hex.no> wrote in message
    news:mailman.10 62498963.22409. python-list@python.org ...
    On Tue, Aug 26, 2003 at 04:33:17PM -0500, Jeff Epler wrote:[color=blue]
    > 4. It's possible to write code so that __import__ uses compiler.compil e
    > instead of the written-in-C compiler, but I don't have this code handy.
    > Also, a test suite is needed, and presumably a written-in-C implementation
    > as well. (option 2: make the compiler.compil e interface the standard
    > compiler, and let the builtin compiler support a Python subset
    > sufficient to bootstrap the written-in-python compiler, or arrange
    > to ship .pyc of the compiler package and completely get rid of the
    > written-in-C compiler)[/color]

    Could you make an effort to locate that code, or give some suggestions to
    where I might locate it myself?

    And in general, if should want to alter the Python compiler, should I start
    with the Python or C version?
    As far as I can see from your email the Python version is easier to modify,
    but why two compilers? Isn't that a lot to maintain?

    [John Roth]
    I believe that the Python version of the compiler uses the C version
    in several places. The documentation mentions the parser and the
    creation of the concrete syntax tree.

    In other words, it's not a complete implementation. It also seems
    to have some problems with error checking. The primary use seems
    to be manifesting an abstract syntax tree for program analysis tools
    to work on.

    John Roth

    Sincerely
    Jørgen


    Comment

    • Michael Hudson

      #3
      Re: Compiler C or Python?

      jhf@hex.no (Jørgen Hermanrud Fjeld) writes:
      [color=blue]
      > On Tue, Aug 26, 2003 at 04:33:17PM -0500, Jeff Epler wrote:[color=green]
      > > 4. It's possible to write code so that __import__ uses compiler.compil e
      > > instead of the written-in-C compiler, but I don't have this code handy.
      > > Also, a test suite is needed, and presumably a written-in-C implementation
      > > as well. (option 2: make the compiler.compil e interface the standard
      > > compiler, and let the builtin compiler support a Python subset
      > > sufficient to bootstrap the written-in-python compiler, or arrange
      > > to ship .pyc of the compiler package and completely get rid of the
      > > written-in-C compiler)[/color]
      >
      > Could you make an effort to locate that code, or give some suggestions to
      > where I might locate it myself?
      >
      > And in general, if should want to alter the Python compiler, should
      > I start with the Python or C version?[/color]

      Whichever's easiest :-) This is usually the Python one.

      A toy that might come in handy is an interactive mode (based on
      code.Interactiv eConsole) that compiles input with the customized
      compiler.
      [color=blue]
      > As far as I can see from your email the Python version is easier to
      > modify, but why two compilers? Isn't that a lot to maintain?[/color]

      The Lib/compiler/ package is pretty slow. Also, making that the only
      compiler might lead to irritating bootstrapping problems (which I now
      see Jeff talked about...).

      Cheers,
      mwh

      --
      Do I do everything in C++ and teach a course in advanced swearing?
      -- David Beazley at IPC8, on choosing a language for teaching

      Comment

      • Jørgen Hermanrud Fjeld

        #4
        Re: Compiler C or Python?

        On Tue, Sep 02, 2003 at 11:37:03AM +0000, Michael Hudson wrote:[color=blue]
        > jhf@hex.no (Jørgen Hermanrud Fjeld) writes:[color=green]
        > > And in general, if should want to alter the Python compiler, should
        > > I start with the Python or C version?[/color]
        >
        > Whichever's easiest :-) This is usually the Python one.
        >[/color]
        Then I shall start with that one. Are there any other arguments/reasons to
        choose one or the other? That is technicalities one should consider.
        [color=blue]
        > A toy that might come in handy is an interactive mode (based on
        > code.Interactiv eConsole) that compiles input with the customized
        > compiler.[/color]
        Thanks, this can make the task at hand a lot easier.
        [color=blue][color=green]
        > > As far as I can see from your email the Python version is easier to
        > > modify, but why two compilers? Isn't that a lot to maintain?[/color]
        >
        > The Lib/compiler/ package is pretty slow. Also, making that the only
        > compiler might lead to irritating bootstrapping problems (which I now
        > see Jeff talked about...).[/color]
        Yes, but the code it generates will be fast enough for my purposes.
        Do you happen to know how consistency between the compilers is maintained?

        Sincerely
        Jørgen

        Comment

        • Michael Hudson

          #5
          Re: Compiler C or Python?

          jhf@hex.no (Jørgen Hermanrud Fjeld) writes:
          [color=blue]
          > On Tue, Sep 02, 2003 at 11:37:03AM +0000, Michael Hudson wrote:[color=green]
          > > jhf@hex.no (Jørgen Hermanrud Fjeld) writes:[color=darkred]
          > > > And in general, if should want to alter the Python compiler, should
          > > > I start with the Python or C version?[/color]
          > >
          > > Whichever's easiest :-) This is usually the Python one.
          > >[/color]
          > Then I shall start with that one. Are there any other arguments/reasons to
          > choose one or the other? That is technicalities one should consider.[/color]

          I don't think so. The code they produce is essentially identical,
          AFAIK (the only difference I'm aware of is the ordering of the
          constants in co_consts -- hardly critical).

          Oh, Raymond Hettinger added some bytecode rewriting steps to the C
          compiler in 2.3. I don't think Lib/compiler does these.

          For *very* simple tweaks I sometimes find Python/compile.c easier to
          work with, but that's probably because Python/compile.c is a hunk of
          procedural C code I've worked with a fair bit and Lib/compiler is an
          OOP-y framework-y hunk of code I don't quite understand. Someone
          starting from scratch is unlikely to find this.

          Obviously, Python/compile.c gets more testing, and probably has fewer
          bugs.
          [color=blue][color=green][color=darkred]
          > > > As far as I can see from your email the Python version is easier to
          > > > modify, but why two compilers? Isn't that a lot to maintain?[/color]
          > >
          > > The Lib/compiler/ package is pretty slow. Also, making that the only
          > > compiler might lead to irritating bootstrapping problems (which I now
          > > see Jeff talked about...).[/color]
          > Yes, but the code it generates will be fast enough for my purposes.[/color]

          Oh yes, the compiled code runs at the same speed.
          [color=blue]
          > Do you happen to know how consistency between the compilers is
          > maintained?[/color]

          Blood and toil :-/

          Cheers,
          mwh

          --
          I have long since given up dealing with people who hold idiotic
          opinions as if they had arrived at them through thinking about
          them. -- Erik Naggum, comp.lang.lisp

          Comment

          Working...