about summary refs log blame commit diff stats
path: root/054static_dispatch.cc
blob: 79537a7ccf3b2695730adfaa17d84c8cd2887290 (plain) (tree)
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# vim: ft=cfg
#
# This is the configuration file of "rifle", ranger's file executor/opener.
# Each line consists of conditions and a command.  For each line the conditions
# are checked and if they are met, the respective command is run.
#
# Syntax:
#   <condition1> , <condition2> , ... = command
#
# The command can contain these environment variables:
#   $1-$9 | The n-th selected file
#   $@    | All selected files
#
# If you use the special command "ask", rifle will ask you what program to run.
#
# Prefixing a condition with "!" will negate its result.
# These conditions are currently supported:
#   match <regexp> | The regexp matches $1
#   ext <regexp>   | The regexp matches the extension of $1
#   mime <regexp>  | The regexp matches the mime type of $1
#   name <regexp>  | The regexp matches the basename of $1
#   path <regexp>  | The regexp matches the absolute path of $1
#   has <program>  | The program is installed (i.e. located in $PATH)
#   file           | $1 is a file
#   directory      | $1 is a directory
#   number <n>     | change the number of this command to n
#   terminal       | stdin, stderr and stdout are connected to a terminal
#   X              | $DISPLAY is not empty (i.e. Xorg runs)
#
# There are also pseudo-conditions which have a "side effect":
#   flag <flags>  | Change how the program is run. See below.
#   label <label> | Assign a label or name to the command so it can
#                 | be started with :open_with <label> in ranger
#                 | or `rifle -p <label>` in the standalone executable.
#   else          | Always true.
#
# Flags are single characters which slightly transform the command:
#   f | Fork the program, make it run in the background.
#     |   New command = setsid $command >& /dev/null &
#   r | Execute the command with root permissions
#     |   New command = sudo $command
#   t | Run the program in a new terminal.  If $TERMCMD is not defined,
#     | rifle will attempt to extract it from $TERM.
#     |   New command = $TERMCMD -e $command
# Note: The "New command" serves only as an illustration, the exact
# implementation may differ.
# Note: When using rifle in ranger, there is an additional flag "c" for
# only running the current file even if you have marked multiple files.

#-------------------------------------------
# Websites
#-------------------------------------------
# Rarely installed browsers get higher priority; It is assumed that if you
# install a rare browser, you probably use it.  Firefox/konqueror/w3m on the
# other hand are often only installed as fallback browsers.
ext x?html?, has surf,           X, flag f = surf -- file://"$1"
ext x?html?, has vimprobable,    X, flag f = vimprobable -- "$@"
ext x?html?, has vimprobable2,   X, flag f = vimprobable2 -- "$@"
ext x?html?, has dwb,            X, flag f = dwb -- "$@"
ext x?html?, has jumanji,        X, flag f = jumanji -- "$@"
ext x?html?, has luakit,         X, flag f = luakit -- "$@"
ext x?html?, has uzbl,           X, flag f = uzbl -- "$@"
ext x?html?, has uzbl-browser,   X, flag f = uzbl-browser -- "$@"
ext x?html?, has uzbl-core,      X, flag f = uzbl-core -- "$@"
ext x?html?, has midori,         X, flag f = midori -- "$@"
ext x?html?, has chromium,       X, flag f = chromium -- "$@"
ext x?html?, has opera,          X, flag f = opera -- "$@"
ext x?html?, has firefox,        X, flag f = firefox -- "$@"
ext x?html?, has seamonkey,      X, flag f = seamonkey -- "$@"
ext x?html?, has iceweasel,      X, flag f = iceweasel -- "$@"
ext x?html?, has epiphany,       X, flag f = epiphany -- "$@"
ext x?html?, has konqueror,      X, flag f = konqueror -- "$@"
ext x?html?, has elinks,          terminal = elinks "$@"
ext x?html?, has links2,          terminal = links2 "$@"
ext x?html?, has links,           terminal = links "$@"
ext x?html?, has lynx,            terminal = lynx -- "$@"
ext x?html?, has w3m,             terminal = w3m "$@"

#-------------------------------------------
# Misc
#-------------------------------------------
# Define the "editor" for text files as first action
mime ^text,  label editor = $EDITOR -- "$@"
mime ^text,  label pager  = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|csv|tex|py|pl|rb|sh|php = $EDITOR -- "$@"
!mime ^text, label pager,  ext xml|csv|tex|py|pl|rb|sh|php = "$PAGER" -- "$@"

ext 1                         = man "$1"
ext s[wmf]c, has zsnes, X     = zsnes "$1"
ext nes, has fceux, X         = fceux "$1"
ext exe                       = wine "$1"
name ^[mM]akefile$            = make

#--------------------------------------------
# Code
#-------------------------------------------
ext py  = python -- "$1"
ext pl  = perl -- "$1"
ext rb  = ruby -- "$1"
ext sh  = sh -- "$1"
ext php = php -- "$1"

