Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60782 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21027 invoked from network); 8 Jun 2012 11:51:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2012 11:51:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:59329] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/10-20505-637E1DF4 for ; Fri, 08 Jun 2012 07:51:19 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 5250E70003D1; Fri, 8 Jun 2012 12:51:15 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 4iBJLCAvriVr; Fri, 8 Jun 2012 12:51:15 +0100 (WEST) Received: from nebm.ist.utl.pt (unknown [IPv6:2001:690:2100:4::58:1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 01D2270003C9; Fri, 8 Jun 2012 12:51:14 +0100 (WEST) Received: from localhost ([127.0.0.1] helo=nebm.ist.utl.pt) by nebm.ist.utl.pt with esmtp (Exim 4.72) (envelope-from ) id 1Scxik-0002f3-TL; Fri, 08 Jun 2012 12:51:14 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 08 Jun 2012 13:51:14 +0200 To: Nikita Popov Cc: internals PHP Organization: =?UTF-8?Q?N=C3=BAcleo_de_Engenharia_Biom=C3=A9dica_do_Insti?= =?UTF-8?Q?tuto_Superior_T=C3=A9cnico?= In-Reply-To: References: <5361275d0179dd0f3061ceabf7bde9af@nebm.ist.utl.pt> <3dfb58cfcdefa75813fa670231040c7b@nebm.ist.utl.pt> Message-ID: <972656153dbd9dedcde64a14e70e460e@nebm.ist.utl.pt> X-Sender: glopes@nebm.ist.utl.pt User-Agent: RoundCube Webmail/0.5.3 Subject: Re: [PHP-DEV] Generators in PHP From: glopes@nebm.ist.utl.pt (Gustavo Lopes) On Fri, 8 Jun 2012 13:24:49 +0200, Nikita Popov wrote: >> Are you planning on any internal API for functions to implement >> generators >> (though I really haven't thought how that would work)? > I don't think that this is possible. Generators require that the > execution context is suspended in some way and we have to that > control > only over userland code, not internal C code. > Couldn't we simulate this by saving the state in a heap allocated structure (whose exact form would depend on the generator implementation). Something like: struct generator_context { zval *(*yield_next)(struct generator_context*); } struct spec_generator_context { struct generator_context parent; int foo; } PHP_FUNCTION(get_generator) { struct spec_generator_context *ctx = emalloc(*ctx); ctx->parent.yield_next = foo_bar(); return_value = make_internal_generator(ctx); } And you could also change the yield_next pointer in foo_bar() to avoid going through goto's or switch statements. Possibly yield_next could be take the arg with double indirection and you could also completely replace the context. I understand this has the problem that the internal and userspace implementations would be markedly different. -- Gustavo Lopes