2 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
8 function _return_value(x
) {
12 function co_return(x
) {
13 return new _return_value(x
);
16 const CONTINUATION
= { toString: function () "[object CONTINUATION]" };
17 const SUSPEND
= { toString: function () "[object SUSPEND]" };
19 function is_coroutine(obj
) {
21 typeof(obj
) == "object" &&
22 typeof(obj
.next
) == "function" &&
23 typeof(obj
.send
) == "function";
26 function _do_call(f
) {
31 var throw_value
= false;
42 if (x
== CONTINUATION
) {
60 stack
[stack
.length
] = f
;
66 if (x
instanceof _return_value
) {
67 if (stack
.length
== 0)
70 f
= stack
[stack
.length
- 1];
76 // Just return the value back to the function
79 if (stack
.length
== 0)
81 f
= stack
[stack
.length
- 1];
83 if (e
instanceof StopIteration
)
98 var cc = function (x
) {
101 } catch (e
if e
instanceof StopIteration
) {}
103 // Dump this error, because it indicates a programming error
107 cc
.throw = function (x
) {
110 } catch (e
if e
instanceof StopIteration
) {}
112 // Dump this error, because it indicates a programming error
118 } catch (e
if e
instanceof StopIteration
) {}
120 // Dump this error, because it indicates a programming error