#--------------------------------------------
# Audio without X
#-------------------------------------------
mime ^audio|ogg$, terminal, has mplayer  = mplayer -- "$@"
mime ^audio|ogg$, terminal, has mplayer2 = mplayer2 -- "$@"
mime ^audio|ogg$, terminal, has mpv      = mpv -- "$@"
ext midi?,        terminal, has wildmidi = wildmidi -- "$@"

#--------------------------------------------
# Video/Audio with a GUI
#-------------------------------------------
mime ^video|audio, has gmplayer, X, flag f = gmplayer -- "$@"
mime ^video|audio, has smplayer, X, flag f = smplayer "$@"
mime ^video,       has mpv,      X, flag f = mpv -- "$@"
mime ^video,       has mpv,      X, flag f = mpv --fs -- "$@"
mime ^video,       has mplayer2, X, flag f = mplayer2 -- "$@"
mime ^video,       has mplayer2, X, flag f = mplayer2 -fs -- "$@"
mime ^video,       has mplayer,  X, flag f = mplayer -- "$@"
mime ^video,       has mplayer,  X, flag f = mplayer -fs -- "$@"
mime ^video|audio, has vlc,      X, flag f = vlc -- "$@"
mime ^video|audio, has totem,    X, flag f = totem -- "$@"
mime ^video|audio, has totem,    X, flag f = totem --fullscreen -- "$@"

#--------------------------------------------
# Video without X:
#-------------------------------------------
mime ^video, terminal, !X, has mpv       = mpv -- "$@"
mime ^video, terminal, !X, has mplayer2  = mplayer2 -- "$@"
mime ^video, terminal, !X, has mplayer   = mplayer -- "$@"

#-------------------------------------------
# Image Viewing:
#-------------------------------------------
mime ^image, has eog,    X, flag f = eog -- "$@"
mime ^image, has eom,    X, flag f = eom -- "$@"
mime ^image, has sxiv,   X, flag f = sxiv -- "$@"
mime ^image, has feh,    X, flag f = feh -- "$@"
mime ^image, has mirage, X, flag f = mirage -- "$@"
mime ^image, has gimp,   X, flag f = gimp -- "$@"
ext xcf,                 X, flag f = gimp -- "$@"

#-------------------------------------------
# Documents
#-------------------------------------------
ext pdf, has llpp,     X, flag f = llpp "$@"
ext pdf, has zathura,  X, flag f = zathura -- "$@"
ext pdf, has mupdf,    X, flag f = mupdf -- "$@"
ext pdf, has apvlv,    X, flag f = apvlv -- "$@"
ext pdf, has xpdf,     X, flag f = xpdf -- "$@"
ext pdf, has evince,   X, flag f = evince -- "$@"
ext pdf, has atril,    X, flag f = atril -- "$@"
ext pdf, has okular,   X, flag f = okular -- "$@"
ext pdf, has epdfview, X, flag f = epdfview -- "$@"

ext docx?, has catdoc,       terminal = catdoc -- "$@" | "$PAGER"

ext                  sxc|xlsx?|xlt|xlw|gnm|gnumeric, has gnumeric,    X, flag f = gnumeric -- "$@"
ext                  sxc|xlsx?|xlt|xlw|gnm|gnumeric, has kspread,     X, flag f = kspread -- "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has libreoffice, X, flag f = libreoffice "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has soffice,     X, flag f = soffice "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has ooffice,     X, flag f = ooffice "$@"

ext djvu, has evince, X, flag f = evince -- "$@"
ext djvu, has atril,  X, flag f = atril -- "$@"

#-------------------------------------------
# Archives
#-------------------------------------------
# This requires atool
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz,  has als     = als -- "$@" | "$PAGER"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has als     = als -- "$@" | "$PAGER"
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz,  has aunpack = aunpack -- "$@"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has aunpack = aunpack -- "$@"

# Fallback:
ext tar|gz, has tar = tar vvtf "$@" | "$PAGER"
ext tar|gz, has tar = tar vvxf "$@"

#-------------------------------------------
# Misc
#-------------------------------------------
label wallpaper, number 11, mime ^image, X = feh --bg-scale "$1"
label wallpaper, number 12, mime ^image, X = feh --bg-tile "$1"
label wallpaper, number 13, mime ^image, X = feh --bg-center "$1"
label wallpaper, number 14, mime ^image, X = feh --bg-fill "$1"

# Define the editor for non-text files + pager as last action
              !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = ask
label editor, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = $EDITOR -- "$@"
label pager,  !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php  = "$PAGER" -- "$@"
ec1c62afd7461e605ad'>c4e143d6 ^
c561f6a9 ^

c4e143d6 ^
c561f6a9 ^
c4e143d6 ^






39017bac ^


6c96a437 ^
39017bac ^

aba49e6c ^
39017bac ^
39017bac ^






1ead3562 ^
7a84094a ^
39017bac ^
7a84094a ^
39017bac ^

7a84094a ^
39017bac ^



76b59897 ^

6c96a437 ^
c4e143d6 ^
6c96a437 ^
c4e143d6 ^
76b59897 ^
17b90929 ^
80411d01 ^
b2e4056d ^
39017bac ^
1cfcb62f ^








39017bac ^

0c1791a9 ^
0c1791a9 ^
6c96a437 ^
0c1791a9 ^
39017bac ^
5d67fac7 ^

