At this moment, I don't have any plans related to implementation of hook-able compiler. However the first step was already done, introducing "zend_ast_process" callback. In general it's should be possible to provide PHP API to manipulate with AST and write compiler extensions in PHP. Looks promising.. :) Anyway, If you are interested - start working on it.
Thanks. Dmitry. On Thu, Feb 5, 2015 at 3:42 PM, Alexander Lisachenko < lisachenko...@gmail.com> wrote: > > 2015-02-05 15:32 GMT+03:00 Dmitry Stogov <dmi...@zend.com>: > >> Hi Alexander, >> >> Defining contracts through doc-comments is also possible, but this way is >> not native. >> On the other hand, if you already have this implemented, we may just >> reuse it. >> > > > Thanks, Dmitry! This would be a really nice feature on engine-level. > Ideally, for PHP7-8, I would like to see a hook system from compile-level > to userland, to define a language extension. This feature is highly > required for custom DSLs and much more. DbC technique can be also > implemented as parse-time weaver. E.g. we define a parser-extension: > > register_parser_extension(ContractExtension::class); > > this class will receive an AST of PHP file and check interesting nodes. > This node can be annotation or something else: > > [Contract::Invariant => $this->value > 0] > class Test { > public $value = 100; > public function foo($newValue) { > $this->value = $newValue; > } > } > > and parser extension change the compiled source code by inserting this > check into methods: > > [Contract::Invariant => $this->value > 0] > class Test { > public $value = 100; > public function foo($newValue) { > $this->value = $newValue; > assert($this->value > 0); // Inserted by parser extension (via > opcodes) > } > } > > Is it possible to do this? >