Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* core/callcc.c: bug in continuations. needed to send back
self
ra…
…ther than `cl` from the yield. * test: a few tests of continuations.
- Loading branch information
_why
committed
Jul 17, 2009
1 parent
3234618
commit 2d18fee
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
names = ("Freddie", "Herbie", "Ron", "Max", "Ringo") | ||
goto = here | ||
name = names pop | ||
(name, "\n") join print | ||
if (name != "Ron"): goto (). | ||
# Ringo | ||
# Max | ||
# Ron | ||
# nil |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Exception = | ||
class (msg, mark): | ||
/message = msg | ||
/mark = mark | ||
/ignored = false. | ||
|
||
Exception resume = (): | ||
/ignored = true | ||
"RESUMING\n" print | ||
m = /mark | ||
m (). | ||
|
||
SCOPES = () | ||
|
||
throw = (msg): | ||
e = Exception (msg, here) | ||
if (! e /ignored): | ||
s = SCOPES last | ||
c = s (0), s (0) = e | ||
c (). | ||
nil. | ||
|
||
try = (block, catch): | ||
cc = () | ||
c = here | ||
if (! cc (0)): | ||
cc push (c) | ||
SCOPES push (cc) | ||
block () | ||
. else: | ||
catch (SCOPES last (0)). | ||
. | ||
|
||
1 to 2 (x): | ||
try (: | ||
"TRY\n" print | ||
if (x == 1): | ||
throw ("TRY ERROR!\n"). | ||
"SUCCESS\n" print. | ||
|
||
(e): | ||
e /message print | ||
e resume. | ||
) | ||
. | ||
|
||
nil | ||
|
||
# TRY | ||
# TRY ERROR! | ||
# RESUMING | ||
# SUCCESS | ||
# TRY | ||
# SUCCESS | ||
# nil |