1cfcb62f ^

5d67fac7 ^


1cfcb62f ^


39017bac ^


5d67fac7 ^
c157066c ^
5d67fac7 ^





5b22547b ^
e76a27f3 ^

5d67fac7 ^

e76a27f3 ^

5d67fac7 ^

e76a27f3 ^



5d67fac7 ^




8d72e565 ^
6c96a437 ^
1cfcb62f ^


acc4792d ^
1cfcb62f ^
acc4792d ^
1cfcb62f ^




1b76245c ^
1cfcb62f ^
1b76245c ^
1cfcb62f ^



5d67fac7 ^
1cfcb62f ^

5d67fac7 ^


6c96a437 ^
5d67fac7 ^



82177734 ^
5d67fac7 ^
39017bac ^

5d67fac7 ^
6c96a437 ^
5d67fac7 ^



fb49fd2d ^
6c96a437 ^
5d67fac7 ^



39017bac ^
5d67fac7 ^



e76a27f3 ^


6c96a437 ^
e76a27f3 ^
ce1e4d3e ^
e76a27f3 ^






6c96a437 ^
e76a27f3 ^
a9b225f7 ^
e76a27f3 ^


6c96a437 ^
e76a27f3 ^

a9b225f7 ^
e76a27f3 ^






e76a27f3 ^
6b59e986 ^
e76a27f3 ^




5d67fac7 ^
6c96a437 ^
5d67fac7 ^
ce1e4d3e ^
e76a27f3 ^
5d67fac7 ^




e76a27f3 ^
6c96a437 ^
e76a27f3 ^
a9b225f7 ^
5d67fac7 ^
7f193a0e ^
5d67fac7 ^
6c96a437 ^
5d67fac7 ^
e76a27f3 ^
a9b225f7 ^
5d67fac7 ^
691b529e ^
5d67fac7 ^



e76a27f3 ^
af023b32 ^

6b59e986 ^
e76a27f3 ^


5d67fac7 ^

6c96a437 ^
5d67fac7 ^








6c96a437 ^
5d67fac7 ^
a9b225f7 ^
5d67fac7 ^
7f193a0e ^
39017bac ^
6c96a437 ^
82177734 ^
5d67fac7 ^
a9b225f7 ^
5d67fac7 ^
7f193a0e ^
5d67fac7 ^






b24eb476 ^

6c96a437 ^
5d67fac7 ^
b24eb476 ^
5d67fac7 ^




691b529e ^
5d67fac7 ^



b24eb476 ^

6c96a437 ^
5d67fac7 ^





b24eb476 ^
6c96a437 ^
5d67fac7 ^



7f193a0e ^
39017bac ^
5d67fac7 ^
39017bac ^

5d67fac7 ^
1ead3562 ^
7a84094a ^
5d67fac7 ^
1ead3562 ^
7a84094a ^
1ead3562 ^
5d67fac7 ^


39017bac ^
5ed9bb13 ^
7a84094a ^
39017bac ^

1ead3562 ^

39017bac ^
5ed9bb13 ^
39017bac ^

5ed9bb13 ^
1ead3562 ^

39017bac ^
7a84094a ^
39017bac ^

5ed9bb13 ^
fb49fd2d ^

1ead3562 ^
7a84094a ^


d52406cc ^


fb49fd2d ^
fb49fd2d ^
7a84094a ^
fb49fd2d ^







7f193a0e ^
82177734 ^
1ead3562 ^
82177734 ^

7a84094a ^
82177734 ^



7a84094a ^
82177734 ^





76b59897 ^
1ead3562 ^
760f683f ^
76b59897 ^


7a84094a ^
76b59897 ^
760f683f ^
76b59897 ^

7a84094a ^
76b59897 ^



1ead3562 ^
760f683f ^
76b59897 ^

760f683f ^
76b59897 ^

7a84094a ^
76b59897 ^

7a84094a ^
76b59897 ^


7f193a0e ^
1ead3562 ^
7a84094a ^
7f193a0e ^
760f683f ^
1ead3562 ^
7f193a0e ^
7a84094a ^
1ead3562 ^
7f193a0e ^

fca48e92 ^


1ead3562 ^
fca48e92 ^
08f4628e ^
7a84094a ^
fca48e92 ^
7a84094a ^
fca48e92 ^
1ead3562 ^
fca48e92 ^
7a84094a ^
fca48e92 ^
691b529e ^

1ead3562 ^
7a84094a ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^




1ead3562 ^
7a84094a ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^




1ead3562 ^
7a84094a ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^
7a84094a ^
691b529e ^

1ead3562 ^
691b529e ^


81c87f08 ^
81c87f08 ^

fb9bcd34 ^


81c87f08 ^
3670fb87 ^
6c96a437 ^
9f95c745 ^
3670fb87 ^
6c96a437 ^
9f95c745 ^
81c87f08 ^

601ff75b ^

1ead3562 ^
7a84094a ^

601ff75b ^
7a84094a ^
601ff75b ^

1ead3562 ^
601ff75b ^
760f683f ^
601ff75b ^

1ead3562 ^
601ff75b ^
760f683f ^
601ff75b ^

