PHP compiler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manuel Lemos

    #16
    Re: PHP compiler

    Hello,

    On 03/08/2004 05:34 PM, CountScubula wrote:[color=blue][color=green]
    >>No. See, you didn't understand my question correctly. I don't actually
    >>need a PHP compiler, what I need is an *information* wether that
    >>compiler exists. And why's that? Becouse my team and I might be doing a
    >>PHP compiler as a student project for my Comiler Design course at
    >>University (I, as a group leader, have 10 people and 4 months on my
    >>hands to build a comiler of my own). So, it would be very nice to have
    >>"nobody did it before" in my project documentation. And I can write that
    >>if I'm not sure, right?[/color]
    >
    >
    > If I may say, if you have never written a compiler before, do attempt a php
    > compiler, stick to a language that is more suited for compiling.
    >
    > PHP has too many functions, that can limit compiling, for example, the
    > require() function can be used like a C-style include, and compiled, but you
    > lose out on the include() function, becouse a lot of time people need to
    > include editable (such as forms erc..) files at run time, therefore those
    > files can not be compiled. Actualy even some require() files can not be
    > compiled, becouse they contain config variables that need to be editied by
    > the user.[/color]

    He never said that he wanted to develop a compiler that generates an
    executable that works by itself. Anybody can develop a compiler that
    links to libphp.a and the necessary parts of Zend engine. Over time the
    compiler could be optimized to replace some PHP function calls with
    native C code.

    Actually, the compiler could be Just In Time (JIT) and be transparently
    integrated in the PHP runtime execution for maximizing the performance
    and keeping the flexibility.

    --

    Regards,
    Manuel Lemos

    PHP Classes - Free ready to use OOP components written in PHP
    Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


    PHP Reviews - Reviews of PHP books and other products


    Metastorage - Data object relational mapping layer generator

    Comment

    • Nikola Skoric

      #17
      Re: PHP compiler

      Dana Mon, 08 Mar 2004 20:24:31 +0100,
      Jedi121 <jedi121news@fr ee.fr.Removethi s> kaze:[color=blue]
      > PHP_Sharp[/color]

      Hm, hm, this one is interesting. I myself have been thinking about
      PHP -> MSIL compiler... Thanks for the tip!

      --
      Pozdrav/Regards, Nikola [Nick] Skoric.
      "...Usne, tice-rugalice - a u oku tajac
      Da sam kaput sa dva lica, da sam Gospo'n Propalica..."
      http://newusers.cjb.net/ - site o Usenetu na hrvatskom!

      Comment

      • Nikola Skoric

        #18
        Re: PHP compiler

        Dana Mon, 08 Mar 2004 19:51:53 +0000,
        J Taylor <jt@imen.org.uk > kaze:[color=blue]
        > Nikola Skoric wrote:[color=green]
        >> That question is of no importance to me at this point. Now my main
        >> concern is to get as much points for my crew and me, so we could get
        >> better grades. *BUT* as I have great intrest in optimizing algorithms,
        >> and I'm still 2 years away from my University diploma, there is a great
        >> probability that I might be doing some optimizing to... and after I'm
        >> finished with the project it would be a realy nice start for a PHP
        >> compiler... if my University alowes me to publish it under GPL.[/color]
        >
        > mmm you might then be interested in compiling to some other bytecode -[/color]

        Yes, I'm thinking about compiling to MSIL (.NET Framework language) because
        of all the built in methods that would minimize the effort of writing the
        built in functions. But, anyway, my compiler doesn't have to have more than
        15 built in functions, my aim is to show to my teacher that I understand the
        way compilers are dedigned, no to build a full scale compiler able to whash
        the dishes...
        [color=blue]
        > you could compile to native but you might also want to try compiling a
        > set of functions (remembering that the entire php compiler spaning all
        > function calls would take a long time (years)).[/color]

        That's the reason I don't have to be able to compile all ot PHP functions.
        [color=blue]
        > You might also want to look at the fact that PHP itself uses library
        > calls so most of the function code will be allready written for you - in
        > this case you might be faster generating C code and compiling that.[/color]

        Hmmm... no, to complicated. Our course is about converting higher languages
        to assembly languages, crosscompilatio n is not an option.
        [color=blue]
        > Are
        > there any PHP developers on the list?[/color]

        Which list? :-)
        [color=blue]
        ><recall title="top ten flame wars of the past">Indeed, Tanenbaum[/color]

        Is that the MINIX guy?

        --
        Pozdrav/Regards, Nikola [Nick] Skoric.
        "...Usne, tice-rugalice - a u oku tajac
        Da sam kaput sa dva lica, da sam Gospo'n Propalica..."
        http://newusers.cjb.net/ - site o Usenetu na hrvatskom!

        Comment

        • rush

          #19
          Re: PHP compiler

          "Nikola Skoric" <nick-news@net4u.hr> wrote in message
          news:MPG.1ab5b6 2d9e401c5c98971 8@localhost...[color=blue]
          > Is the a PHP compiler? A program that compiles PHP code to executable
          > which doesn't need php interpreter to execute...[/color]

          Nikola,

          I have been thinkering about possibilites and implications of writing
          another php implementation. My expirience is that first thing that you would
          have to ask yourself is "What is PHP actually?". Is it just a core of the
          language (syntax and semantics). Is the library also part of it? The whole
          library or just some "core" parts of library? Is the web server interface
          also part of the language implementation?

          Here are most troublesome aspects I have came uppon:

          * there is no formal definition of the language and the system. The whole
          thing relies on the concept "implementa tion is definition". For instance
          there is no formal description of the syntax, instead, you digg into the
          bison and flex sources and hack your way from there. I still keep finding
          things in implementation that make system behave differently than what I
          would expect it normaly.

          * library. It is a precious resource, more or less you can find interface to
          allmost anything you would ever like to use. Anyway it is huge, and written
          by many. Writing it from the scratch is mission impossible without very huge
          resources. You can try to use existing library, and try to provide the same
          interface from your execution environment, as original zend engine does so
          that library feels at home. Anyway, while there are descriptions of that
          interface, but I do not feel those descriptions have completness necessary
          to mimic zend environment completely. Also it would still be possible that
          in some library someone hacked a bit deeper than that and used some internal
          knowledge of zend engine.

          * if using the already exiting library you would have to choose wheater to
          tray to use it in "binary compatible" or logically same way. Binary
          compatible would save you from recompiling the library with all caveats that
          might arouse, but forgetting the binary compatibility would allow you to at
          least better fit execution model to your desires.

          * you cold go mixed way with library, reimplement most important parts
          (array strings ..) so that you can use your own execution envornment, and
          use some tunneling to speak with old library for the rest.

          * you could say that library is not part of php and implement just the core
          of the language. This would of course be just an toy.

          * Testing. How do you know that you have done good job in the end
          (especially when you do not have formal definition avaliable)? Testing would
          have to be massive in order to weed out not only bugs, but you
          missunderstandi ngs what php actually is.

          * Legalize ... brr... Library has been written by many, and while my
          understanfding of original Zensd licence is quite liberal, I have not read
          all of the copyright notices in every single source for the library. There
          could be some caveats.

          Anyway, since we live in the same town, you could drop me an e-mail, and we
          could meet for coffe or beer, and chat from time to time about our findings.

          rush
          --
          Get your very own domain easily. Fast and professional customer service.



          Comment

          • R. Rajesh Jeba Anbiah

            #20
            Re: PHP compiler

            Manuel Lemos <mlemos@acm.org > wrote in message news:<c2jf0e$1s u49r$1@ID-138275.news.uni-berlin.de>...
            <snip>[color=blue]
            > He never said that he wanted to develop a compiler that generates an
            > executable that works by itself. Anybody can develop a compiler that
            > links to libphp.a and the necessary parts of Zend engine. Over time the
            > compiler could be optimized to replace some PHP function calls with
            > native C code.[/color]

            So, are you suggesting bcompiler
            <http://pecl.php.net/package/bcompiler> or BinaryPHP
            <http://sourceforge.net/projects/binaryphp/> ?

            p.s.: I never used these tools.

            --
            "I don't believe in the God who doesn't give me food, but shows me
            heaven!"--Swami Vivekanandha
            Email: rrjanbiah-at-Y!com

            Comment

            • Lothar Scholz

              #21
              Re: PHP compiler

              Manuel Lemos <mlemos@acm.org > wrote in message news:<c2jf0e$1s u49r$1@ID-138275.news.uni-berlin.de>...
              [color=blue]
              >
              > He never said that he wanted to develop a compiler that generates an
              > executable that works by itself. Anybody can develop a compiler that
              > links to libphp.a and the necessary parts of Zend engine. Over time the
              > compiler could be optimized to replace some PHP function calls with
              > native C code.
              >[/color]

              But i'm 100% sure that this is nothing for a university compiler
              course. Maybe it is if you only teach the tokenizer and lexical
              parser. But this should take no longer then a month. Everything else
              is for educational things just stupid. Writing an interpreter is a
              good home work assignment, i did this with a lisp interpreter in my
              student days, but using PHP in a compiler course. Oh my Buddha, please
              help the unwise.

              Comment

              • Andreas Rueckert

                #22
                Re: PHP compiler

                On Tue, 9 Mar 2004 10:15:31 +0000 (UTC),
                Nikola Skoric <nick-news@net4u.hr> wrote:

                --<snip>--
                [color=blue]
                >Yes, I'm thinking about compiling to MSIL (.NET Framework language) because
                >of all the built in methods that would minimize the effort of writing the
                >built in functions. But, anyway, my compiler doesn't have to have more than
                >15 built in functions, my aim is to show to my teacher that I understand the
                >way compilers are dedigned, no to build a full scale compiler able to whash
                >the dishes...[/color]

                We were working on a Antlr parser for PHP, that is still incomplete yet.
                But it does not actually contain any builtin PHP methods. It would just
                parser to the point, where it's clear, that the current token is the name
                of a builtin method. Then it should lookup the name in a list of methods,
                that would reference the code to execute that method. So you could add
                new methods dynamically without changing the parser.

                Ciao,
                Andreas

                Comment

                • Manuel Lemos

                  #23
                  Re: PHP compiler

                  Hello,

                  On 03/09/2004 09:36 AM, R. Rajesh Jeba Anbiah wrote:[color=blue][color=green]
                  >>He never said that he wanted to develop a compiler that generates an
                  >>executable that works by itself. Anybody can develop a compiler that
                  >>links to libphp.a and the necessary parts of Zend engine. Over time the
                  >>compiler could be optimized to replace some PHP function calls with
                  >>native C code.[/color]
                  >
                  >
                  > So, are you suggesting bcompiler[/color]

                  No, AFAIK, bcompiler is a dead project.

                  [color=blue]
                  > <http://pecl.php.net/package/bcompiler> or BinaryPHP
                  > <http://sourceforge.net/projects/binaryphp/> ?[/color]

                  Maybe it would be more like this but this project seems to be dead as well.

                  --

                  Regards,
                  Manuel Lemos

                  PHP Classes - Free ready to use OOP components written in PHP
                  Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


                  PHP Reviews - Reviews of PHP books and other products


                  Metastorage - Data object relational mapping layer generator

                  Comment

                  • Manuel Lemos

                    #24
                    Re: PHP compiler

                    On 03/09/2004 10:35 AM, Lothar Scholz wrote:[color=blue][color=green]
                    >>He never said that he wanted to develop a compiler that generates an
                    >>executable that works by itself. Anybody can develop a compiler that
                    >>links to libphp.a and the necessary parts of Zend engine. Over time the
                    >>compiler could be optimized to replace some PHP function calls with
                    >>native C code.
                    >>[/color]
                    >
                    >
                    > But i'm 100% sure that this is nothing for a university compiler[/color]

                    Why not?

                    [color=blue]
                    > course. Maybe it is if you only teach the tokenizer and lexical
                    > parser. But this should take no longer then a month. Everything else
                    > is for educational things just stupid. Writing an interpreter is a
                    > good home work assignment, i did this with a lisp interpreter in my
                    > student days, but using PHP in a compiler course. Oh my Buddha, please
                    > help the unwise.[/color]

                    What you are suggestiong seems pointless. PHP engine itself since
                    version 4 is already a compiler that converts PHP source and byte codes.
                    Writing an interpreter is like going back to the slow PHP 3 days.

                    If anybody writes a tool that converts PHP bytecodes into C/C++ code
                    that when executed does the same as when the original bytecodes are
                    interpreted by the Zend engine, that is also a compiler tool to me. And
                    yes, the base project could be developed in a month much more likely
                    than a PHP source to binary executable project.

                    --

                    Regards,
                    Manuel Lemos

                    PHP Classes - Free ready to use OOP components written in PHP
                    Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


                    PHP Reviews - Reviews of PHP books and other products


                    Metastorage - Data object relational mapping layer generator

                    Comment

                    • Lothar Scholz

                      #25
                      Re: PHP compiler

                      Manuel Lemos <mlemos@acm.org > wrote in message news:<c2ljlo$1u 41c9$1@ID-138275.news.uni-berlin.de>...[color=blue]
                      >
                      > Why not?[/color]

                      You never took a compiler construction course in a university right ?
                      It makes no sense because the semantik analyse and type interference
                      are the more important parts. Writing parsers for simple grammers are
                      done in the second year. And then there is something like register
                      optimization etc.
                      Of course it is interesting to do a JIT compiler but nothing for
                      students course.

                      I only feel sorry for the poor students who have such teachers.
                      [color=blue]
                      > If anybody writes a tool that converts PHP bytecodes into C/C++ code
                      > that when executed does the same as when the original bytecodes are
                      > interpreted by the Zend engine, that is also a compiler tool to me.[/color]

                      Dynamical typing makes this impossible if you don't change the
                      language with typedefs, if you do it will look like a interpreter. And
                      a bytecode compiler is still to a huge part nothing more then an
                      inpreter.

                      Comment

                      • Manuel Lemos

                        #26
                        Re: PHP compiler

                        Hello,

                        On 03/10/2004 03:34 AM, Lothar Scholz wrote:[color=blue][color=green]
                        >>Why not?[/color]
                        >
                        >
                        > You never took a compiler construction course in a university right ?
                        > It makes no sense because the semantik analyse and type interference
                        > are the more important parts. Writing parsers for simple grammers are
                        > done in the second year. And then there is something like register
                        > optimization etc.
                        > Of course it is interesting to do a JIT compiler but nothing for
                        > students course.
                        >
                        > I only feel sorry for the poor students who have such teachers.[/color]

                        Maybe, but the world is wide and not every university is equal
                        everywhere in the world. So, it is possible that for the original poster
                        university, the teachers could be more open minded and accept different
                        types of project proposals.

                        [color=blue][color=green]
                        >>If anybody writes a tool that converts PHP bytecodes into C/C++ code
                        >>that when executed does the same as when the original bytecodes are
                        >>interpreted by the Zend engine, that is also a compiler tool to me.[/color]
                        >
                        >
                        > Dynamical typing makes this impossible if you don't change the
                        > language with typedefs, if you do it will look like a interpreter. And
                        > a bytecode compiler is still to a huge part nothing more then an
                        > inpreter.[/color]

                        I don't know how much you know from what Zend op codes that the Zend
                        engine executes at run time. What I can tell you is that plenty can be
                        done to benefit from compilation to C/C++ .

                        Even if no significant speedup would be possible, the fact that it would
                        generate a binary executable would be already a benefit for those that
                        would like to provide their code in easy to reverse-engineer format.

                        In fact, one of the major reasons why PHP is not taken seriously in the
                        business world is the lack of real binary compiler tools or at least
                        tools that let you bundle compiled code in an easy to sell world.

                        Sure there are commercial encoders that cost money. But considering that
                        most other languages provide free tools to compile their code and
                        generate standalone applications that do not depend on commercial
                        extensions to run, many people just drop PHP as a viable solution to
                        develop their products.


                        --

                        Regards,
                        Manuel Lemos

                        PHP Classes - Free ready to use OOP components written in PHP
                        Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


                        PHP Reviews - Reviews of PHP books and other products


                        Metastorage - Data object relational mapping layer generator

                        Comment

                        • Nikola Skoric

                          #27
                          Re: PHP compiler

                          Dana Wed, 10 Mar 2004 03:57:49 -0300,
                          Manuel Lemos <mlemos@acm.org > kaze:[color=blue]
                          > Hello,
                          >
                          > On 03/10/2004 03:34 AM, Lothar Scholz wrote:[color=green][color=darkred]
                          >>>Why not?[/color]
                          >>
                          >>
                          >> You never took a compiler construction course in a university right ?
                          >> It makes no sense because the semantik analyse and type interference
                          >> are the more important parts. Writing parsers for simple grammers are
                          >> done in the second year. And then there is something like register
                          >> optimization etc.
                          >> Of course it is interesting to do a JIT compiler but nothing for
                          >> students course.
                          >>
                          >> I only feel sorry for the poor students who have such teachers.[/color]
                          >
                          > Maybe, but the world is wide and not every university is equal
                          > everywhere in the world. So, it is possible that for the original poster
                          > university, the teachers could be more open minded and accept different
                          > types of project proposals.[/color]

                          No, he isn't :-) Our compiler has to have lexical analizer, syntax
                          analizer, semantical analizer, then it has to produce some kind of
                          middle-source on which the optimization is done and that that optimized
                          mid-lang goes to assembler (I might have missed something, this week the
                          teacher started lecturing the syntax analizer, so I'm not sure to which
                          extent we'll have to go with the later parts). JIT compiler is to simple
                          to make a project like this. I mean, bytecode don't even have loops, do
                          they? Syntax tree of a bytecode program wouldn't be a much of a tree
                          anyway... more something like a bush :-) *IF* I understood the paradigma
                          of bytecode correctly.

                          --
                          Pozdrav/Regards, Nikola [Nick] Skoric.
                          "...Usne, tice-rugalice - a u oku tajac
                          Da sam kaput sa dva lica, da sam Gospo'n Propalica..."
                          http://newusers.cjb.net/ - site o Usenetu na hrvatskom!

                          Comment

                          • Kreso

                            #28
                            Re: PHP compiler

                            Nikola Skoric wrote:[color=blue]
                            > Is the a PHP compiler? A program that compiles PHP code to executable
                            > which doesn't need php interpreter to execute...[/color]

                            check this http://www.triplehash.com/content.php?id=26

                            --
                            kreso



                            Comment

                            • J Taylor

                              #29
                              Re: PHP compiler

                              [color=blue]
                              >
                              >
                              > No, he isn't :-) Our compiler has to have lexical analizer, syntax
                              > analizer, semantical analizer, then it has to produce some kind of
                              > middle-source on which the optimization is done and that that optimized
                              > mid-lang goes to assembler (I might have missed something, this week the
                              > teacher started lecturing the syntax analizer, so I'm not sure to which
                              > extent we'll have to go with the later parts). JIT compiler is to simple
                              > to make a project like this. I mean, bytecode don't even have loops, do
                              > they? Syntax tree of a bytecode program wouldn't be a much of a tree
                              > anyway... more something like a bush :-) *IF* I understood the paradigma
                              > of bytecode correctly.
                              >[/color]

                              Sorry what??? bytecode is just code ina binary format. ITs interpreted
                              by a virtual machine to allow cross-platform useage.

                              Bytecode is effectivly a simple assembler language - one that is as
                              simple as the most simple device you wish to run on - your compiler
                              could merge instructions (from the use of otehr markers in the byte
                              code) into

                              And bytecode wouldnt have loops??? what about threads?? your entire
                              stack engine system would have to be worked out (Especially for htings
                              like networking which you almost certainly want to do in a seperate
                              thread and call backwards.

                              Where you seriously going to generate a "linear" program of byte code,
                              having exploded all the loops & function calls???

                              just save yourself the time and effort and write a scheme compiler.
                              Seriously.

                              J

                              Comment

                              • Chung Leong

                                #30
                                Re: PHP compiler

                                Mr John Coggeshall is working on one. Check out his project page:


                                Uzytkownik "Nikola Skoric" <nick-news@net4u.hr> napisal w wiadomosci
                                news:MPG.1ab5b6 2d9e401c5c98971 8@localhost...[color=blue]
                                > Is the a PHP compiler? A program that compiles PHP code to executable
                                > which doesn't need php interpreter to execute...
                                >
                                > --
                                > Pozdrav/Regards, Nikola [Nick] Skoric.
                                > "...Usne, tice-rugalice - a u oku tajac
                                > Da sam kaput sa dva lica, da sam Gospo'n Propalica..."
                                > http://newusers.cjb.net/ - site o Usenetu na hrvatskom![/color]


                                Comment

                                Working...