about summary refs log tree commit diff stats
path: root/html/003trace.test.cc.html
blob: 439e8613efaeaf08ef1be4bdb67625dc310ae05b (plain) (blame)
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
<!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 - 003trace.test.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<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-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.cSpecial { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Normal">void</span> test_trace_check_compares<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer: foo&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_check_ignores_other_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 2&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;bar&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: foo&quot;</span><span class="Delimiter">);</span>
  CHECK_TRACE_DOESNT_CONTAIN<span class="Delimiter">(</span><span class="Constant">&quot;test layer 2: foo&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_check_ignores_leading_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">too little whitespace</span><span class="Comment">*/</span><span class="Constant">&quot;foo&quot;</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">);</span>
  CHECK<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">too much whitespace</span><span class="Comment">*/</span><span class="Constant">&quot;  foo&quot;</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_check_ignores_other_lines<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;bar&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: foo&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_check_ignores_other_lines2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;bar&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: bar&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: foo&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_ignores_trailing_whitespace2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo &quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: foo&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_orders_across_layers<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 2&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;bar&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;qux&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1: foo^Dtest layer 2: bar^Dtest layer 1: qux^D&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_supports_count<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;foo&quot;</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_supports_count2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;bar&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK_EQ<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trace_count_ignores_trailing_whitespace<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;foo</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  CHECK<span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;test layer 1&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;foo&quot;</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Comment">// pending: DUMP tests</span>
<span class="Comment">// pending: readable_contents() adds newline if necessary.</span>
<span class="Comment">// pending: raise also prints to stderr.</span>
<span class="Comment">// pending: raise doesn't print to stderr if Hide_errors is set.</span>
<span class="Comment">// pending: raise doesn't have to be saved if Hide_errors is set, just printed.</span>
<span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL.</span>
<span class="Comment">// pending: raise prints to stderr if Trace_stream is NULL even if Hide_errors is set.</span>
<span class="Comment">// pending: raise &lt;&lt; ... die() doesn't die if Hide_errors is set.</span>

^L

<span class="Comment">// can't check trace because trace methods call 'split'</span>

<span class="Normal">void</span> test_split_returns_at_least_one_elem<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  vector&lt;string&gt; result = split<span class="Delimiter">(</span><span class="Constant">&quot;&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;,&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_split_returns_entire_input_when_no_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  vector&lt;string&gt; result = split<span class="Delimiter">(</span><span class="Constant">&quot;abc&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;,&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">&quot;abc&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_split_works<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  vector&lt;string&gt; result = split<span class="Delimiter">(</span><span class="Constant">&quot;abc,def&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;,&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">&quot;abc&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">&quot;def&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_split_works2<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  vector&lt;string&gt; result = split<span class="Delimiter">(</span><span class="Constant">&quot;abc,def,ghi&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;,&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">&quot;abc&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">&quot;def&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">&quot;ghi&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_split_handles_multichar_delim<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  vector&lt;string&gt; result = split<span class="Delimiter">(</span><span class="Constant">&quot;abc,,def,,ghi&quot;</span><span class="Delimiter">,</span> <span class="Constant">&quot;,,&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>size<span class="Delimiter">(),</span> <span class="Constant">3</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> <span class="Constant">&quot;abc&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">),</span> <span class="Constant">&quot;def&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>result<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">),</span> <span class="Constant">&quot;ghi&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">void</span> test_trim<span class="Delimiter">()</span> <span class="Delimiter">{</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot; &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;  &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;a&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot; a&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;  a&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;  ab&quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;ab&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;a &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;a  &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;ab  &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;ab&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot; a &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;  a  &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;a&quot;</span><span class="Delimiter">);</span>
  CHECK_EQ<span class="Delimiter">(</span>trim<span class="Delimiter">(</span><span class="Constant">&quot;  ab  &quot;</span><span class="Delimiter">),</span> <span class="Constant">&quot;ab&quot;</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
class="o">="Delimiter">()</span> <span class="Delimiter">{</span> restore_snapshots<span class="Delimiter">();</span> Recipe_ordinal_snapshot = Recipe_ordinal_snapshot_stash<span class="Delimiter">;</span> Recipe_ordinal_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Recipe_snapshot = Recipe_snapshot_stash<span class="Delimiter">;</span> Recipe_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Type_ordinal_snapshot = Type_ordinal_snapshot_stash<span class="Delimiter">;</span> Type_ordinal_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Type_snapshot = Type_snapshot_stash<span class="Delimiter">;</span> Type_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Name_snapshot = Name_snapshot_stash<span class="Delimiter">;</span> Name_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> Recipe_variants_snapshot = Recipe_variants_snapshot_stash<span class="Delimiter">;</span> Recipe_variants_snapshot_stash<span class="Delimiter">.</span>clear<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Load Recipes&quot;)</span> load<span class="Delimiter">(</span>string<span class="Delimiter">(</span> <span class="Constant">&quot;recipe interactive [</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">)</span> + <span class="Comment">// just a dummy version to initialize the Recipe_ordinal and so on</span> <span class="Constant">&quot;]</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;recipe sandbox [</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;local-scope</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;screen:address:screen &lt;- new-fake-screen 30, 5</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;r:number/routine_id &lt;- start-running interactive, screen</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;limit-time r, 100000/instructions</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;wait-for-routine r</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;sandbox-state:number &lt;- routine-state r/routine_id</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;completed?:boolean &lt;- equal sandbox-state, 1/completed</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;output:address:array:character &lt;- $most-recent-products</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;errors:address:array:character &lt;- save-errors</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;stashes:address:array:character &lt;- save-app-trace</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;$cleanup-run-interactive</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;return output, errors, screen, stashes, completed?</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> + <span class="Constant">&quot;]</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">);</span> <span class="Comment">//: adjust errors in the sandbox</span> <span class="Delimiter">:(after &quot;string maybe(string s)&quot;)</span> <span class="Normal">if</span> <span class="Delimiter">(</span>s == <span class="Constant">&quot;interactive&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">&quot;&quot;</span><span class="Delimiter">;</span> <span class="Delimiter">:(scenario run_interactive_comments)</span> def main [ <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [<span class="Comment"># ab</span> add <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">2</span>] <span class="Constant">2</span>:address:array:character<span class="Special"> &lt;- </span>run-interactive <span class="Constant">1</span>:address:array:character <span class="Constant">3</span>:array:character<span class="Special"> &lt;- </span>copy *<span class="Constant">2</span>:address:array:character ] <span class="traceContains">+mem: storing 52 in location 4</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> _START_TRACKING_PRODUCTS<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$start-tracking-products&quot;</span><span class="Delimiter">,</span> _START_TRACKING_PRODUCTS<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> _START_TRACKING_PRODUCTS: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> _START_TRACKING_PRODUCTS: <span class="Delimiter">{</span> Track_most_recent_products = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> _STOP_TRACKING_PRODUCTS<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$stop-tracking-products&quot;</span><span class="Delimiter">,</span> _STOP_TRACKING_PRODUCTS<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> _STOP_TRACKING_PRODUCTS: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> _STOP_TRACKING_PRODUCTS: <span class="Delimiter">{</span> Track_most_recent_products = <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> _MOST_RECENT_PRODUCTS<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$most-recent-products&quot;</span><span class="Delimiter">,</span> _MOST_RECENT_PRODUCTS<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> _MOST_RECENT_PRODUCTS: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> _MOST_RECENT_PRODUCTS: <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>new_mu_string<span class="Delimiter">(</span>Most_recent_products<span class="Delimiter">));</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> SAVE_ERRORS<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;save-errors&quot;</span><span class="Delimiter">,</span> SAVE_ERRORS<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> SAVE_ERRORS: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> SAVE_ERRORS: <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>trace_error_contents<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> SAVE_APP_TRACE<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;save-app-trace&quot;</span><span class="Delimiter">,</span> SAVE_APP_TRACE<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> SAVE_APP_TRACE: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> SAVE_APP_TRACE: <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>trace_app_contents<span class="Delimiter">());</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> _CLEANUP_RUN_INTERACTIVE<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$cleanup-run-interactive&quot;</span><span class="Delimiter">,</span> _CLEANUP_RUN_INTERACTIVE<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> _CLEANUP_RUN_INTERACTIVE: <span class="Delimiter">{</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> _CLEANUP_RUN_INTERACTIVE: <span class="Delimiter">{</span> run_code_end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario &quot;run_interactive_converts_result_to_text&quot;)</span> def main [ <span class="Comment"># try to interactively add 2 and 2</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [add <span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">2</span>] <span class="Constant">2</span>:address:array:character<span class="Special"> &lt;- </span>run-interactive <span class="Constant">1</span>:address:array:character <span class="Constant">10</span>:array:character<span class="Special"> &lt;- </span>copy <span class="Constant">2</span>:address:array:character/lookup ] <span class="Comment"># first letter in the output should be '4' in unicode</span> <span class="traceContains">+mem: storing 52 in location 11</span> <span class="Delimiter">:(scenario &quot;run_interactive_returns_text&quot;)</span> def main [ <span class="Comment"># try to interactively add 2 and 2</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [ <span class="Normal">x</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [a] <span class="Normal">y</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [b] <span class="Normal">z</span>:address:array:character<span class="Special"> &lt;- </span>append x:address:array:character<span class="Delimiter">,</span> y:address:array:character ] <span class="Constant">2</span>:address:array:character<span class="Special"> &lt;- </span>run-interactive <span class="Constant">1</span>:address:array:character <span class="Constant">10</span>:array:character<span class="Special"> &lt;- </span>copy <span class="Constant">2</span>:address:array:character/lookup ] <span class="Comment"># output contains &quot;ab&quot;</span> <span class="traceContains">+mem: storing 97 in location 11</span> <span class="traceContains">+mem: storing 98 in location 12</span> <span class="Delimiter">:(scenario &quot;run_interactive_returns_errors&quot;)</span> def main [ <span class="Comment"># run a command that generates an error</span> <span class="Constant">1</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [x:number<span class="Special"> &lt;- </span>copy <span class="Constant">34</span> get x:number<span class="Delimiter">,</span> foo:offset] <span class="Constant">2</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">3</span>:address:array:character<span class="Special"> &lt;- </span>run-interactive <span class="Constant">1</span>:address:array:character <span class="Constant">10</span>:array:character<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>:address:array:character/lookup ] <span class="Comment"># error should be &quot;unknown element foo in container number&quot;</span> <span class="traceContains">+mem: storing 117 in location 11</span> <span class="traceContains">+mem: storing 110 in location 12</span> <span class="traceContains">+mem: storing 107 in location 13</span> <span class="traceContains">+mem: storing 110 in location 14</span> <span class="Comment"># ...</span> <span class="Delimiter">:(scenario run_interactive_with_comment)</span> def main [ <span class="Comment"># 2 instructions, with a comment after the first</span> <span class="Constant">1</span>:address:array:number<span class="Special"> &lt;- </span><span class="Normal">new</span> [a:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> <span class="Comment"># abc</span> <span class="Normal">b</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> ] <span class="Constant">2</span>:address:array:character<span class="Delimiter">,</span> <span class="Constant">3</span>:address:array:character<span class="Special"> &lt;- </span>run-interactive <span class="Constant">1</span>:address:array:character ] <span class="Comment"># no errors</span> <span class="traceContains">+mem: storing 0 in location 3</span> <span class="Delimiter">:(before &quot;End Globals&quot;)</span> string Most_recent_products<span class="Delimiter">;</span> <span class="Delimiter">:(before &quot;End Setup&quot;)</span> Most_recent_products = <span class="Constant">&quot;&quot;</span><span class="Delimiter">;</span> <span class="Delimiter">:(before &quot;End of Instruction&quot;)</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Track_most_recent_products<span class="Delimiter">)</span> <span class="Delimiter">{</span> track_most_recent_products<span class="Delimiter">(</span>current_instruction<span class="Delimiter">(),</span> products<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> <span class="Normal">void</span> track_most_recent_products<span class="Delimiter">(</span><span class="Normal">const</span> instruction&amp; instruction<span class="Delimiter">,</span> <span class="Normal">const</span> vector&lt;vector&lt;<span class="Normal">double</span>&gt; &gt;&amp; products<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream out<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>products<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// string</span> <span class="Normal">if</span> <span class="Delimiter">(</span>i &lt; SIZE<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_string<span class="Delimiter">(</span>instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> tb_shutdown<span class="Delimiter">();</span> cerr &lt;&lt; read_mu_string<span class="Delimiter">(</span>trace_error_contents<span class="Delimiter">())</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> cerr &lt;&lt; SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;: &quot;</span><span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j &lt; SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> cerr &lt;&lt; no_scientific<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span> cerr &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span> out &lt;&lt; read_mu_string<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// End Record Product Special-cases</span> <span class="Delimiter">}</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j &lt; SIZE<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> ++j<span class="Delimiter">)</span> out &lt;&lt; no_scientific<span class="Delimiter">(</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">))</span> &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span> out &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> Most_recent_products = out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> string strip_comments<span class="Delimiter">(</span>string in<span class="Delimiter">)</span> <span class="Delimiter">{</span> ostringstream result<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>in<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> result &lt;&lt; in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">else</span> <span class="Delimiter">{</span> <span class="Normal">while</span> <span class="Delimiter">(</span>i+<span class="Constant">1</span> &lt; SIZE<span class="Delimiter">(</span>in<span class="Delimiter">)</span> &amp;&amp; in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i+<span class="Constant">1</span><span class="Delimiter">)</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> ++i<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Delimiter">}</span> <span class="Normal">int</span> stringified_value_of_location<span class="Delimiter">(</span><span class="Normal">int</span> address<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// convert to string</span> ostringstream out<span class="Delimiter">;</span> out &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address<span class="Delimiter">));</span> <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>out<span class="Delimiter">.</span>str<span class="Delimiter">());</span> <span class="Delimiter">}</span> <span class="Normal">int</span> trace_error_contents<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector&lt;trace_line&gt;::iterator p = Trace_stream<span class="Delimiter">-&gt;</span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-&gt;</span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-&gt;</span>label != <span class="Constant">&quot;error&quot;</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> out &lt;&lt; p<span class="Delimiter">-&gt;</span>contents<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>*--p<span class="Delimiter">-&gt;</span>contents<span class="Delimiter">.</span>end<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> string result = out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> truncate<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">int</span> trace_app_contents<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> ostringstream out<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector&lt;trace_line&gt;::iterator p = Trace_stream<span class="Delimiter">-&gt;</span>past_lines<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != Trace_stream<span class="Delimiter">-&gt;</span>past_lines<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-&gt;</span>depth != App_depth<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> out &lt;&lt; p<span class="Delimiter">-&gt;</span>contents<span class="Delimiter">;</span> <span class="Normal">if</span> <span class="Delimiter">(</span>*--p<span class="Delimiter">-&gt;</span>contents<span class="Delimiter">.</span>end<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> out &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> string result = out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> truncate<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Identifier">return</span> new_mu_string<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">void</span> truncate<span class="Delimiter">(</span>string&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>x<span class="Delimiter">)</span> &gt; <span class="Constant">1024</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> x<span class="Delimiter">.</span>erase<span class="Delimiter">(</span><span class="Constant">1024</span><span class="Delimiter">);</span> *x<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> = <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> *++x<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> = <span class="Constant">'.'</span><span class="Delimiter">;</span> *++++x<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> = <span class="Constant">'.'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Comment">//: simpler version of run-interactive: doesn't do any running, just loads</span> <span class="Comment">//: recipes and reports errors.</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span> RELOAD<span class="Delimiter">,</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span> put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;reload&quot;</span><span class="Delimiter">,</span> RELOAD<span class="Delimiter">);</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span> <span class="Normal">case</span> RELOAD: <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'reload' requires exactly one ingredient, but got &quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_string<span class="Delimiter">(</span>inst<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 &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'reload' should be a string, but got &quot;</span> &lt;&lt; inst<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 &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span> <span class="Normal">case</span> RELOAD: <span class="Delimiter">{</span> <span class="Comment">// conundrum: need to support repeated reloads of the same code, but not</span> <span class="Comment">// wipe out state for the current test</span> <span class="Comment">// hacky solution: subset of restore_snapshots() without restoring recipes {</span> <span class="Comment">// can't yet define containers in a test that runs 'reload'</span> Type_ordinal = Type_ordinal_snapshot<span class="Delimiter">;</span> Type = Type_snapshot<span class="Delimiter">;</span> <span class="Comment">// can't yet create new specializations of shape-shifting recipes in a test</span> <span class="Comment">// that runs 'reload'</span> Recipe_variants = Recipe_variants_snapshot<span class="Delimiter">;</span> Name = Name_snapshot<span class="Delimiter">;</span> <span class="Comment">// }</span> string code = read_mu_string<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> run_code_begin<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">should_stash_snapshots</span><span class="Comment">*/</span><span class="Constant">false</span><span class="Delimiter">);</span> routine* save_current_routine = Current_routine<span class="Delimiter">;</span> Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span> vector&lt;recipe_ordinal&gt; recipes_reloaded = load<span class="Delimiter">(</span>code<span class="Delimiter">);</span> transform_all<span class="Delimiter">();</span> Trace_stream<span class="Delimiter">-&gt;</span>newline<span class="Delimiter">();</span> <span class="Comment">// flush trace</span> Current_routine = save_current_routine<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>trace_error_contents<span class="Delimiter">());</span> run_code_end<span class="Delimiter">();</span> <span class="Comment">// wait until we're done with the trace contents</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario reload_continues_past_error)</span> def main [ local-scope <span class="Normal">x</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [recipe foo [ get <span class="Constant">1234</span>:number<span class="Delimiter">,</span> foo:offset ]] reload x <span class="Constant">1</span>:number/<span class="Special">raw &lt;- </span>copy <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 34 in location 1</span> <span class="Delimiter">:(scenario reload_can_repeatedly_load_container_definitions)</span> <span class="Comment"># define a container and try to create it (merge requires knowing container size)</span> def main [ local-scope <span class="Normal">x</span>:address:array:character<span class="Special"> &lt;- </span><span class="Normal">new</span> [ container foo [ <span class="Normal">x</span>:number <span class="Normal">y</span>:number ] recipe bar [ local-scope <span class="Normal">x</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span> ] ] <span class="Comment"># save warning addresses in locations of type 'number' to avoid spurious changes to them due to 'abandon'</span> <span class="Constant">1</span>:number/<span class="Special">raw &lt;- </span>reload x <span class="Constant">2</span>:number/<span class="Special">raw &lt;- </span>reload x ] <span class="Comment"># no errors on either load</span> <span class="traceContains">+mem: storing 0 in location 1</span> <span class="traceContains">+mem: storing 0 in location 2</span> </pre> </body> </html> <!-- vim: set foldmethod=manual : -->