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
|
<!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 - 048tangle.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; }
.Constant { color: #00a0a0; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.CommentedCode { color: #6c6c6c; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Allow code for recipes to be pulled in from multiple places.</span>
<span class="Comment">//:</span>
<span class="Comment">//: TODO: switch recipe.steps to a more efficient data structure.</span>
<span class="Delimiter">:(scenario tangle_before)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">3</span>
<span class="Comment">//: while loading recipes, load before/after fragments</span>
<span class="Delimiter">:(before "End Globals")</span>
map<string <span class="Comment">/*</span><span class="Comment">label</span><span class="Comment">*/</span><span class="Delimiter">,</span> recipe> Before_fragments<span class="Delimiter">,</span> After_fragments<span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Setup")</span>
Before_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
After_fragments<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
<span class="Delimiter">:(before "End Command Handlers")</span>
else if <span class="Delimiter">(</span>command == <span class="Constant">"before"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
string label = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
recipe tmp = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
Before_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>Before_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
else if <span class="Delimiter">(</span>command == <span class="Constant">"after"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
string label = next_word<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
recipe tmp = slurp_recipe<span class="Delimiter">(</span>in<span class="Delimiter">);</span>
After_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>After_fragments[label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> tmp<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
<span class="Comment">//: after all recipes are loaded, insert fragments at appropriate labels</span>
<span class="Delimiter">:(after "int main")</span>
Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>insert_fragments<span class="Delimiter">);</span>
<span class="Delimiter">:(code)</span>
void insert_fragments<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Comment">// Copy into a new vector because insertions invalidate iterators.</span>
<span class="Comment">// But this way we can't insert into labels created inside before/after.</span>
vector<instruction> result<span class="Delimiter">;</span>
for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
const instruction inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Delimiter">{</span>
result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
if <span class="Delimiter">(</span>Before_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != Before_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
result<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>result<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> Before_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> Before_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>inst<span class="Delimiter">);</span>
if <span class="Delimiter">(</span>After_fragments<span class="Delimiter">.</span>find<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">)</span> != After_fragments<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
result<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>result<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> After_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> After_fragments[inst<span class="Delimiter">.</span>label]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>end<span class="Delimiter">());</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="CommentedCode">//? for (long long int i = 0; i < SIZE(result); ++i) { //? 1</span>
<span class="CommentedCode">//? cout << result.at(i).to_string() << '\n'; //? 1</span>
<span class="CommentedCode">//? } //? 1</span>
Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>swap<span class="Delimiter">(</span>result<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario tangle_before_and_after)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
<span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="Comment"># label1</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="traceContains">+mem: storing 0 in location 4</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">4</span>
<span class="Delimiter">:(scenario tangle_keeps_labels_separate)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
+label2
<span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label2 [
<span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label2 [
<span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="Comment"># label1</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="Comment"># 'after' fragments for earlier label always go before 'before' fragments for later label</span>
<span class="traceContains">+mem: storing 0 in location 4</span>
<span class="Comment"># label2</span>
<span class="traceContains">+mem: storing 0 in location 5</span>
<span class="traceContains">+mem: storing 0 in location 6</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">6</span>
<span class="Delimiter">:(scenario tangle_stacks_multiple_fragments)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
<span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="Comment"># 'before' fragments stack in order</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="traceContains">+mem: storing 0 in location 4</span>
<span class="Comment"># label1</span>
<span class="Comment"># 'after' fragments stack in reverse order</span>
<span class="traceContains">+mem: storing 0 in location 5</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="traceContains">+mem: storing 0 in location 6</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">6</span>
<span class="Delimiter">:(scenario tangle_supports_fragments_with_multiple_instructions)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
<span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
<span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="Comment"># label1</span>
<span class="traceContains">+mem: storing 0 in location 4</span>
<span class="traceContains">+mem: storing 0 in location 5</span>
<span class="traceContains">+mem: storing 0 in location 6</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">6</span>
<span class="Delimiter">:(scenario tangle_tangles_into_all_labels_with_same_name)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
+label1
+label1
<span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
before +label1 [
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
after +label1 [
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="Comment"># label1</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="traceContains">+mem: storing 0 in location 2</span>
<span class="Comment"># label1</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
<span class="traceContains">+mem: storing 0 in location 4</span>
<span class="Comment"># nothing else</span>
$mem: <span class="Constant">6</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|