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 - 061recipe.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; }
.SalientComment { color: #00ffff; }
.traceContains { color: #008000; }
.cSpecial { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.Constant { color: #00a0a0; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: So far we've been calling a fixed recipe in each instruction, but we'd</span>
<span class="Comment">//: also like to make the recipe a variable, pass recipes to "higher-order"</span>
<span class="Comment">//: recipes, return recipes from recipes and so on.</span>
<span class="Comment">//:</span>
<span class="Comment">//: todo: support storing shape-shifting recipes into recipe variables and calling them</span>
<span class="Delimiter">:(scenario call_literal_recipe)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>call f<span class="Delimiter">,</span> <span class="Constant">34</span>
]
recipe f x:number <span class="Delimiter">-></span> y:number [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+mem: storing 34 in location 1</span>
<span class="Delimiter">:(scenario call_variable)</span>
recipe main [
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number <span class="Delimiter">-></span> number<span class="Delimiter">)}</span><span class="Special"> <- </span>copy f
<span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number <span class="Delimiter">-></span> number<span class="Delimiter">)},</span> <span class="Constant">34</span>
]
recipe f x:number <span class="Delimiter">-></span> y:number [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(before "End Mu Types Initialization")</span>
put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"recipe-literal"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Comment">// 'recipe' variables can store recipe-literal</span>
type_ordinal recipe = put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"recipe"</span><span class="Delimiter">,</span> Next_type_ordinal++<span class="Delimiter">);</span>
get_or_insert<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> recipe<span class="Delimiter">).</span>name = <span class="Constant">"recipe"</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Null-type is_disqualified Exceptions")</span>
if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type && contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span>
x<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span><span class="Constant">"recipe-literal"</span><span class="Delimiter">,</span> get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"recipe-literal"</span><span class="Delimiter">));</span>
x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">));</span>
<span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
CALL<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"call"</span><span class="Delimiter">,</span> CALL<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Checks")</span>
case CALL: <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
raise_error << 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> << <span class="Constant">"'call' requires at least one ingredient (the recipe to call)</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>
if <span class="Delimiter">(</span>!is_mu_recipe<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_error << 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> << <span class="Constant">"first ingredient of 'call' should be a recipe, but got "</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>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="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
case CALL: <span class="Delimiter">{</span>
<span class="Comment">// Begin Call</span>
if <span class="Delimiter">(</span>Trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span>
++Trace_stream<span class="Delimiter">-></span>callstack_depth<span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">"trace"</span><span class="Delimiter">)</span> << <span class="Constant">"indirect 'call': incrementing callstack depth to "</span> << Trace_stream<span class="Delimiter">-></span>callstack_depth << end<span class="Delimiter">();</span>
assert<span class="Delimiter">(</span>Trace_stream<span class="Delimiter">-></span>callstack_depth < <span class="Constant">9000</span><span class="Delimiter">);</span> <span class="Comment">// 9998-101 plus cushion</span>
<span class="Delimiter">}</span>
const instruction& caller_instruction = current_instruction<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>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>
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>
finish_call_housekeeping<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">,</span> ingredients<span class="Delimiter">);</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="SalientComment">//:: check types for 'call' instructions</span>
<span class="Delimiter">:(scenario call_check_literal_recipe)</span>
<span class="Special">% Hide_errors = true;</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>call f<span class="Delimiter">,</span> <span class="Constant">34</span>
]
recipe f x:boolean <span class="Delimiter">-></span> y:boolean [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+error: main: ingredient 0 has the wrong type at '1:number <- call f, 34'</span>
<span class="traceContains">+error: main: product 0 has the wrong type at '1:number <- call f, 34'</span>
<span class="Delimiter">:(scenario call_check_variable_recipe)</span>
<span class="Special">% Hide_errors = true;</span>
recipe main [
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe boolean <span class="Delimiter">-></span> boolean<span class="Delimiter">)}</span><span class="Special"> <- </span>copy f
<span class="Constant">2</span>:number<span class="Special"> <- </span>call <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe boolean <span class="Delimiter">-></span> boolean<span class="Delimiter">)},</span> <span class="Constant">34</span>
]
recipe f x:boolean <span class="Delimiter">-></span> y:boolean [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+error: main: ingredient 0 has the wrong type at '2:number <- call {1: (recipe boolean -> boolean)}, 34'</span>
<span class="traceContains">+error: main: product 0 has the wrong type at '2:number <- call {1: (recipe boolean -> boolean)}, 34'</span>
<span class="Delimiter">:(after "Transform.push_back(check_instruction)")</span>
Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_indirect_calls_against_header<span class="Delimiter">);</span> <span class="Comment">// idempotent</span>
<span class="Delimiter">:(code)</span>
void check_indirect_calls_against_header<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"--- type-check 'call' instructions inside recipe "</span> << get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name << end<span class="Delimiter">();</span>
const recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<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>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
const instruction& inst = caller<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>operation != CALL<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// error raised above</span>
const reagent& callee = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
if <span class="Delimiter">(</span>!is_mu_recipe<span class="Delimiter">(</span>callee<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// error raised above</span>
const recipe callee_header = is_literal<span class="Delimiter">(</span>callee<span class="Delimiter">)</span> ? get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> callee<span class="Delimiter">.</span>value<span class="Delimiter">)</span> : from_reagent<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>
if <span class="Delimiter">(</span>!callee_header<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
for <span class="Delimiter">(</span>long int i = <span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span>+<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">),</span> inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"ingredient "</span> << i-<span class="Comment">/*</span><span class="Comment">skip callee</span><span class="Comment">*/</span><span class="Constant">1</span> << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>callee_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
raise_error << maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"product "</span> << i << <span class="Constant">" has the wrong type at '"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
recipe from_reagent<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span>
recipe result_header<span class="Delimiter">;</span> <span class="Comment">// will contain only ingredients and products, nothing else</span>
result_header<span class="Delimiter">.</span>has_header = <span class="Constant">true</span><span class="Delimiter">;</span>
const type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">;</span>
for <span class="Delimiter">(;</span> curr<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>name == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Comment">// skip delimiter</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
for <span class="Delimiter">(;</span> curr<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span>
result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span>
<span class="Identifier">return</span> result_header<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
bool is_mu_recipe<span class="Delimiter">(</span>reagent r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe-literal"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Comment">// End is_mu_recipe Cases</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario copy_typecheck_recipe_variable)</span>
<span class="Special">% Hide_errors = true;</span>
recipe main [
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># abc def</span>
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number <span class="Delimiter">-></span> number<span class="Delimiter">)}</span><span class="Special"> <- </span>copy f <span class="Comment"># store literal in a matching variable</span>
<span class="Delimiter">{</span><span class="Constant">2</span>: <span class="Delimiter">(</span>recipe boolean <span class="Delimiter">-></span> boolean<span class="Delimiter">)}</span><span class="Special"> <- </span>copy <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number <span class="Delimiter">-></span> number<span class="Delimiter">)}</span> <span class="Comment"># mismatch between recipe variables</span>
]
recipe f x:number <span class="Delimiter">-></span> y:number [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+error: main: can't copy {1: (recipe number -> number)} to {2: (recipe boolean -> boolean)}; types don't match</span>
<span class="Delimiter">:(scenario copy_typecheck_recipe_variable_2)</span>
<span class="Special">% Hide_errors = true;</span>
recipe main [
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>recipe number <span class="Delimiter">-></span> number<span class="Delimiter">)}</span><span class="Special"> <- </span>copy f <span class="Comment"># mismatch with a recipe literal</span>
]
recipe f x:boolean <span class="Delimiter">-></span> y:boolean [
local-scope
load-ingredients
y<span class="Special"> <- </span>copy x
]
<span class="traceContains">+error: main: can't copy f to {1: (recipe number -> number)}; types don't match</span>
<span class="Delimiter">:(before "End Matching Types For Literal(to)")</span>
if <span class="Delimiter">(</span>is_mu_recipe<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">))</span> <span class="Delimiter">{</span>
raise_error << <span class="Constant">"trying to store recipe "</span> << from<span class="Delimiter">.</span>name << <span class="Constant">" into "</span> << to_string<span class="Delimiter">(</span>to<span class="Delimiter">)</span> << <span class="Constant">" but there's no such recipe</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
const recipe& rrhs = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> from<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
const recipe& rlhs = from_reagent<span class="Delimiter">(</span>to<span class="Delimiter">);</span>
for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>rrhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> rrhs<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
for <span class="Delimiter">(</span>long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i < min<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>products<span class="Delimiter">),</span> SIZE<span class="Delimiter">(</span>rrhs<span class="Delimiter">.</span>products<span class="Delimiter">));</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>rlhs<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> rrhs<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|