Zephir as a Translator rather than Compiler


I think you should consider implementing zephir more of as a translator rather than a compiler. What do I mean by that?

To explain the request, I will explain my problem.

Well I had a really annoying problem with routing in PHALCON that I couldn't find the answer for in the documentation.

I have been using PHALCON for a while, but even though the documentation for PHALCON is not bad at all, there things that are not very well explained, or just glossed over. So I found myself trying to solve the problems through trial and error / google searches and, lately, looking through the zephir code for phalcon 2.0.0. But even though the zephir code is close enough to PHP for easy reading (unlike the PHALCON C extension code!!!), mentally stepping through the ZEP code was not cutting it. Nothing beat simply running a test case through XDEBUG to understand the logic and the ability to view the objects states.

Basically, even though the PHP extension method really provides a performance boost, it would still be nice to have a PHP version of PHALCON to use for internal development/debugging (or for use in hosting sites that don't allow the phalcon extension).

I saw that there exists a project, in which the person basically tried to implement a version of PHALCON in PHP (but unfortunately, and expectedly) the project seems to be more or less dead and stopped at an older version of PHALCON.

Again, looking through ZEP code for PHALCON 2.0.0 it seemed relatively simple to translate to PHP. But again, why bother doing a manual translation, with all the problems that creates (maintenance, typos, etc) when we could just as easily translate the zep code to PHP. That gave me the idea that, if I some how could patch your compiler, I could get it to translate the ZEP code to PHP.

So what is the problem with the current ZEPHIR Compiler code source?

Initially, this seemed to be a simple thing to do. You already had the Lexer / Parser so in theory all I had to do was plugin for different code emitter to have a PHP version of PHALCON based on the latest ZEP code.

Unfortunately, even though I tried very hard to maintain myself within the current code structure, I found that my solution was just one BIG hack. On the other hand, all I wanted to do was code a PHP emitter plugin. But again, without having to re-write or duplicate a serious amount of your code, that wasn't possible. If I fork the compiler, I am always going to have the problem of synchronizing /patching my version of the compiler in order to maintain compatibility with yours, so instead, I was hoping that we could work towards a code based in which the C Code emitter might be less coupled with the rest of the code allowing for it's subtitution or replacement by plugins.

ZEP could truly benefit from a modular system. It would allow such things as:

  1. Having a PHP version of an extension (Like the case of PHALCON) so that you could easily debug the code.
  2. pretty printers to be easily integrated, or better yet,
  3. Addons/improvements to PHP.

I personally would love to have a C Preprocessor like system in ZEP/PHP, that would allow me to have code that is included only in development and not production (i.e. asserts with zero foot print in production).

Anyway this was my idea. TIA

Not everything in Phalcon can be written in PHP, for instance, PHQL/Volt/Annotations/JSMIN/CSSMIN/Escaper/Text are written in pure C, and create a PHP implementation is just not easy

What you say is probably true, but still both the value of ZEPHIR and PHALCON is undermined by the fact that you can't generate PHP even just for debug purposes, and, after hitting my head against another problem that I'm having a hard time solving, because O can't debug the PHALCON code, I have forked the zephir compiler (https://github.com/test-to-com/zephir) and in the process o building the translator.

Actually, If ignore the existing code, more or less, it's surprisingly easy to do. Currently I'm just trying to translate the Test Extension that comes with the compiler, but, the idea that was used by zephir to extend PHP might also be usable to solve the problems you noted above.

But even a partial translation of PHALCON, as long as it covers most of the needed functions, might be better than nothing. I'll get back to this thread later on when I have a partial translation of the PHALCON code.