Created
May 23, 2011 03:27
-
-
Save jspahrsummers/986175 to your computer and use it in GitHub Desktop.
Tentative coroutine syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define coroutine(ARGS) \ | |
__block unsigned long ext_coroutine_line_ = 0; \ | |
\ | |
return ^(ARGS){ \ | |
for (;; ext_coroutine_line_ = 0) \ | |
switch (ext_coroutine_line_) \ | |
default: | |
#define return_coroutine \ | |
} | |
#define yield \ | |
if ((ext_coroutine_line_ = __LINE__) == 0) \ | |
case __LINE__: \ | |
; \ | |
else \ | |
return | |
id myCoroutine = | |
^{ | |
__block int myVariable = 5; | |
coroutine(int n) { | |
// do stuff | |
yield 5 + n; | |
// do more stuff | |
yield ++myVariable; | |
} | |
return_coroutine; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is very tricky And obscure...
I was trying to expand the macros, only to find it was more confusing...
//===before expand
//after expanding