Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62316 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96735 invoked from network); 20 Aug 2012 21:55:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 21:55:31 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:56558] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/90-28202-252B2305 for ; Mon, 20 Aug 2012 17:55:31 -0400 Received: by lahl5 with SMTP id l5so3628459lah.29 for ; Mon, 20 Aug 2012 14:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=cO/sMCfbvsfPy4ouPJlzCcmTVtfH68WjpIzhZcCASUA=; b=DwMMoGphnLtV36sGWfj3ZYikn+9J1ehNwS/tmqu1DIG6pb2apQHH9h1ESOQUQ8rRhN FCNCxpgl+psOJMx9J0dvgtyNHLgRMTs//J/IVV8Ad9c5kJ5xrrgL7aOtE1VSQTQ999vz z0jRqHjVeIxs8o2GSIy/t/mIio59qxUpmvYNSaPapi1lyRDXdJTOrLTI+7YcWYveU8iY OQQaL4iyWta7ZAdMuU4L+LF3HDCoNI78I33Y82bTNBoNb43GlYvZxvEcccWEMkK2UlWu VRhWhk4/Wa0UnXM2rr5orJwrBGyPP47YP8IJHPlocZVtJ3xU2VyyyN6/GMDPz+OKt3T9 e8yA== MIME-Version: 1.0 Received: by 10.152.113.68 with SMTP id iw4mr15323850lab.50.1345499727832; Mon, 20 Aug 2012 14:55:27 -0700 (PDT) Received: by 10.152.122.51 with HTTP; Mon, 20 Aug 2012 14:55:27 -0700 (PDT) In-Reply-To: <503298F2.6090801@gmail.com> References: <503171CB.3090609@sugarcrm.com> <50317E51.4090305@lerdorf.com> <503225D8.4040900@gmail.com> <503298F2.6090801@gmail.com> Date: Mon, 20 Aug 2012 23:55:27 +0200 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Generators From: nikita.ppv@gmail.com (Nikita Popov) On Mon, Aug 20, 2012 at 10:07 PM, =C1ngel Gonz=E1lez wr= ote: > On 20/08/12 15:12, Nikita Popov wrote: >>> You could not decorate it and rely instead on the presence of the yield >>> keyword, but parsers will thank knowing about it from the start rather >>> than realising at mid-parsing that the function is a completely >>> different beast. >> No, parsers don't care about this. It's trivial to detect in both cases. >> >> Nikita > Yes, it's trivial to detect, but how much work is for it to do so? > Suppose the parser reads php code and outputs machine instructions. When > it encouters a function(), it adds the function prologue, goes reserving > stack > space for the variables it encounters, and so on. Then you find a yield > keyword. > Options: > - Discard the generated code and go back to the function begin, using > this time > an storage into an object instead of the stack. > - Copy all the state to an object and return it. > - Add an initial pass checking which functions are generators. > > PHP being a dynamic language, it may be able to move the function variabl= es > to a class. But it's not trivial for any parser. Sorry, I don't understand what we are arguing about here. I implemented this. I did the parser changes for this feature. And I told you that they were simple either way (both with keyword, as in the initial implementation, and without keyword, as in the current implementation). For 3rd parties (like IDEs) it is even simpler because their parsers are AST-based (unlike PHP's own parser), so they shouldn't care at all. Honestly, I stopped understanding what this whole discussion is about around ~100 mails ago. Nikita