haXe/PHP Alpha 2 Status

The second release of haXe/PHP is available.

I would like to discuss here the development status of the project and maybe receive some feedback.

First of all, my todo list is almost empty and this is a good thing. The generator and the class libraries have made a big step forward from the first alpha. I consider the generator usable and I am actually using it for two small projects I am developing.

The last step I have to accomplish before passing to the beta status is to workaround some edge cases on strings and arrays. In the current implementation, strings (and arrays) are not encapsulated in objects and the compiler tries to resolve any occurrences in the following way:


"mystring".substr(0, 2);

is generated as:


php_Boot::substr("mystring", 0, 2);

The big advantage of this is that the code is fast but it leaves quite a big problem behind:


var d : Dynamic = "mystring";
d.substr(0, 2);

generates:


$d = "mystring";
$d->substr(0, 2);

In this case the compiler cannot correctly interpret the code and generates an invalid field access on a string value. The most obvious solution is to drop the native implementation and wrap strings (and arrays) into objects as Neko does … I’ve tried it and it has been painful … not the implementation of course but the performances have dropped to unusable. My full test suite that usually took a few milliseconds to be executed, passed to take a few (too much) seconds. The other solution, the one I am trying to figure out how to implement, is to wrap into objects only those occurrences that are not known for sure. So the above example would be transformed into:


$d = php_Boot::__box("mystring"); // now $d is an instance of php_HString
$d->substr(0, 2);

where __box is a function that makes a runtime typecheck on its argument and wraps it in a proper object if required. This function comes with the complementary __unbox that makes the reverse. This seems a good solution to me but I know it will not be easy to implement because the compiler will have to make a lot of look-ups to match the expected types with the passed types …. maybe Nicolas has some good advices on this ;-)

The other issue is the standard library. Many of the classes in the neko package have been implemented in php (Lib, Sys, SPOD and db related, File, Web …) and the idea is to cover the full package so that we can switch from and to the two platforms easily. To make it even easier, a neutral package exists that maps to the platform in use. So neutral.Web will automatically map to neko.Web or php.Web.

Some classes have not been ported yet because they extend the Input/Output classes. Those two classes are neko specific but in the haXe 2.0 they will become cross-platform using the new Bytes class. Because I am lazy I will wait for haXe 2.0 to implement them for PHP.

 

Comments are closed.