1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 053continuation.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.traceContains { color: #008000; }
.traceAbsent { color: #c00000; }
.Constant { color: #00a0a0; }
.cSpecial { color: #008000; }
.CommentedCode { color: #6c6c6c; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.SalientComment { color: #00ffff; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Continuations are a powerful primitive for constructing advanced kinds of</span>
<span class="Comment">//: control *policies* like back-tracking. They're usually provided using a</span>
<span class="Comment">//: primitive called 'call-cc': <a href="http://en.wikipedia.org/wiki/Call-with-current-continuation)">http://en.wikipedia.org/wiki/Call-with-current-continuation)</a></span>
<span class="Comment">//: But in mu 'call-cc' is constructed out of a combination of two primitives:</span>
<span class="Comment">//: 'current-continuation', which returns a continuation, and</span>
<span class="Comment">//: 'continue-from', which takes a continuation to switch to.</span>
<span class="Comment">//: todo: implement continuations in mu's memory</span>
<span class="Delimiter">:(before "End Globals")</span>
map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> call_stack> Continuation<span class="Delimiter">;</span>
<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Setup")</span>
Continuation<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
Next_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Mu Types Initialization")</span>
type_ordinal continuation = Type_ordinal[<span class="Constant">"continuation"</span>] = Next_type_ordinal++<span class="Delimiter">;</span>
Type[continuation]<span class="Delimiter">.</span>name = <span class="Constant">"continuation"</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
CURRENT_CONTINUATION<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
Recipe_ordinal[<span class="Constant">"current-continuation"</span>] = CURRENT_CONTINUATION<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> CURRENT_CONTINUATION: <span class="Delimiter">{</span>
<span class="Comment">// copy the current call stack</span>
Continuation[Next_continuation_id] = Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">;</span> <span class="Comment">// deep copy because calls have no pointers</span>
<span class="Comment">// make sure calling the copy doesn't spawn the same continuation again</span>
++Continuation[Next_continuation_id]<span class="Delimiter">.</span>front<span class="Delimiter">().</span>running_step_index<span class="Delimiter">;</span>
products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>Next_continuation_id<span class="Delimiter">);</span>
++Next_continuation_id<span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"current-continuation"</span><span class="Delimiter">)</span> << <span class="Constant">"new continuation "</span> << Next_continuation_id << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
CONTINUE_FROM<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
Recipe_ordinal[<span class="Constant">"continue-from"</span>] = CONTINUE_FROM<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> CONTINUE_FROM: <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": first ingredient of 'continue-from' should be a continuation id generated by 'current-continuation', but got "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> c = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
Current_routine<span class="Delimiter">-></span>calls = Continuation[c]<span class="Delimiter">;</span> <span class="Comment">// deep copy; calls have no pointers</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of this instruction</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario continuation)</span>
<span class="Comment"># simulate a loop using continuations</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
<span class="Constant">2</span>:continuation<span class="Special"> <- </span>current-continuation
<span class="Delimiter">{</span>
<span class="CommentedCode">#? $print 1:number</span>
<span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span>
<span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean
<span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>
<span class="Identifier">continue</span>-from <span class="Constant">2</span>:continuation <span class="Comment"># loop</span>
<span class="Delimiter">}</span>
]
<span class="traceContains">+mem: storing 1 in location 1</span>
<span class="traceContains">+mem: storing 2 in location 1</span>
<span class="traceContains">+mem: storing 3 in location 1</span>
<span class="traceAbsent">-mem: storing 4 in location 1</span>
<span class="Comment"># ensure every iteration doesn't copy the stack over and over</span>
$current-continuation: <span class="Constant">1</span>
<span class="Delimiter">:(scenario continuation_inside_caller)</span>
<span class="CommentedCode">#? % Trace_stream->dump_layer = "all"; #? 1</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>
<span class="Constant">2</span>:continuation<span class="Special"> <- </span>loop-body
<span class="Delimiter">{</span>
<span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">3</span>
<span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean
<span class="Identifier">continue</span>-from <span class="Constant">2</span>:continuation <span class="Comment"># loop</span>
<span class="Delimiter">}</span>
]
recipe loop-body [
<span class="Constant">4</span>:continuation<span class="Special"> <- </span>current-continuation
<span class="Constant">1</span>:number<span class="Special"> <- </span>add <span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 1 in location 1</span>
<span class="traceContains">+mem: storing 2 in location 1</span>
<span class="traceContains">+mem: storing 3 in location 1</span>
<span class="traceAbsent">-mem: storing 4 in location 1</span>
<span class="SalientComment">//:: A variant of continuations is the 'delimited' continuation that can be called like any other recipe.</span>
<span class="Comment">//:</span>
<span class="Comment">//: In mu, this is constructed out of two primitives:</span>
<span class="Comment">//:</span>
<span class="Comment">//: * 'create-delimited-continuation' lays down a mark on the call</span>
<span class="Comment">//: stack and calls the provided function (it is sometimes called 'prompt')</span>
<span class="Comment">//: * 'reply-current-continuation' copies the top of the stack until the</span>
<span class="Comment">//: mark, and returns it as the response of create-delimited-continuation</span>
<span class="Comment">//: (which might be a distant ancestor on the call stack; intervening calls</span>
<span class="Comment">//: don't return)</span>
<span class="Comment">//:</span>
<span class="Comment">//: The resulting slice of the stack can now be called just like a regular</span>
<span class="Comment">//: function.</span>
<span class="Delimiter">:(scenario delimited_continuation)</span>
recipe main [
<span class="Constant">1</span>:continuation<span class="Special"> <- </span>create-delimited-continuation f:recipe <span class="Constant">12</span> <span class="Comment"># 12 is an argument to f</span>
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span>
<span class="Delimiter">{</span>
<span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Constant">1</span>:continuation<span class="Delimiter">,</span> <span class="Constant">2</span>:number <span class="Comment"># 2 is an argument to g, the 'top' of the continuation</span>
<span class="Constant">3</span>:boolean<span class="Special"> <- </span>greater-<span class="Normal">or</span>-equal <span class="Constant">2</span>:number<span class="Delimiter">,</span> <span class="Constant">8</span>
<span class="Identifier">break</span>-<span class="Normal">if</span> <span class="Constant">3</span>:boolean
loop
<span class="Delimiter">}</span>
]
recipe f [
<span class="Constant">11</span>:number<span class="Special"> <- </span>next-ingredient
<span class="Constant">12</span>:number<span class="Special"> <- </span>g <span class="Constant">11</span>:number
reply <span class="Constant">12</span>:number
]
recipe g [
<span class="Constant">21</span>:number<span class="Special"> <- </span>next-ingredient
rewind-ingredients
reply-delimited-continuation
<span class="Comment"># calls of the continuation start from here</span>
<span class="Constant">22</span>:number<span class="Special"> <- </span>next-ingredient
<span class="Constant">23</span>:number<span class="Special"> <- </span>add <span class="Constant">22</span>:number<span class="Delimiter">,</span> <span class="Constant">1</span>
reply <span class="Constant">23</span>:number
]
<span class="CommentedCode">#? ?</span>
<span class="Comment"># first call of 'g' executes the part before reply-delimited-continuation</span>
<span class="traceContains">+mem: storing 12 in location 21</span>
<span class="traceContains">+run: 2:number <- copy 5</span>
<span class="traceContains">+mem: storing 5 in location 2</span>
<span class="Comment"># calls of the continuation execute the part after reply-delimited-continuation</span>
<span class="traceContains">+run: 2:number <- call 1:continuation, 2:number</span>
<span class="traceContains">+mem: storing 5 in location 22</span>
<span class="traceContains">+mem: storing 6 in location 2</span>
<span class="traceContains">+run: 2:number <- call 1:continuation, 2:number</span>
<span class="traceContains">+mem: storing 6 in location 22</span>
<span class="traceContains">+mem: storing 7 in location 2</span>
<span class="traceContains">+run: 2:number <- call 1:continuation, 2:number</span>
<span class="traceContains">+mem: storing 7 in location 22</span>
<span class="traceContains">+mem: storing 8 in location 2</span>
<span class="Comment"># first call of 'g' does not execute the part after reply-delimited-continuation</span>
<span class="traceAbsent">-mem: storing 12 in location 22</span>
<span class="Comment"># calls of the continuation don't execute the part before reply-delimited-continuation</span>
<span class="traceAbsent">-mem: storing 5 in location 21</span>
<span class="traceAbsent">-mem: storing 6 in location 21</span>
<span class="traceAbsent">-mem: storing 7 in location 21</span>
<span class="Comment"># termination</span>
<span class="traceAbsent">-mem: storing 9 in location 2</span>
<span class="Comment">//: 'create-delimited-continuation' is like 'call' except it adds a 'reset' mark to</span>
<span class="Comment">//: the call stack</span>
<span class="Delimiter">:(before "End call Fields")</span>
<span class="Normal">bool</span> is_reset<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End call Constructor")</span>
is_reset = <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Comment">//: like call, but mark the current call as a 'reset' call before pushing the next one on it</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
CREATE_DELIMITED_CONTINUATION<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
Recipe_ordinal[<span class="Constant">"create-delimited-continuation"</span>] = CREATE_DELIMITED_CONTINUATION<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> CREATE_DELIMITED_CONTINUATION: <span class="Delimiter">{</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>is_reset = <span class="Constant">true</span><span class="Delimiter">;</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>Recipe_ordinal[current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name]<span class="Delimiter">));</span>
ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span> <span class="Comment">// drop the callee</span>
<span class="Identifier">goto</span> call_housekeeping<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Comment">//: save the slice of current call stack until the 'create-delimited-continuation'</span>
<span class="Comment">//: call, and return it as the result.</span>
<span class="Comment">//: todo: implement delimited continuations in mu's memory</span>
<span class="Delimiter">:(before "End Globals")</span>
map<<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span><span class="Delimiter">,</span> call_stack> Delimited_continuation<span class="Delimiter">;</span>
<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> Next_delimited_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Setup")</span>
Delimited_continuation<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
Next_delimited_continuation_id = <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
REPLY_DELIMITED_CONTINUATION<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
Recipe_ordinal[<span class="Constant">"reply-delimited-continuation"</span>] = REPLY_DELIMITED_CONTINUATION<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> REPLY_DELIMITED_CONTINUATION: <span class="Delimiter">{</span>
<span class="Comment">// first clear any existing ingredients, to isolate the creation of the</span>
<span class="Comment">// continuation from its calls</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>next_ingredient_to_process = <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Comment">// copy the current call stack until the most recent 'reset' call</span>
call_stack::iterator find_reset<span class="Delimiter">(</span>call_stack& c<span class="Delimiter">);</span> <span class="Comment">// manual prototype containing '::'</span>
call_stack::iterator reset = find_reset<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>reset == Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": couldn't find a 'reset' call to jump out to</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
Delimited_continuation[Next_delimited_continuation_id] = call_stack<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> reset<span class="Delimiter">);</span>
<span class="Normal">while</span> <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>begin<span class="Delimiter">()</span> != reset<span class="Delimiter">)</span> <span class="Delimiter">{</span>
--Callstack_depth<span class="Delimiter">;</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop_front<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Comment">// return it as the result of the 'reset' call</span>
products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>Next_delimited_continuation_id<span class="Delimiter">);</span>
++Next_delimited_continuation_id<span class="Delimiter">;</span>
<span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// continue to process rest of 'reset' call</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(code)</span>
call_stack::iterator find_reset<span class="Delimiter">(</span>call_stack& c<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">for</span> <span class="Delimiter">(</span>call_stack::iterator p = c<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != c<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>is_reset<span class="Delimiter">)</span> <span class="Identifier">return</span> p<span class="Delimiter">;</span>
<span class="Identifier">return</span> c<span class="Delimiter">.</span>end<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Comment">//: overload 'call' for continuations</span>
<span class="Delimiter">:(after "Begin Call")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>properties<span class="Delimiter">.</span>empty<span class="Delimiter">()</span>
&& !current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>empty<span class="Delimiter">()</span>
&& current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">"continuation"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Comment">// copy multiple calls on to current call stack</span>
assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>Delimited_continuation<span class="Delimiter">.</span>find<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> == Delimited_continuation<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": no such delimited continuation "</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Normal">const</span> call_stack& new_calls = Delimited_continuation[ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>]<span class="Delimiter">;</span>
<span class="Normal">for</span> <span class="Delimiter">(</span>call_stack::const_reverse_iterator p = new_calls<span class="Delimiter">.</span>rbegin<span class="Delimiter">();</span> p != new_calls<span class="Delimiter">.</span>rend<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span>
Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>*p<span class="Delimiter">);</span>
++current_step_index<span class="Delimiter">();</span> <span class="Comment">// skip past the reply-delimited-continuation</span>
ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span> <span class="Comment">// drop the callee</span>
<span class="Identifier">goto</span> call_housekeeping<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|