Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 18, 2004 most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
"The most portable coroutine solution I have seen in C is at http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html and relies on the infamous "Duff's device" in order to do its magic of jumping back into the middle of a C routine (it uses a switch statement as a sort of computed goto). A good hack, and written in fully portable ANSI C." (from: http://nebuladevice.sourceforge.net/cgi-bin/twiki/view/Nebula/FiberMicrothread) |
January 18, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | If you weren't the same guy who posted about Stackless Python, I would've jumped on the table. Now, I have to ask you, what's your agenda? |
January 18, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | In article <buf189$1krd$1@digitaldaemon.com>, Georg Wrede says... > >If you weren't the same guy who posted about Stackless Python, I would've jumped on the table. > >Now, I have to ask you, what's your agenda? > Collect all the info, and let Walter decide :-) |
January 20, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | nice thingies, played a bit in D with it (see code below). btw in Python you do have the keyword "yield" - used for generators - which does stuff like this, there you can do something like this: for x in array: doit(x) after the last occurrence an exception is thrown (I believe), this exception indicates that the iteration is finished. bye, roel ============================================= char[uint] enumerate( char[] s ) { static uint state = 0; static uint index = 0; char[uint] ti; switch (state) { case 0: for ( ; index<s.length; ++index ) { state = 1; ti[index] = s[index]; return ti; case 1: } return ti; } } void main() { char[] s = "hello"; char[uint] ci; while ( cast(bool)(ci = enumerate(s))) printf( "%d -> %c\n", ci.keys[0],ci.values[0]); } |
January 21, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | Looks like finally a legitimate use of the __LINE__ macro besides cross-compilation and leak tracking. This is why language support is so important for coroutines/fibers/whatever you call them. Sean <nobody@no.where> wrote in message news:buessj$1dg1$1@digitaldaemon.com... > > "The most portable coroutine solution I have seen in C is at > > http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html > > and relies on the infamous "Duff's device" in order to do its magic of jumping > back into the middle of a C routine (it uses a switch statement as a sort of > computed goto). A good hack, and written in fully portable ANSI C." > > > (from: > http://nebuladevice.sourceforge.net/cgi-bin/twiki/view/Nebula/FiberMicrothread) |
January 21, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | In article <bule3p$2sjc$1@digitaldaemon.com>, Sean L. Palmer says... > >This is why language support is so important for coroutines/fibers/whatever you call them. > ><nobody@no.where> wrote in message news:buessj$1dg1$1@digitaldaemon.com... >> "The most portable coroutine solution I have seen in C is at >> http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html >> and relies on the infamous "Duff's device" in order to do >> its magic of jumping back into the middle of a C routine (it >> uses a switch statement as a sort of computed goto). A good hack, >> and written in fully portable ANSI C." Maybe we should try to figure out what the absolute minimum hacking by Walter would be, that enables us to implement help for this in D? I don't mean anything final and fancy, or perfect, just the minimum so that one can implement this particular solution in D with less brittle results and somewhat less coding. I may have some ideas, but they're still just embryonic. |
January 23, 2004 Re: most portable coroutine implementation (in C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | His iterator stuff, opApply, is getting really close. Sean "Georg Wrede" <Georg_member@pathlink.com> wrote in message news:bulluv$6tj$1@digitaldaemon.com... > In article <bule3p$2sjc$1@digitaldaemon.com>, Sean L. Palmer says... > > > >This is why language support is so important for coroutines/fibers/whatever you call them. > > Maybe we should try to figure out what the absolute minimum hacking by Walter would be, that enables us to implement help for this in D? > > I don't mean anything final and fancy, or perfect, just the minimum so that one can implement this particular solution in D with less brittle results and somewhat less coding. > > I may have some ideas, but they're still just embryonic. |
Copyright © 1999-2021 by the D Language Foundation