1ead3562 ^
601ff75b ^


7874586e ^
80411d01 ^


7a84094a ^
80411d01 ^
7a84094a ^
80411d01 ^



7a84094a ^
80411d01 ^



7a84094a ^

80411d01 ^
0fb8f78c ^
0fb8f78c ^
445bc53e ^
7c9def3c ^
7a84094a ^
0fb8f78c ^
0f2781f8 ^
0fb8f78c ^

0f2781f8 ^

0fb8f78c ^



94fed202 ^
94fed202 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632




                                                                           
          
                     
 
                         

             
                                




                                                                           
                                     


                                                     

                                                                                                          






                                                              

                                          
                                              
                                                                         
                                                            




                                                              


                                                                                           
                                                                                      
                           
                                   



                       
                                                          
                                                                                          


       
                                                
                                                                                   
                                              


                                                          
                          
   
            




                                                                 
                                                    


                                                                             

                   
                                                 

                                                      
                                                                       




                   





                                       

                                                                  
 
                                                                      

                    
                                                   
                






                                                                        


                                                           
                                       

                                   
                                                 
                       






                                                                           
          
                           
 
                         

             
                                



                             

                                                                           
                                                    
                                                                                                            
                                                 
                                                                                                      
 
                                                                                                                                                  
                                               
                                                            
 








                                                                              

                                                
                                         
                                                                                                       
                                                                     
                                                      
                                

                                                                                 

                                                     


                                                        


                                                              


   
                                                                     
                                                                     





                                                                      
                            

                                                                                              

                            

                                               

                            



                                                                                                    




                                                                                                                          
                                                                                                                           
                                                                                                     


                                                                                               
                                                                                                                             
          
                                                                                        




                                                                                 
                                                                                                                          
              
                                                                                     



         
            

 


                                                                                                              
                                              



                                                                                                                   
   
                

 
                                                                                         
                                                                                      



                                                                                   
   
                                                                                



                                                                                
     



              


                                                                                                                                                  
                                              
                                       
                                                                                                                                                       






                                                                                                                             
                                                                                      
                                                                                                                       
                                                                            


                   
                                                                                

                                                                             
                                                                         






                                                                                                       
                                            
                            




                                                                                                                                                        
                                
                                              
                                       
                                                                                                                                                  
                                                                                                                        




                                       
                                                                                                                                   
                                                                                      
                                                                                                                             
                                                                            
                   
     
   
                                                                                
                                                
                                                                                                                       
                                                                         
                   
     



              
                                                                                                             

                                                
                                                                            


          

                                                                                                     
                                              








                                                                                                          
                                                                                      
                                                                          
                                                                            
                   
     
   
                                                                                
                                                
                                                                    
                                                                         
                   
     






                                                                                         

                      
                                                
                                                            
                                                                 




                                                                                    
     



                                               

                                                      
                                            





                                                                   
                                   
                                                                    



                                                                 
     
   
               

 
                                                               
          
                 
 
          
                                              
           


                              
                                                             
                     
                         

             

           
 
                              

                                                               
                     

           
 
                         

             
                              

                                              
          


                              


                                
 
                                                     
                                  







                                               
 
                                                                   
          

                
                           



                  
                                  





                  
                                                                                                 
          
                         


               
       
 
                           

                  
                           



                                                                                                  
          
                         

        
                           

                  
                           

               
       


         
                                                                                
          
                
 
                          
           
 
                        
           

                              


                                                                                 
          
             
                           
                    
 
                        
                  
           
 
                                                                     
                              

                                                                          
          
                                                 
 
                         

                  
           
 
                         

                  
           




                                                                                     
          
                                                        
 
                         

                  
           
 
                         

                  
           




                                                                           
          
                     
 
                         

                  
           
 
                        

                  
           


                              
 

                                       


                                           
                    
                                  
                                                      
                                                      
                                             
                                                   
                                                   

                   

                                                 
          

                    
 
                        

                  
           
 
                          

                  
           
 
                           

                  
           


                              
 


                                                          
                
 
                        



                  
                         



                  

                                                                 
 
                                                    
          
             
                     
                    
 
                                                    

           

                                                                             



                              
                        
               
//: Transform to maintain multiple variants of a recipe depending on the
//: number and types of the ingredients and products. Allows us to use nice
//: names like 'print' or 'length' in many mutually extensible ways.

:(scenario static_dispatch)
def main [
  7:num/raw <- test 3
]
def test a:num -> z:num [
  z <- copy 1
]
def test a:num, b:num -> z:num [
  z <- copy 2
]
+mem: storing 1 in location 7

//: When loading recipes, accumulate variants if headers don't collide, and
//: flag an error if headers collide.

:(before "End Globals")
map<string, vector<recipe_ordinal> > Recipe_variants;
:(before "End One-time Setup")
put(Recipe_variants, "main", vector<recipe_ordinal>());  // since we manually added main to Recipe_ordinal

:(before "End Globals")
map<string, vector<recipe_ordinal> > Recipe_variants_snapshot;
:(before "End save_snapshots")
Recipe_variants_snapshot = Recipe_variants;
:(before "End restore_snapshots")
Recipe_variants = Recipe_variants_snapshot;

