Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62309 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83256 invoked from network); 20 Aug 2012 20:08:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 20:08:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:38783] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/27-07742-95992305 for ; Mon, 20 Aug 2012 16:08:58 -0400 Received: by wibhq12 with SMTP id hq12so3372521wib.11 for ; Mon, 20 Aug 2012 13:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=JBNsnGdoi3RBfukytIJJinoV6l5Yin1Ua6xvnqHsds0=; b=HBizGTRJ10C/bk5jKm0rL46xnGXJ6LMksY7NQCiL2WlIw4cpRAlA10nfEAZ+fmWTnn 4XhldgG2WvyPR5VDDgHJYasb/RlqUvmM1zU71Jh8Pu0eQj2OHh8NURSwCLatuieAuEf+ pKRaM27WAuo4NJQP4YQIWqgrCB6PlzWvdik4EPdB2UqEhm0G1UUxRsNJgPfagS62d/cM 3z7uOFS+grK1pNMbtZ/i03fteTstwb4tEuBaWLYm63fO61dbecsROk57F3d+glFR9jQT NADXsNGNrAzKe0Ie4rhnKLE6bGpnxt+tWZW2OVlmzwrHfO45KlL11YM5rONp73jOC69q ps6Q== Received: by 10.216.198.10 with SMTP id u10mr7819755wen.80.1345493334616; Mon, 20 Aug 2012 13:08:54 -0700 (PDT) Received: from [192.168.1.26] (16.Red-83-49-113.dynamicIP.rima-tde.net. [83.49.113.16]) by mx.google.com with ESMTPS id z11sm44102177wiv.10.2012.08.20.13.08.52 (version=SSLv3 cipher=OTHER); Mon, 20 Aug 2012 13:08:53 -0700 (PDT) Message-ID: <503298F2.6090801@gmail.com> Date: Mon, 20 Aug 2012 22:07:14 +0200 User-Agent: Thunderbird MIME-Version: 1.0 To: Nikita Popov CC: PHP internals References: <503171CB.3090609@sugarcrm.com> <50317E51.4090305@lerdorf.com> <503225D8.4040900@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Generators From: keisial@gmail.com (=?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?=) 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 variables to a class. But it's not trivial for any parser.