Re: Generators in PHP

From: Date: Mon, 11 Jun 2012 21:12:03 +0000
Subject: Re: Generators in PHP
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-60797@lists.php.net to get a copy of this message
Can you really use setjmp and longjmp in that way safely? I thought it was only safe to longjmp "back," not "forward" - you can use them to fake exception support but that's it because you'll smash the stack otherwise. Something like that... OK, I'm thinking of this: "Similarly, C99 does not require that longjmp preserve the current stack frame. This means that jumping into a function which was exited via a call to longjmp is undefined.[6] However, most implementations of longjmp leave the stack frame intact, allowing setjmp and longjmp to be used to jump back-and-forth between two or more functions—a feature exploited for multitasking." It does not sound like something that can be done in portable C. On Mon, Jun 11, 2012 at 4:13 PM, Anatoliy Belsky <ab@php.net> wrote: > Hi, > > it'd be really cool if the implementation would do the "real" context > switch in c, which would be the true basis for spl_coroutine. The current > implementation seems not to do that. > > Context switch in c would be comparable with threads. In fact coroutines > would be a comensation for lacking threads functionality in php, as they > are already implemented on most popular platforms. However, it would > require some platform specific libs (fibers on windows, setjmp and longjmp > on unix(like)). > > Coroutines in c are per se thread safe, so implementing them once would > not hurt both ts and nts. Additionally, in some cases coroutines can even > have advantages over the "usual" preemptive threads. > > Regards > > Anatoliy > > Am Mi, 6.06.2012, 04:42 schrieb Laruence: >> On Wed, Jun 6, 2012 at 10:27 AM, Laruence <laruence@php.net> wrote: >>> On Wed, Jun 6, 2012 at 10:15 AM, Laruence <laruence@php.net> wrote: >>>> Hi Nikita: >>>> >>>>    the most important part to me is how did you implemented >>>> yield >>>> keyword,   is there a whole patch file I can look into? >>> Nervermind,  I will check the branch out later >>> >>> thanks >> >> After a quick look,  I think the main idea should goes to two parts: >> >> 1. implement yield (Zend) >> 2. implement spl_generators but not generator class (Spl) >> >> then we can implement spl_coroutine later base on this.  what do you >> think? >> >> thanks >>>> >>>>    what will happen if you use a yield in a >>>> normal function? >>>> >>>>    actually,  I tried to implemented coroutine, but since I could not >>>> find a way to make zend_execute interruptable, then I didn't make it. >>>> >>>>    so, I am really interesting of this tech-specific :) >>>> >>>> thanks >>>> >>>> On Wed, Jun 6, 2012 at 1:35 AM, Nikita Popov >>>> <nikita.ppv@googlemail.com> wrote: >>>>> Hi internals! >>>>> >>>>> In the last few days I've created a proof of concept implementation >>>>> for generators in PHP. It's not yet complete, but the basic >>>>> functionality is there: >>>>> https://github.com/nikic/php-src/tree/addGeneratorsSupport4 >>>>> a##½i@$s_P ‘V/ >>>>> >>>>> The implementation is outlined in the RFC-stub here: >>>>> https://wiki.php.net/rfc/generators >>>>> >>>>> Before going any further I'd like to get some comments about what you >>>>> think of adding generator support to PHP. >>>>> >>>>> If you don't know what generators are you should have a look at the >>>>> "Introduction" section in the above RFC or in the Python >>>>> documentation >>>>> at http://wiki.python.org/moin/Generators. >>>>> >>>>> Nikita >>>>> >>>>> -- >>>>> PHP Internals - PHP Runtime Development Mailing List >>>>> To unsubscribe, visit: >>>>> http://www.php.net/unsub.php >>>>> >>>> >>>> >>>> >>>> -- >>>> Laruence  Xinchen Hui >>>> http://www.laruence.com/ >>> >>> >>> >>> -- >>> Laruence  Xinchen Hui >>> http://www.laruence.com/ >> >> >> >> -- >> Laruence  Xinchen Hui >> http://www.laruence.com/ >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Tom Boutell P'unk Avenue 215 755 1330 punkave.com window.punkave.com

« previous php.internals (#60797) next »