:(before "End Load Recipe Header(result)")
// there can only ever be one variant for main
if (result.name != "main" && contains_key(Recipe_ordinal, result.name)) {
  const recipe_ordinal r = get(Recipe_ordinal, result.name);
  if (!contains_key(Recipe, r) || get(Recipe, r).has_header) {
    string new_name = matching_variant_name(result);
    if (new_name.empty()) {
      // variant doesn't already exist
      new_name = next_unused_recipe_name(result.name);
      put(Recipe_ordinal, new_name, Next_recipe_ordinal++);
      get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, new_name));
    }
    trace(9999, "load") << "switching " << result.name << " to " << new_name << end();
    result.name = new_name;
    result.is_autogenerated = true;
  }
}
else {
  // save first variant
  put(Recipe_ordinal, result.name, Next_recipe_ordinal++);
  get_or_insert(Recipe_variants, result.name).push_back(get(Recipe_ordinal, result.name));
}

:(code)
string matching_variant_name(const recipe& rr) {
  const vector<recipe_ordinal>& variants = get_or_insert(Recipe_variants, rr.name);
  for (int i = 0;  i < SIZE(variants);  ++i) {
    if (!contains_key(Recipe, variants.at(i))) continue;
    const recipe& candidate = get(Recipe, variants.at(i));
    if (!all_reagents_match(rr, candidate)) continue;
    return candidate.name;
  }
  return "";
}

bool all_reagents_match(const recipe& r1, const recipe& r2) {
  if (SIZE(r1.ingredients) != SIZE(r2.ingredients)) return false;
  if (SIZE(r1.products) != SIZE(r2.products)) return false;
  for (int i = 0;  i < SIZE(r1.ingredients);  ++i) {
    expand_type_abbreviations(r1.ingredients.at(i).type);
    expand_type_abbreviations(r2.ingredients.at(i).type);
    if (!deeply_equal_type_names(r1.ingredients.at(i), r2.ingredients.at(i)))
      return false;
  }
  for (int i = 0;  i < SIZE(r1.products);  ++i) {
    expand_type_abbreviations(r1.products.at(i).type);
    expand_type_abbreviations(r2.products.at(i).type);
    if (!deeply_equal_type_names(r1.products.at(i), r2.products.at(i)))
      return false;
  }
  return true;
}

:(before "End Globals")
set<string> Literal_type_names;
:(before "End One-time Setup")
Literal_type_names.insert("number");
Literal_type_names.insert("character");
:(code)
bool deeply_equal_type_names(const reagent& a, const reagent& b) {
  return deeply_equal_type_names(a.type, b.type);
}
bool deeply_equal_type_names(const type_tree* a, const type_tree* b) {
  if (!a) return !b;
  if (!b) return !a;
  if (a->name == "literal" && b->name == "literal")
    return true;
  if (a->name == "literal")
    return Literal_type_names.find(b->name) != Literal_type_names.end();
  if (b->name == "literal")
    return Literal_type_names.find(a->name) != Literal_type_names.end();
  return a->name == b->name
      && deeply_equal_type_names(a->left, b->left)
      && deeply_equal_type_names(a->right, b->right);
}

string next_unused_recipe_name(const string& recipe_name) {
  for (int i = 2;  /*forever*/;  ++i) {
    ostringstream out;
    out << recipe_name << '_' << i;
    if (!contains_key(Recipe_ordinal, out.str()))
      return out.str();
  }
}

//: Once all the recipes are loaded, transform their bodies to replace each
//: call with the most suitable variant.

:(scenario static_dispatch_picks_most_similar_variant)
def main [
  7:num/raw <- test 3, 4, 5
]
def test a:num -> z:num [
  z <- copy 1
]
def test a:num, b:num -> z:num [
  z <- copy 2
]
+mem: storing 2 in location 7

//: support recipe headers in a previous transform to fill in missing types
:(before "End check_or_set_invalid_types")
for (int i = 0;  i < SIZE(caller.ingredients);  ++i)
  check_or_set_invalid_types(caller.ingredients.at(i).type, maybe(caller.name), "recipe header ingredient");
for (int i = 0;  i < SIZE(caller.products);  ++i)
  check_or_set_invalid_types(caller.products.at(i).type, maybe(caller.name), "recipe header product");

//: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes)
:(after "Transform.push_back(transform_names)")
Transform.push_back(resolve_ambiguous_calls);  // idempotent

//: In a later layer we'll introduce recursion in resolve_ambiguous_calls, by
//: having it generate code for shape-shifting recipes and then transform such
//: code. This data structure will help error messages be more useful.
//:
//: We're punning the 'call' data structure just because it has slots for
//: calling recipe and calling instruction.
:(before "End Globals")
list<call> resolve_stack;

