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…
PHPPHP: a PHP VM in PHP
31–40 of 52 posts
Re: PHPPHP: a PHP VM in PHP
#32PHPPHP is well on its way to being a simple PHP command line debugger. To my knowledge there currently isn't a good tool for command line debugging on PHP.
phpsh[1] by Facebook is good. Ironically, it's written in Python. [1] http://www.phpsh.org/
Re: PHPPHP: a PHP VM in PHP
#33First thing is that it's clearly a very clean and high quality implementation. It's clear the author knows a substantial amount of both the implementation of the Zend engine and its semantics. This is clear from the replication of zvals, and things like separation.
However I think that it's missing most of the copy on write, reference and separation semantics. These are pretty complex so that's not unexpected. And example here is the function implementation that copies the parameter list - that's almost certainly not right. I don't see reference counts or separation in assignment either.
That said, I didn't look fully so I could be wrong.
I would recommend the author use the test suites from phc, Zend, and hiphop - that would help highlight a lot of the weird corner cases (example copying an array that had referenced in it!)
Anyway, very cool (especially impressive for 6 hours!) and I hope you go on with this :)
(Comment via phone, excuse typos)
Re: PHPPHP: a PHP VM in PHP
#34So I've studied the Zend implementation in depth as part of my phd, and I'm the author of a lot of the implementation, and all of the optimizations and static analysis in phc. So I know quite a bit about this, and looked through the implementation. First thing is that it's clearly a very clean and high quality implementation. It's clear the author knows a substantial amount of both the implementation of the Zend engi…
As far as the missing parts, yes, we know those are missing. The Zval implementation was a place-holder to let it work. Now that it's working for basic code, the goal is to refactor in an appropriate design for it. Once that happens, we can implement full copy-on-write. It's very much a work-in-progress...
As far as test cases, we've been using the Zend language test cases as part of a guide. Seeing as only about 6% of them pass right now, they are not in the repo. But eventually the goal is to port them in.
Once that happens, the next goal is to get it to host run-tests.php (the PHP core test runner).
From there, there's one goal left: self-hosting.
Thanks again!!!
Re: PHPPHP: a PHP VM in PHP
#35Re: PHPPHP: a PHP VM in PHP
#36I'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…
If I wanted to create a C compiler in C as quickly as possible and had no other tools except for an assembler, I'd probably write an interpreter for C in assembly first rather than a compiler. Then I'd write a compiler for C in C and then compile the compiler by running the compiler under the interpreter.
Re: PHPPHP: a PHP VM in PHP
#37Earlier 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…
Re: PHPPHP: a PHP VM in PHP
#38PHPPHP is well on its way to being a simple PHP command line debugger. To my knowledge there currently isn't a good tool for command line debugging on PHP.
phpsh[1] by Facebook is good. Ironically, it's written in Python. [1] http://www.phpsh.org/
Re: PHPPHP: a PHP VM in PHP
#39I'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…
Re: PHPPHP: a PHP VM in PHP
#40I'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…
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…
Off-topic, but this is a rather amusing benchmark for irrelevance. I suspect that deletionism would not permit it to be true, either.