about summary refs log blame commit diff stats
path: root/html/examples/ex8.subx.html
blob: 1f57fcdf7b2e693b94a3f93e478ed43acd88db6e (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                                                          
                                     

                                                
                                   
                                                                                                      
                                                 

                       

                                                                                           
                    
                                     
                                

                                                             
           
                                  

                                                                           
                             















                                                                                 
                                                  















                                                                              
                                                                                                                                       
                         
                                                                                                                                             
                                                                         
                                                                                 
                                                                                                                                           
                                                                                                                 




                                                                                                          


                                                                                              
                                                                                
                                                                                                             
                                        
                                               


                                                                                                                                                                                                                            
                                        
                                                                               
                                                                                           

                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                         
                                                                                                        
                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                       
                                        

                                                                                                                                                                                                                                                                                                                                                                                            

















                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                           






                                                                                                             



                                     
<!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 - examples/ex8.subx</title>
<meta name="Generator" content="Vim/8.1">
<meta name="plugin-version" content="vim8.1_v1">
<meta name="syntax" content="none">
<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
<meta name="colorscheme" content="minimal-light">
<style type="text/css">
<!--
pre { font-family: monospace; color: #000000; background-color: #c6c6c6; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #c6c6c6; }
a { color:inherit; }
* { font-size:12pt; font-size: 1em; }
.subxComment { color: #005faf; }
.subxS2Comment { color: #8a8a8a; }
.subxFunction { color: #af5f00; text-decoration: underline; }
.LineNr { }
.subxS1Comment { color: #0000af; }
.SpecialChar { color: #d70000; }
.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; }
.Constant { color: #008787; }
-->
</style>

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

/* function to open any folds containing a jumped-to line before jumping to it */
function JumpToLine()
{
  var lineNum;
  lineNum = window.location.hash;
  lineNum = lineNum.substr(1); /* strip off '#' */

  if (lineNum.indexOf('L') == -1) {
    lineNum = 'L'+lineNum;
  }
  var lineElem = document.getElementById(lineNum);
  /* Always jump to new location even if the line was hidden inside a fold, or
   * we corrected the raw number to a line ID.
   */
  if (lineElem) {
    lineElem.scrollIntoView(true);
  }
  return true;
}
if ('onhashchange' in window) {
  window.onhashchange = JumpToLine;
}

-->
</script>
</head>
<body onload='JumpToLine();'>
<a href='https://github.com/akkartik/mu/blob/master/examples/ex8.subx'>https://github.com/akkartik/mu/blob/master/examples/ex8.subx</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr"> 1 </span><span class="subxComment"># Example reading commandline arguments: compute length of first arg.</span>
<span id="L2" class="LineNr"> 2 </span><span class="subxComment">#</span>
<span id="L3" class="LineNr"> 3 </span><span class="subxComment"># To run:</span>
<span id="L4" class="LineNr"> 4 </span><span class="subxComment">#   $ ./subx translate init.linux examples/ex8.subx -o examples/ex8</span>
<span id="L5" class="LineNr"> 5 </span><span class="subxComment">#   $ ./subx run examples/ex8 abc de fghi</span>
<span id="L6" class="LineNr"> 6 </span><span class="subxComment"># Expected result:</span>
<span id="L7" class="LineNr"> 7 </span><span class="subxComment">#   $ echo $?</span>
<span id="L8" class="LineNr"> 8 </span><span class="subxComment">#   3  # length of 'abc'</span>
<span id="L9" class="LineNr"> 9 </span><span class="subxComment">#</span>
<span id="L10" class="LineNr">10 </span><span class="subxComment"># At the start of a SubX program:</span>
<span id="L11" class="LineNr">11 </span><span class="subxComment">#   argc: *esp</span>
<span id="L12" class="LineNr">12 </span><span class="subxComment">#   argv[0]: *(esp+4)</span>
<span id="L13" class="LineNr">13 </span><span class="subxComment">#   argv[1]: *(esp+8)</span>
<span id="L14" class="LineNr">14 </span><span class="subxComment">#   ...</span>
<span id="L15" class="LineNr">15 </span><span class="subxComment"># Locals start from esp-4 downwards.</span>
<span id="L16" class="LineNr">16 </span>
<span id="L17" class="LineNr">17 </span>== code
<span id="L18" class="LineNr">18 </span><span class="subxComment">#   instruction                     effective address                                                   register    displacement    immediate</span>
<span id="L19" class="LineNr">19 </span><span class="subxS1Comment"># . op          subop               mod             rm32          base        index         scale       r32</span>
<span id="L20" class="LineNr">20 </span><span class="subxS1Comment"># . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes</span>
<span id="L21" class="LineNr">21 </span>
<span id="L22" class="LineNr">22 </span><span class="SpecialChar">Entry</span>:
<span id="L23" class="LineNr">23 </span>    <span class="subxS1Comment"># . prologue</span>
<span id="L24" class="LineNr">24 </span>    89/copy                         3/mod/direct    5/rm32/ebp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          4/r32/esp  <span class="Normal"> . </span>             <span class="Normal"> . </span>                <span class="subxComment"># copy esp to ebp</span>
<span id="L25" class="LineNr">25 </span>    <span class="subxComment"># eax = ascii-length(argv[1])</span>
<span id="L26" class="LineNr">26 </span>    <span class="subxS2Comment"># . . push args</span>
<span id="L27" class="LineNr">27 </span>    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>         <span class="Normal"> . </span>          8/disp8        <span class="Normal"> . </span>                <span class="subxComment"># push *(ebp+8)</span>
<span id="L28" class="LineNr">28 </span>    <span class="subxS2Comment"># . . call</span>
<span id="L29" class="LineNr">29 </span>    e8/call  <a href='ex8.subx.html#L37'>ascii-length</a>/disp32
<span id="L30" class="LineNr">30 </span>    <span class="subxS2Comment"># . . discard args</span>
<span id="L31" class="LineNr">31 </span>    81          0/subop/add         3/mod/direct    4/rm32/esp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>         <span class="Normal"> . </span>         <span class="Normal"> . </span>              4/imm32           <span class="subxComment"># add to esp</span>
<span id="L32" class="LineNr">32 </span>
<span id="L33" class="LineNr">33 </span>    <span class="subxComment"># exit(eax)</span>
<span id="L34" class="LineNr">34 </span>    89/copy                         3/mod/direct    3/rm32/ebx   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          0/r32/eax  <span class="Normal"> . </span>             <span class="Normal"> . </span>                <span class="subxComment"># copy eax to ebx</span>
<span id="L35" class="LineNr">35 </span>    e8/call  syscall_exit/disp32
<span id="L36" class="LineNr">36 </span>
<span id="L37" class="LineNr">37 </span><span class="subxFunction">ascii-length</span>:  <span class="subxComment"># s : (address array byte) -&gt; n/eax</span>
<span id="L38" class="LineNr">38 </span>    <span class="subxComment"># edx = s</span>
<span id="L39" class="LineNr">39 </span>    8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/esp  4/index/none <span class="Normal"> . </span>          2/r32/edx   4/disp8        <span class="Normal"> . </span>                <span class="subxComment"># copy *(esp+4) to edx</span>
<span id="L40" class="LineNr">40 </span>    <span class="subxComment"># var result/eax = 0</span>
<span id="L41" class="LineNr">41 </span>    b8/copy-to-eax  0/imm32
<span id="L42" class="LineNr">42 </span><span class="Constant">$ascii-length:loop</span>:
<span id="L43" class="LineNr">43 </span>    <span class="subxComment"># var c/ecx = *s</span>
<span id="L44" class="LineNr">44 </span>    8a/copy-byte                    0/mod/*         2/rm32/edx   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          1/r32/CL   <span class="Normal"> . </span>             <span class="Normal"> . </span>                <span class="subxComment"># copy byte at *edx to CL</span>
<span id="L45" class="LineNr">45 </span>    <span class="subxComment"># if (c == '\0') break</span>
<span id="L46" class="LineNr">46 </span>    81          7/subop/compare     3/mod/direct    1/rm32/ecx   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>         <span class="Normal"> . </span>         <span class="Normal"> . </span>              0/imm32           <span class="subxComment"># compare ecx</span>
<span id="L47" class="LineNr">47 </span>    74/jump-if-equal  $ascii-length:end/disp8
<span id="L48" class="LineNr">48 </span>    <span class="subxComment"># ++s</span>
<span id="L49" class="LineNr">49 </span>    42/increment-edx
<span id="L50" class="LineNr">50 </span>    <span class="subxComment"># ++result</span>
<span id="L51" class="LineNr">51 </span>    40/increment-eax
<span id="L52" class="LineNr">52 </span>    <span class="subxComment"># loop</span>
<span id="L53" class="LineNr">53 </span>    eb/jump  $ascii-length:<span class="Constant">loop</span>/disp8
<span id="L54" class="LineNr">54 </span><span class="Constant">$ascii-length:end</span>:
<span id="L55" class="LineNr">55 </span>    <span class="subxComment"># return eax</span>
<span id="L56" class="LineNr">56 </span>    c3/return
<span id="L57" class="LineNr">57 </span>
<span id="L58" class="LineNr">58 </span>== data
<span id="L59" class="LineNr">59 </span>
<span id="L60" class="LineNr">60 </span><span class="subxS2Comment"># . . vim&#0058;nowrap:textwidth=0</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
ass='alt'>
35457609 ^
acc4792d ^

100157d1 ^
96ac511e ^
1ead3562 ^
3a787ca7 ^
96ac511e ^
3a787ca7 ^
96ac511e ^
72c4fb2d ^
1ead3562 ^
72c4fb2d ^



a4ef18b1 ^
1ead3562 ^
bc643692 ^
a4ef18b1 ^
35457609 ^
acc4792d ^

a4ef18b1 ^
96ac511e ^
1ead3562 ^
bc643692 ^
96ac511e ^
35457609 ^
acc4792d ^


96ac511e ^

1ead3562 ^
bc643692 ^
96ac511e ^
35457609 ^
acc4792d ^



f02842a9 ^

1ead3562 ^
bc643692 ^
f02842a9 ^
35457609 ^
acc4792d ^



0060093e ^

1ead3562 ^
8a3d101e ^
0060093e ^
acc4792d ^
076f39b8 ^










14274372 ^
a0b9fa55 ^
5ed9bb13 ^
1ead3562 ^
14274372 ^

1ead3562 ^
14274372 ^

5ed9bb13 ^
14274372 ^
a0b9fa55 ^
1ead3562 ^
14274372 ^

1ead3562 ^
14274372 ^

5ed9bb13 ^

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
                                                                      
 
                                                                                
                        
          
                     
 
                         

                                     

       
                                          
                         
                      
                  

 
                                          
                      
                                
                        
                                     
                             

                                   
                                                  

                                         
                                                         
                                     
                                         
                                      
     
                           
          
                                                                         
     
   

                
 
                               

                              
                         
                                      
                           
                          
                                            
                                                                  
                                                 
                                                            
                                                                      
                                                      
                                               
                                                                    
                                                   
   
                         
                            
                                                        
                                          

 
                                              
                      
                                      
                      
                                                          
                                                                         

                                       
                                                   
                                                                           
                           
                                             
                                   
     




                                                       
                                   
                      
                                                       

                 

                       
                                             
                                        
                        
                                                         

                   
                                
                          
                                        
   
                                   
                                             
                                   
 
                                                                                    
                          
                              
                                                              
                        
                                                         


                   



                                                              
                           
                                            


                    
                         
                                                                  

                 

                                                 
 
                               
                                             
 
                                                                 
                                                                                          
                                                                                                  
                                                                       
                                                                                            
                                                                    
                      
                                                       


                 


                               
                                      

                                
                      
                                                   


                   

                       
                                 
       

                                            
                                                                    




                   
                                                                                              






                    

                                                
                             
                                     
                                                              

                                                
   

 











                                                                               
                                
                                         
             
                                                       


   

                                                                             
                                     
                       
                                     
                     
                                
       

                                                           
              

 
                

                                       

              
                 
              



                
                                        
                                                                                     

        
                                        
          
                     
 
                         

                                     

                                             
          
           
                     
 
                         

                                     
 
                                               
          
           
                     

           
                         

                                     
 
                                               
          
                     
           
                     
 
                         

                                     
                         

                                     

                                           
          
                                
 
                         

                                     
 
                       
          
      
 
                   
 
                                       
          



                         
                                     
          
                                 
 
                         

                                                           
 
                                   
          
                               
 
                         


                                     

                                      
          
                                         
 
                         



                                     

                                
          
                                                 
 
                         



                                            

                            
          
                                    
 
                                                          










                                                 
 
                                     
                     
          

                     
          

                     
                              
 
                                              
          

                     
           

                     

                              
//: Phase 1 of running mu code: load it from a textual representation.

:(scenarios load)  // use 'load' instead of 'run' in all scenarios in this layer
:(scenario first_recipe)
def main [
  1:number <- copy 23
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}

:(code)
vector<recipe_ordinal> load(string form) {
  istringstream in(form);
  in >> std::noskipws;
  return load(in);
}

vector<recipe_ordinal> load(istream& in) {
  in >> std::noskipws;
  vector<recipe_ordinal> result;
  while (has_data(in)) {
    skip_whitespace_and_comments(in);
    if (!has_data(in)) break;
    string command = next_word(in);
    // Command Handlers
    if (command == "recipe" || command == "def") {
      result.push_back(slurp_recipe(in));
    }
    else if (command == "recipe!" || command == "def!") {
      Disable_redefine_checks = true;
      result.push_back(slurp_recipe(in));
      Disable_redefine_checks = false;
    }
    // End Command Handlers
    else {
      raise << "unknown top-level command: " << command << '\n' << end();
    }
  }
  return result;
}

int slurp_recipe(istream& in) {
  recipe result;
  result.name = next_word(in);
  // End Load Recipe Name
  skip_whitespace_but_not_newline(in);
  // End Recipe Refinements
  if (result.name.empty())
    raise << "empty result.name\n" << end();
  trace(9991, "parse") << "--- defining " << result.name << end();
  if (!contains_key(Recipe_ordinal, result.name))
    put(Recipe_ordinal, result.name, Next_recipe_ordinal++);
  if (Recipe.find(get(Recipe_ordinal, result.name)) != Recipe.end()) {
    trace(9991, "parse") << "already exists" << end();
    if (should_check_for_redefine(result.name))
      raise << "redefining recipe " << result.name << "\n" << end();
    Recipe.erase(get(Recipe_ordinal, result.name));
  }
  slurp_body(in, result);
  // End Recipe Body(result)
  put(Recipe, get(Recipe_ordinal, result.name), result);
  return get(Recipe_ordinal, result.name);
}

void slurp_body(istream& in, recipe& result) {
  in >> std::noskipws;
  skip_whitespace_but_not_newline(in);
  if (in.get() != '[')
    raise << "recipe body must begin with '['\n" << end();
  skip_whitespace_and_comments(in);  // permit trailing comment after '['
  instruction curr;
  while (next_instruction(in, &curr)) {
    // End Rewrite Instruction(curr, recipe result)
    trace(9992, "load") << "after rewriting: " << to_string(curr) << end();
    if (!curr.is_empty()) {
      curr.original_string = to_string(curr);
      result.steps.push_back(curr);
    }
  }
}

bool next_instruction(istream& in, instruction* curr) {
  curr->clear();
  skip_whitespace_and_comments(in);
  if (!has_data(in)) {
    raise << "0: unbalanced '[' for recipe\n" << end();
    return false;
  }

  vector<string> words;
  while (has_data(in) && in.peek() != '\n') {
    skip_whitespace_but_not_newline(in);
    if (!has_data(in)) {
      raise << "1: unbalanced '[' for recipe\n" << end();
      return false;
    }
    string word = next_word(in);
    words.push_back(word);
    skip_whitespace_but_not_newline(in);
  }
  skip_whitespace_and_comments(in);
  if (SIZE(words) == 1 && words.at(0) == "]")
    return false;  // end of recipe

  if (SIZE(words) == 1 && !isalnum(words.at(0).at(0)) && words.at(0).at(0) != '$') {
    curr->is_label = true;
    curr->label = words.at(0);
    trace(9993, "parse") << "label: " << curr->label << end();
    if (!has_data(in)) {
      raise << "7: unbalanced '[' for recipe\n" << end();
      return false;
    }
    return true;
  }

  vector<string>::iterator p = words.begin();
  if (find(words.begin(), words.end(), "<-") != words.end()) {
    for (; *p != "<-"; ++p)
      curr->products.push_back(reagent(*p));
    ++p;  // skip <-
  }

  if (p == words.end()) {
    raise << "instruction prematurely ended with '<-'\n" << end();
    return false;
  }
  curr->old_name = curr->name = *p;  p++;
  // curr->operation will be set in a later layer

  for (; p != words.end(); ++p)
    curr->ingredients.push_back(reagent(*p));

  trace(9993, "parse") << "instruction: " << curr->name << end();
  trace(9993, "parse") << "  number of ingredients: " << SIZE(curr->ingredients) << end();
  for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p)
    trace(9993, "parse") << "  ingredient: " << to_string(*p) << end();
  for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p)
    trace(9993, "parse") << "  product: " << to_string(*p) << end();
  if (!has_data(in)) {
    raise << "9: unbalanced '[' for recipe\n" << end();
    return false;
  }
  return true;
}

string next_word(istream& in) {
  skip_whitespace_but_not_newline(in);
  // End next_word Special-cases
  ostringstream out;
  slurp_word(in, out);
  skip_whitespace_and_comments_but_not_newline(in);
  return out.str();
}

:(before "End Globals")
// word boundaries
const string Terminators("(){}");
:(code)
void slurp_word(istream& in, ostream& out) {
  char c;
  if (has_data(in) && Terminators.find(in.peek()) != string::npos) {
    in >> c;
    out << c;
    return;
  }
  while (in >> c) {
    if (isspace(c) || Terminators.find(c) != string::npos || Ignore.find(c) != string::npos) {
      in.putback(c);
      break;
    }
    out << c;
  }
}

void skip_whitespace_and_comments(istream& in) {
  while (true) {
    if (!has_data(in)) break;
    if (isspace(in.peek())) in.get();
    else if (Ignore.find(in.peek()) != string::npos) in.get();
    else if (in.peek() == '#') skip_comment(in);
    else break;
  }
}

// confusing; move to the next line only to skip a comment, but never otherwise
void skip_whitespace_and_comments_but_not_newline(istream& in) {
  while (true) {
    if (!has_data(in)) break;
    if (in.peek() == '\n') break;
    if (isspace(in.peek())) in.get();
    else if (Ignore.find(in.peek()) != string::npos) in.get();
    else if (in.peek() == '#') skip_comment(in);
    else break;
  }
}

void skip_comment(istream& in) {
  if (has_data(in) && in.peek() == '#') {
    in.get();
    while (has_data(in) && in.peek() != '\n') in.get();
  }
}

//: Warn if a recipe gets redefined, because large codebases can accidentally
//: step on their own toes. But there'll be many occasions later where
//: we'll want to disable the errors.
:(before "End Globals")
bool Disable_redefine_checks = false;
:(before "End Setup")
Disable_redefine_checks = false;
:(code)
bool should_check_for_redefine(const string& recipe_name) {
  if (Disable_redefine_checks) return false;
  return true;
}

// for debugging
:(code)
void show_rest_of_stream(istream& in) {
  cerr << '^';
  char c;
  while (in >> c)
    cerr << c;
  cerr << "$\n";
  exit(0);
}

:(scenario parse_comment_outside_recipe)
# this comment will be dropped by the tangler, so we need a dummy recipe to stop that
def f1 [
]
# this comment will go through to 'load'
def main [
  1:number <- copy 23
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}

:(scenario parse_comment_amongst_instruction)
def main [
  # comment
  1:number <- copy 23
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}

:(scenario parse_comment_amongst_instruction_2)
def main [
  # comment
  1:number <- copy 23
  # comment
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}

:(scenario parse_comment_amongst_instruction_3)
def main [
  1:number <- copy 23
  # comment
  2:number <- copy 23
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {2: "number"}

:(scenario parse_comment_after_instruction)
def main [
  1:number <- copy 23  # comment
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}

:(scenario parse_label)
def main [
  +foo
]
+parse: label: +foo

:(scenario parse_dollar_as_recipe_name)
def main [
  $foo
]
+parse: instruction: $foo

:(scenario parse_multiple_properties)
def main [
  1:number <- copy 23/foo:bar:baz
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal", "foo": ("bar" "baz")}
+parse:   product: {1: "number"}

:(scenario parse_multiple_products)
def main [
  1:number, 2:number <- copy 23
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   product: {1: "number"}
+parse:   product: {2: "number"}

:(scenario parse_multiple_ingredients)
def main [
  1:number, 2:number <- copy 23, 4:number
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   ingredient: {4: "number"}
+parse:   product: {1: "number"}
+parse:   product: {2: "number"}

:(scenario parse_multiple_types)
def main [
  1:number, 2:address:number <- copy 23, 4:number
]
+parse: instruction: copy
+parse:   ingredient: {23: "literal"}
+parse:   ingredient: {4: "number"}
+parse:   product: {1: "number"}
+parse:   product: {2: ("address" "number")}

:(scenario parse_properties)
def main [
  1:address:number/lookup <- copy 23
]
+parse:   product: {1: ("address" "number"), "lookup": ()}

//: this test we can't represent with a scenario
:(code)
void test_parse_comment_terminated_by_eof() {
  Trace_file = "parse_comment_terminated_by_eof";
  load("recipe main [\n"
       "  a:number <- copy 34\n"
       "]\n"
       "# abc");  // no newline after comment
  cerr << ".";  // termination = success
}

:(scenario forbid_redefining_recipes)
% Hide_errors = true;
def main [
  1:number <- copy 23
]
def main [
  1:number <- copy 24
]
+error: redefining recipe main

:(scenario permit_forcibly_redefining_recipes)
def main [
  1:number <- copy 23
]
def! main [
  1:number <- copy 24
]
-error: redefining recipe main
$error: 0