:(code)
void resolve_ambiguous_calls(recipe_ordinal r) {
  recipe& caller_recipe = get(Recipe, r);
  trace(9991, "transform") << "--- resolve ambiguous calls for recipe " << caller_recipe.name << end();
  for (int index = 0;  index < SIZE(caller_recipe.steps);  ++index) {
    instruction& inst = caller_recipe.steps.at(index);
    if (inst.is_label) continue;
    if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) == 0) continue;
    trace(9992, "transform") << "instruction " << inst.original_string << end();
    resolve_stack.push_front(call(r));
    resolve_stack.front().running_step_index = index;
    string new_name = best_variant(inst, caller_recipe);
    if (!new_name.empty())
      inst.name = new_name;
    assert(resolve_stack.front().running_recipe == r);
    assert(resolve_stack.front().running_step_index == index);
    resolve_stack.pop_front();
  }
}

string best_variant(instruction& inst, const recipe& caller_recipe) {
  vector<recipe_ordinal>& variants = get(Recipe_variants, inst.name);
  vector<recipe_ordinal> candidates;

  // Static Dispatch Phase 1
  candidates = strictly_matching_variants(inst, variants);
  if (!candidates.empty()) return best_variant(inst, candidates).name;

  // Static Dispatch Phase 2
  candidates = strictly_matching_variants_except_literal_zero_against_address(inst, variants);
  if (!candidates.empty()) return best_variant(inst, candidates).name;

  // Static Dispatch Phase 3
  //: (shape-shifting recipes in a later layer)
  // End Static Dispatch Phase 3

  // Static Dispatch Phase 4
  candidates = strictly_matching_variants_except_literal_against_address_or_boolean(inst, variants);
  if (!candidates.empty()) return best_variant(inst, candidates).name;

  // Static Dispatch Phase 5
  candidates = matching_variants(inst, variants);
  if (!candidates.empty()) return best_variant(inst, candidates).name;

  // error messages
  if (get(Recipe_ordinal, inst.name) >= MAX_PRIMITIVE_RECIPES) {  // we currently don't check types for primitive variants
    raise << maybe(caller_recipe.name) << "failed to find a matching call for '" << inst.original_string << "'\n" << end();
    for (list<call>::iterator p = /*skip*/++resolve_stack.begin();  p != resolve_stack.end();  ++p) {
      const recipe& specializer_recipe = get(Recipe, p->running_recipe);
      const instruction& specializer_inst = specializer_recipe.steps.at(p->running_step_index);
      if (specializer_recipe.name != "interactive")
        raise << "  (from '" << to_original_string(specializer_inst) << "' in " << specializer_recipe.name << ")\n" << end();
      else
        raise << "  (from '" << to_original_string(specializer_inst) << "')\n" << end();
      // One special-case to help with the rewrite_stash transform. (cross-layer)
      if (specializer_inst.products.at(0).name.find("stash_") == 0) {
        instruction stash_inst;
        if (next_stash(*p, &stash_inst)) {
          if (specializer_recipe.name != "interactive")
            raise << "  (part of '" << stash_inst.original_string << "' in " << specializer_recipe.name << ")\n" << end();
          else
            raise << "  (part of '" << stash_inst.original_string << "')\n" << end();
        }
      }
    }
  }
  return "";
}

// phase 1
vector<recipe_ordinal> strictly_matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) {
  vector<recipe_ordinal> result;
  for (int i = 0;  i < SIZE(variants);  ++i) {
    if (variants.at(i) == -1) continue;
    trace(9992, "transform") << "checking variant (strict) " << i << ": " << header_label(variants.at(i)) << end();
    if (all_header_reagents_strictly_match(inst, get(Recipe, variants.at(i))))
      result.push_back(variants.at(i));
  }
  return result;
}

bool all_header_reagents_strictly_match(const instruction& inst, const recipe& variant) {
  for (int i = 0;  i < min(SIZE(inst.ingredients), SIZE(variant.ingredients));  ++i) {
    if (!types_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) {
      trace(9993, "transform") << "strict match failed: ingredient " << i << end();
      return false;
    }
  }
  for (int i = 0;  i < min(SIZE(inst.products), SIZE(variant.products));  ++i) {
    if (is_dummy(inst.products.at(i))) continue;
    if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) {
      trace(9993, "transform") << "strict match failed: product " << i << end();
      return false;
    }
  }
  return true;
}

// phase 2
vector<recipe_ordinal> strictly_matching_variants_except_literal_zero_against_address(const instruction& inst, vector<recipe_ordinal>& variants) {
  vector<recipe_ordinal> result;
  for (int i = 0;  i < SIZE(variants);  ++i) {
    if (variants.at(i) == -1) continue;
    trace(9992, "transform") << "checking variant (strict except literal-zero-against-address) " << i << ": " << header_label(variants.at(i)) << end();
    if (all_header_reagents_strictly_match_except_literal_zero_against_address(inst, get(Recipe, variants.at(i))))
      result.push_back(variants.at(i));
  }
  return result;
}

bool all_header_reagents_strictly_match_except_literal_zero_against_address(const instruction& inst, const recipe& variant) {
  for (int i = 0;  i < min(SIZE(inst.ingredients), SIZE(variant.ingredients));  ++i) {
    if (!types_strictly_match_except_literal_zero_against_address(variant.ingredients.at(i), inst.ingredients.at(i))) {
      trace(9993, "transform") << "match failed: ingredient " << i << end();
      return false;
    }
  }
  for (int i = 0;  i < min(SIZE(inst.products), SIZE(variant.products));  ++i) {
    if (is_dummy(inst.products.at(i))) continue;
    if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) {
      trace(9993, "transform") << "match failed: product " << i << end();
      return false;
    }
  }
  return true;
}

