Live data from Hacker News

PHPPHP: a PHP VM in PHP

github.com

41–50 of 52 posts

Re: PHPPHP: a PHP VM in PHP

#41

I'm surprised this wasn't done earlier. It's actually a quite common practice for a language to eventually write a compiler for it in said language; this is called bootstrapping a compiler [1], and makes the language "self-hosted". C is a notorious language in this case, and is the closest to the real chick-or-the-egg problem this is: how do you write a C compiler without a C compiler? C is often the lowest-level lan…

This isn't exactly bootstrapping a compiler. The concept there is that in the end you do not need the foreign compiler. In this case, you still need the native implementation to run the php implementation, giving it much less practicle purpose than bootsrapping compiled languages. From a theoratical perspective, this is equivelent to bootstrapping, as it is not an intrinsic property of PHP that it does not get compiled.

Re: PHPPHP: a PHP VM in PHP

#42
post #37
post #14

Earlier quoted context omitted.

Actually (according to Ritchie's description of the history of C at http://cm.bell-labs.com/cm/cs/who/dmr/chist.html ) they never wrote a C compiler in asm. Instead it was a gradual process of evolution, so the first C compiler would have been written in B; and the B compiler was itself written in B and self-hosting, bootstrapped from a B compiler written in a thing I've never heard of called TMG. None of which is to…

Calling B a high level language is something of a stretch.

Nowadays, the same can be said of C.

Re: PHPPHP: a PHP VM in PHP

#43
post #12

I'm the author of this library. I figured I'd answer a couple of questions as to why I wrote this. First, it was something that I always wanted to do. For no particular reason other than I wanted to do it. I knew it was possible, but possible and doing it are two very different things. Second, it was far easier than I thought. The time to the initial commit (basic working VM) was only about 6 hours of work. So it's n…

Brilliant , PHP source code will need a loads of cleaning one day or another anyway , could help making changes to the language ...

Anyone who could run a non-conforming PHP could just run something better.

A conforming, but massively improved (read: JIT) PHP interpreter is really the only way forward for us who are so unfortunate. The good news is that there are starting to be viable options in that space.

Re: PHPPHP: a PHP VM in PHP

#44

PHP has the wind in its sails or what? last month i got pointed to PH7 ( http://ph7.symisc.net/quick_intro.html ) which is an embeddable PHP interpreter (bytecode compiler + VM) for C/C++/Objective C host applications (amazing piece of work) and now I'm investigating this stuff.

Absolutely. The dams of NIH have begun to break down. (I've started to see teams use things like Compass instead of conclude "But I have to install Ruby?")

People are collaborating on actually finally decent solutions (Composer, PHPSpec2, Behat). I see people relying less and less upon PHP's bloated, arcane and mostly dangerous standard library, instead building reusable chunks of PHP with surprisingly acceptable (comparably beautiful) design (Goutte, Twig, Doctrine).

Drupal, which I have managed to end end up working with full time for the last few years, has finally stopped (poorly) reinventing everything it touches: http://www.garfieldtech.com/blog/off-the-island-2013 and I expect that trend to continue.

We are starting to have a decent forward-thinking and flexible frameworks and projects like PHPBB have started actually using them.

I've also seen people actually using IDEs, writing docs, specifying argument types and being aware of the concept of stepping debuggers.

Facebook has sponsored enough alternate implementations of the interpreter that I've begun to lose track, charting the massive room for improvements.

Things are genuinely starting to look better; I still lose sleep over my tools and hoop-jump laden development workflow, but I actually have hope that I might not have to by this time next year.

Re: PHPPHP: a PHP VM in PHP

#45
post #4

I thought this might be a bit similar to PyPy... turns out it's only similar in idea. But hey it looks fun, and as the author said, why not?

Here's a project which is strikingly similar to (has common tooling with) PyPy:

https://bitbucket.org/fijal/hippyvm (repo) http://morepypy.blogspot.com/2012/07/hello-everyone.html (article)

Re: PHPPHP: a PHP VM in PHP

#46
post #14

Earlier quoted context omitted.

Which you can then use to recompile your OS easily (FreeBSD, some Linux based OS's) and tune it to a specific machine / configuration. That's why people like Kernighan and Ritchie (RIP) are so well respected. They wrote C to the target language first (asm) then rewrote C in C once they had a good enough compiler. Considering that C is the cornerstone of UNIX and modern variants I'd say this is no small feat. C will b…

Actually (according to Ritchie's description of the history of C at http://cm.bell-labs.com/cm/cs/who/dmr/chist.html ) they never wrote a C compiler in asm. Instead it was a gradual process of evolution, so the first C compiler would have been written in B; and the B compiler was itself written in B and self-hosting, bootstrapped from a B compiler written in a thing I've never heard of called TMG. None of which is to…

Yes, I forgot about B. :) "Ritchie wrote a compiler using TMG which produced machine code." vs Ken Thompson's B compiler that produced threaded code.

Re: PHPPHP: a PHP VM in PHP

#48
post #43
post #12

Earlier quoted context omitted.

Brilliant , PHP source code will need a loads of cleaning one day or another anyway , could help making changes to the language ...

Anyone who could run a non-conforming PHP could just run something better. A conforming, but massively improved (read: JIT) PHP interpreter is really the only way forward for us who are so unfortunate. The good news is that there are starting to be viable options in that space.

And what are the exact problems with the current interpreter?

Re: PHPPHP: a PHP VM in PHP

#49

Earlier quoted context omitted.

Which you can then use to recompile your OS easily (FreeBSD, some Linux based OS's) and tune it to a specific machine / configuration. That's why people like Kernighan and Ritchie (RIP) are so well respected. They wrote C to the target language first (asm) then rewrote C in C once they had a good enough compiler. Considering that C is the cornerstone of UNIX and modern variants I'd say this is no small feat. C will b…

> C will be around for a long time after many of the current languages, domain specific or not, become just another wikipedia entry. Off-topic, but this is a rather amusing benchmark for irrelevance. I suspect that deletionism would not permit it to be true, either.

Can you explain what you mean? I hardly think C is a benchmark for irrelevance.

Re: PHPPHP: a PHP VM in PHP

#50
post #42

Earlier quoted context omitted.

Nowadays, the same can be said of C.

Nowadays? C was never a high level language except and wasn't designed to be. Mid-level yes. As in just above asm.

There was a time being above asm, having non-register data types, functions and libraries was considered being a high-level language. I'd consider C higher level than FORTRAN 77, for instance.

You just need to be old enough ;-)

Post reply on HN