HipHop: PHP to C++ Compiler
“HipHop for PHP isn’t technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features — such as eval() — in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP’s runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.“ (Haiping Zhao) [HipHop for PHP: Move Fast]
Given the totally adhock way PHP is structured combined with the fact that Zhao claims his compiler is not a compiler but a “source code transformer” makes me wonder what exactly is going on. These steps the transformer takes to do it’s transforming look suspiciously like compiler steps:
Whenever I heard people redefine the term “compiler” it usually turned out they were hand coding a recursive decent parser. I know, it’s easy to bash something you have no experience with, but if someone is talking about “reimplementation of PHP’s runtime system” any professional-coder should raise an eyebrow. Besides, would you want to clone all that PHP magic stuff into a new runtime system? Next to a PHP compiler, Zaho is also writing a PHP interpreter: “We have also developed HPHPi, which is an experimental interpreter designed for development. When using HPHPi you don’t need to compile your PHP source code before running it. It’s helped us catch bugs in HipHop itself and provides engineers a way to use HipHop without changing how they write PHP.“ My guess is that facebook would have been better off with a formal language that is PHP like but much simpler and mostly orthogonal. On the other hand, being well designed is no prerequisite for being popular.