bool types_strictly_match_except_literal_zero_against_address(const reagent& to, const reagent& from) {
  if (is_literal(from) && is_mu_address(to))
    return from.name == "0";
  return types_strictly_match(to, from);
}

// phase 4
vector<recipe_ordinal> strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, vector<recipe_ordinal>& variants) {
  vector<recipe_ordinal> result;
  for (int i = 0;  i < SIZE(variants);  ++i) {
    if (variants.at(i) == -1) continue;
    trace(9992, "transform") << "checking variant (strict except literal-against-boolean) " << i << ": " << header_label(variants.at(i)) << end();
    if (all_header_reagents_strictly_match_except_literal_against_address_or_boolean(inst, get(Recipe, variants.at(i))))
      result.push_back(variants.at(i));
  }
  return result;
}

bool all_header_reagents_strictly_match_except_literal_against_address_or_boolean(const instruction& inst, const recipe& variant) {
  for (int i = 0;  i < min(SIZE(inst.ingredients), SIZE(variant.ingredients));  ++i) {
    if (!types_strictly_match_except_literal_against_address_or_boolean(variant.ingredients.at(i), inst.ingredients.at(i))) {
      trace(9993, "transform") << "match failed: ingredient " << i << end();
      return false;
    }
  }
  for (int i = 0;  i < min(SIZE(variant.products), SIZE(inst.products));  ++i) {
    if (is_dummy(inst.products.at(i))) continue;
    if (!types_strictly_match_except_literal_against_address_or_boolean(variant.products.at(i), inst.products.at(i))) {
      trace(9993, "transform") << "match failed: product " << i << end();
      return false;
    }
  }
  return true;
}

bool types_strictly_match_except_literal_against_address_or_boolean(const reagent& to, const reagent& from) {
  if (is_literal(from) && is_mu_boolean(to))
    return from.name == "0" || from.name == "1";
  return types_strictly_match_except_literal_zero_against_address(to, from);
}

// phase 5
vector<recipe_ordinal> matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) {
  vector<recipe_ordinal> result;
  for (int i = 0;  i < SIZE(variants);  ++i) {
    if (variants.at(i) == -1) continue;
    trace(9992, "transform") << "checking variant " << i << ": " << header_label(variants.at(i)) << end();
    if (all_header_reagents_match(inst, get(Recipe, variants.at(i))))
      result.push_back(variants.at(i));
  }
  return result;
}

bool all_header_reagents_match(const instruction& inst, const recipe& variant) {
  for (int i = 0;  i < min(SIZE(inst.ingredients), SIZE(variant.ingredients));  ++i) {
    if (!types_match(variant.ingredients.at(i), inst.ingredients.at(i))) {
      trace(9993, "transform") << "match failed: ingredient " << i << end();
      return false;
    }
  }
  for (int i = 0;  i < min(SIZE(variant.products), SIZE(inst.products));  ++i) {
    if (is_dummy(inst.products.at(i))) continue;
    if (!types_match(variant.products.at(i), inst.products.at(i))) {
      trace(9993, "transform") << "match failed: product " << i << end();
      return false;
    }
  }
  return true;
}

// tie-breaker for each phase
const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& candidates) {
  assert(!candidates.empty());
  int min_score = 999;
  int min_index = 0;
  for (int i = 0;  i < SIZE(candidates);  ++i) {
    const recipe& candidate = get(Recipe, candidates.at(i));
    int score = abs(SIZE(candidate.products)-SIZE(inst.products))
                          + abs(SIZE(candidate.ingredients)-SIZE(inst.ingredients));
    assert(score < 999);
    if (score < min_score) {
      min_score = score;
      min_index = i;
    }
  }
  return get(Recipe, candidates.at(min_index));
}

int non_ghost_size(vector<recipe_ordinal>& variants) {
  int result = 0;
  for (int i = 0;  i < SIZE(variants);  ++i)
    if (variants.at(i) != -1) ++result;
  return result;
}

bool next_stash(const call& c, instruction* stash_inst) {
  const recipe& specializer_recipe = get(Recipe, c.running_recipe);
  int index = c.running_step_index;
  for (++index;  index < SIZE(specializer_recipe.steps);  ++index) {
    const instruction& inst = specializer_recipe.steps.at(index);
    if (inst.name == "stash") {
      *stash_inst = inst;
      return true;
    }
  }
  return false;
}

:(scenario static_dispatch_disabled_in_recipe_without_variants)
def main [
  1:num <- test 3
]
def test [
  2:num <- next-ingredient  # ensure no header
  return 34
]
+mem: storing 34 in location 1

:(scenario static_dispatch_disabled_on_headerless_definition)
% Hide_errors = true;
def test a:num -> z:num [
  z <- copy 1
]
def test [
  return 34
]
+error: redefining recipe test

