Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81921 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80319 invoked from network); 5 Feb 2015 13:07:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 13:07:26 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.171 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:64382] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/9A-27691-D0B63D45 for ; Thu, 05 Feb 2015 08:07:26 -0500 Received: by mail-vc0-f171.google.com with SMTP id hq12so402369vcb.2 for ; Thu, 05 Feb 2015 05:07:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=DDv+hFSYrtDdMA2kgz53rDJYF4vhqBysdmWEWD8T7pw=; b=hKymipEhpjD0uCkwWxI5HM0e0BJEnqz0l5sfs5cLlc9HjShFqs2Rs17izPDOuDVfnY T2ZXmOvmP3HDrFEB02ecZo3hFYAsJuRmSroQtwmxC2ABcqUUhipUeE0BIZt5Kov5lZ9c z94kVeN9nLvhbPpwVHzrHPVtjgkIcabv4sstP91QmaLS76tor1HvvUGjf5QK5WbiY9ox 5y2XdrOuFNZdp7CNWrXo99oiclQ8QOi/Pgcdhnq19c+uvNVoezjtsVWRKz9gSjQPj14i LkDhxPXCpD+/7PQ/4T/cYfJ8BXVUM1ZRaRpuLit/EhgQxijZCXFItEnGBHDnyarhGayT jC4g== X-Gm-Message-State: ALoCoQkNb+vBxjEvsGakyTq0/3dFp1/2NnQNouO0n67C5vgd8CGBYrrbmzArOto8SR9dmvoJMGhf6X8t7SjknPg/Xr2ZCl9J6SVpUNMknjlg6LWGfR1UK0sNuwCOR/fTLUSECWDbHapG5UREnYugSa8r3KUpWvwe6w== MIME-Version: 1.0 X-Received: by 10.52.238.233 with SMTP id vn9mr1712310vdc.12.1423141642108; Thu, 05 Feb 2015 05:07:22 -0800 (PST) Received: by 10.52.74.73 with HTTP; Thu, 5 Feb 2015 05:07:21 -0800 (PST) In-Reply-To: References: <7740874.yAST26hVNS@rofl> Date: Thu, 5 Feb 2015 17:07:21 +0400 Message-ID: To: Alexander Lisachenko Cc: Patrick Schaaf , PHP internals list , Yasuo Ohgaki Content-Type: multipart/alternative; boundary=001a1135f1ce0b15e2050e56fcd7 Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --001a1135f1ce0b15e2050e56fcd7 Content-Type: text/plain; charset=UTF-8 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.it@gmail.com> wrote: > > 2015-02-05 15:32 GMT+03:00 Dmitry Stogov : > >> 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? > --001a1135f1ce0b15e2050e56fcd7--