:(scenario static_dispatch_disabled_on_headerless_definition_2)
% Hide_errors = true;
def test [
  return 34
]
def test a:num -> z:num [
  z <- copy 1
]
+error: redefining recipe test

:(scenario static_dispatch_on_primitive_names)
def main [
  1:num <- copy 34
  2:num <- copy 34
  3:bool <- equal 1:num, 2:num
  4:bool <- copy 0/false
  5:bool <- copy 0/false
  6:bool <- equal 4:bool, 5:bool
]
# temporarily hardcode number equality to always fail
def equal x:num, y:num -> z:bool [
  local-scope
  load-ingredients
  z <- copy 0/false
]
# comparing numbers used overload
+mem: storing 0 in location 3
# comparing booleans continues to use primitive
+mem: storing 1 in location 6

:(scenario static_dispatch_works_with_dummy_results_for_containers)
def main [
  _ <- test 3, 4
]
def test a:num -> z:point [
  local-scope
  load-ingredients
  z <- merge a, 0
]
def test a:num, b:num -> z:point [
  local-scope
  load-ingredients
  z <- merge a, b
]
$error: 0

:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use)
def main [
  x:&:foo <- new foo:type
  test x
]
container foo [
  x:num
]
def test a:&:foo -> z:num [
  local-scope
  load-ingredients
  z:num <- get *a, x:offset
]
$error: 0

:(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use)
def main [
  x:&:foo <- new foo:type
  test x
]
def test a:&:foo -> z:num [
  local-scope
  load-ingredients
  z:num <- get *a, x:offset
]
container foo [
  x:num
]
$error: 0

:(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses)
def main [
  1:num <- foo 0
]
def foo x:&:num -> y:num [
  return 34
]
def foo x:num -> y:num [
  return 35
]
+mem: storing 35 in location 1

:(scenario static_dispatch_on_non_literal_character_ignores_variant_with_numbers)
% Hide_errors = true;
def main [
  local-scope
  x:char <- copy 10/newline
  1:num/raw <- foo x
]
def foo x:num -> y:num [
  load-ingredients
  return 34
]
+error: main: ingredient 0 has the wrong type at '1:num/raw <- foo x'
-mem: storing 34 in location 1

:(scenario static_dispatch_dispatches_literal_to_boolean_before_character)
def main [
  1:num/raw <- foo 0  # valid literal for boolean
]
def foo x:char -> y:num [
  local-scope
  load-ingredients
  return 34
]
def foo x:bool -> y:num [
  local-scope
  load-ingredients
  return 35
]
# boolean variant is preferred
+mem: storing 35 in location 1

:(scenario static_dispatch_dispatches_literal_to_character_when_out_of_boolean_range)
def main [
  1:num/raw <- foo 97  # not a valid literal for boolean
]
def foo x:char -> y:num [
  local-scope
  load-ingredients
  return 34
]
def foo x:bool -> y:num [
  local-scope
  load-ingredients
  return 35
]
# character variant is preferred
+mem: storing 34 in location 1

:(scenario static_dispatch_dispatches_literal_to_number_if_at_all_possible)
def main [
  1:num/raw <- foo 97
]
def foo x:char -> y:num [
  local-scope
  load-ingredients
  return 34
]
def foo x:num -> y:num [
  local-scope
  load-ingredients
  return 35
]
# number variant is preferred
+mem: storing 35 in location 1

:(code)
string header_label(recipe_ordinal r) {
  return header_label(get(Recipe, r));
}
string header_label(const recipe& caller) {
  ostringstream out;
  out << "recipe " << caller.name;
  for (int i = 0;  i < SIZE(caller.ingredients);  ++i)
    out << ' ' << to_string(caller.ingredients.at(i));
  if (!caller.products.empty()) out << " ->";
  for (int i = 0;  i < SIZE(caller.products);  ++i)
    out << ' ' << to_string(caller.products.at(i));
  return out.str();
}

:(scenario reload_variant_retains_other_variants)
def main [
  1:num <- copy 34
  2:num <- foo 1:num
]
def foo x:num -> y:num [
  local-scope
  load-ingredients
  return 34
]
def foo x:&:num -> y:num [
  local-scope
  load-ingredients
  return 35
]
def! foo x:&:num -> y:num [
  local-scope
  load-ingredients
  return 36
]
+mem: storing 34 in location 2
$error: 0

:(scenario dispatch_errors_come_after_unknown_name_errors)
% Hide_errors = true;
def main [
  y:num <- foo x
]
def foo a:num -> b:num [
  local-scope
  load-ingredients
  return 34
]
def foo a:bool -> b:num [
  local-scope
  load-ingredients
  return 35
]
+error: main: missing type for 'x' in 'y:num <- foo x'
+error: main: failed to find a matching call for 'y:num <- foo x'

:(scenario override_methods_with_type_abbreviations)
def main [
  local-scope
  s:text <- new [abc]
  1:num/raw <- foo s
]
def foo a:address:array:character -> result:number [
  return 34
]
# identical to previous variant once you take type abbreviations into account
def! foo a:text -> result:num [
  return 35
]
+mem: storing 35 in location 1

:(before "End Includes")
using std::abs;