about summary refs log tree commit diff stats
path: root/html/linux/101_write.subx.html
blob: ce117c1166889b7080572b331f99badd536eafde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!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 - linux/101_write.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-dark">
<style type="text/css">
<!--
pre { font-family: monospace; color: #000000; background-color: #a8a8a8; }
body { font-size:12pt; font-family: monospace; color: #000000; background-color: #a8a8a8; }
a { color:inherit; }
* { font-size:12pt; font-size: 1em; }
.subxComment { color: #005faf; }
.subxS1Comment { color: #0000af; }
.subxS2Comment { color: #8a8a8a; }
.LineNr { }
.Constant { color: #008787; }
.Normal { color: #000000; background-color: #a8a8a8; padding-bottom: 1px; }
.SpecialChar { color: #d70000; }
.subxMinorFunction { color: #875f5f; }
-->
</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/main/linux/101_write.subx'>https://github.com/akkartik/mu/blob/main/linux/101_write.subx</a>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr"> 1 </span><span class="subxComment"># _write: write to a file descriptor (fd)</span>
<span id="L2" class="LineNr"> 2 </span>
<span id="L3" class="LineNr"> 3 </span>== code
<span id="L4" class="LineNr"> 4 </span><span class="subxComment">#   instruction                     effective address                                                   register    displacement    immediate</span>
<span id="L5" class="LineNr"> 5 </span><span class="subxS1Comment"># . op          subop               mod             rm32          base        index         scale       r32</span>
<span id="L6" class="LineNr"> 6 </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="L7" class="LineNr"> 7 </span>
<span id="L8" class="LineNr"> 8 </span><span class="SpecialChar">Entry</span>:  <span class="subxComment"># just exit; can't test _write just yet</span>
<span id="L9" class="LineNr"> 9 </span>    bb/copy-to-ebx  0/imm32
<span id="L10" class="LineNr">10 </span>    e8/call  <a href='000init.subx.html#L18'>syscall_exit</a>/disp32
<span id="L11" class="LineNr">11 </span>
<span id="L12" class="LineNr">12 </span><span class="subxMinorFunction">_write</span>:  <span class="subxComment"># fd: int, s: (addr array byte)</span>
<span id="L13" class="LineNr">13 </span>    <span class="subxS1Comment"># . prologue</span>
<span id="L14" class="LineNr">14 </span>    55/push-ebp
<span id="L15" class="LineNr">15 </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="L16" class="LineNr">16 </span>    <span class="subxS1Comment"># . save registers</span>
<span id="L17" class="LineNr">17 </span>    50/push-eax
<span id="L18" class="LineNr">18 </span>    51/push-ecx
<span id="L19" class="LineNr">19 </span>    52/push-edx
<span id="L20" class="LineNr">20 </span>    53/push-ebx
<span id="L21" class="LineNr">21 </span>    <span class="subxComment"># syscall(write, fd, (data) s+4, (size) *s)</span>
<span id="L22" class="LineNr">22 </span>    <span class="subxS1Comment"># . ebx = fd</span>
<span id="L23" class="LineNr">23 </span>    8b/copy                         1/mod/*+disp8   5/rm32/ebp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          3/r32/ebx   8/disp8        <span class="Normal"> . </span>                <span class="subxComment"># copy *(ebp+8) to ebx</span>
<span id="L24" class="LineNr">24 </span>    <span class="subxS1Comment"># . var data/ecx: (addr byte) = s+4</span>
<span id="L25" class="LineNr">25 </span>    8b/copy                         1/mod/*+disp8   5/rm32/ebp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          1/r32/ecx   0xc/disp8      <span class="Normal"> . </span>                <span class="subxComment"># copy *(ebp+12) to ecx</span>
<span id="L26" class="LineNr">26 </span>    81          0/subop/add         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>              4/imm32           <span class="subxComment"># add to ecx</span>
<span id="L27" class="LineNr">27 </span>    <span class="subxS1Comment"># . var size/edx: int = *s</span>
<span id="L28" class="LineNr">28 </span>    8b/copy                         1/mod/*+disp8   5/rm32/ebp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          2/r32/edx   0xc/disp8      <span class="Normal"> . </span>                <span class="subxComment"># copy *(ebp+12) to edx</span>
<span id="L29" class="LineNr">29 </span>    8b/copy                         0/mod/indirect  2/rm32/edx   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          2/r32/edx  <span class="Normal"> . </span>             <span class="Normal"> . </span>                <span class="subxComment"># copy *edx to edx</span>
<span id="L30" class="LineNr">30 </span>    <span class="subxS1Comment"># . syscall</span>
<span id="L31" class="LineNr">31 </span>    e8/call  <a href='000init.subx.html#L29'>syscall_write</a>/disp32
<span id="L32" class="LineNr">32 </span>    <span class="subxComment"># if (eax &lt; 0) abort</span>
<span id="L33" class="LineNr">33 </span>    3d/compare-eax-with  0/imm32
<span id="L34" class="LineNr">34 </span>    0f 8c/jump-if-&lt;  $_write:abort/disp32
<span id="L35" class="LineNr">35 </span><span class="Constant">$_write:end</span>:
<span id="L36" class="LineNr">36 </span>    <span class="subxS1Comment"># . restore registers</span>
<span id="L37" class="LineNr">37 </span>    5b/pop-to-ebx
<span id="L38" class="LineNr">38 </span>    5a/pop-to-edx
<span id="L39" class="LineNr">39 </span>    59/pop-to-ecx
<span id="L40" class="LineNr">40 </span>    58/pop-to-eax
<span id="L41" class="LineNr">41 </span>    <span class="subxS1Comment"># . epilogue</span>
<span id="L42" class="LineNr">42 </span>    89/copy                         3/mod/direct    4/rm32/esp   <span class="Normal"> . </span>         <span class="Normal"> . </span>           <span class="Normal"> . </span>          5/r32/ebp  <span class="Normal"> . </span>             <span class="Normal"> . </span>                <span class="subxComment"># copy ebp to esp</span>
<span id="L43" class="LineNr">43 </span>    5d/pop-to-ebp
<span id="L44" class="LineNr">44 </span>    c3/return
<span id="L45" class="LineNr">45 </span>
<span id="L46" class="LineNr">46 </span><span class="Constant">$_write:abort</span>:
<span id="L47" class="LineNr">47 </span>    <span class="subxComment"># can't write a message here for risk of an infinite loop, so we'll use a special exit code instead</span>
<span id="L48" class="LineNr">48 </span>    <span class="subxS1Comment"># . syscall(exit, 255)</span>
<span id="L49" class="LineNr">49 </span>    bb/copy-to-ebx  0xff/imm32
<span id="L50" class="LineNr">50 </span>    e8/call  <a href='000init.subx.html#L18'>syscall_exit</a>/disp32
<span id="L51" class="LineNr">51 </span>    <span class="subxComment"># never gets here</span>
<span id="L52" class="LineNr">52 </span>
<span id="L53" class="LineNr">53 </span><span class="subxS2Comment"># . . vim&#0058;nowrap:textwidth=0</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
56219bb2eb59487d1012f837bd07ec336f5'>1ead3562 ^
192d59d3 ^
198ad741 ^

192d59d3 ^
198ad741 ^
18e626df ^
5f98a10c ^

1ead3562 ^
192d59d3 ^
ce2b0aec ^
5f98a10c ^
ce2b0aec ^
5f98a10c ^

1ead3562 ^
192d59d3 ^

ce2b0aec ^
5f98a10c ^
ce2b0aec ^
5f98a10c ^
1ead3562 ^
192d59d3 ^
ce2b0aec ^
5f98a10c ^

ce2b0aec ^
5f98a10c ^
1ead3562 ^
192d59d3 ^
ce2b0aec ^
5f98a10c ^

ce2b0aec ^
53881567 ^

caec3c16 ^
c792fe8e ^


2b250717 ^
c792fe8e ^




3b0aa1ac ^
1ead3562 ^
760f683f ^


a3d9828c ^
db5c9550 ^

72cc3ae1 ^
dd2e01e4 ^
db5c9550 ^
53881567 ^
80411d01 ^




8b9e9fb1 ^
80411d01 ^
6179649e ^

d57bf669 ^
c6354606 ^



6179649e ^
06b3eb96 ^

5bdc0334 ^






72cc3ae1 ^
8c9e97ae ^
3b0aa1ac ^
1ead3562 ^
7136ddd5 ^
192d59d3 ^
72cc3ae1 ^


caec3c16 ^
7284d503 ^
caec3c16 ^

3b0aa1ac ^
1ead3562 ^
192d59d3 ^


d52406cc ^
caec3c16 ^
5497090a ^
6e793202 ^
7bf9212f ^

caec3c16 ^
dd2e01e4 ^
caec3c16 ^
e6692482 ^
e4630643 ^
2b250717 ^
e4630643 ^

ab6ed192 ^
6179649e ^

d57bf669 ^
c6354606 ^



6179649e ^
caec3c16 ^
5bdc0334 ^






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
                                                                                
                                                                        

                
                           
          
                 

                 
                             
 
                      

                                                      
          
                     
 
                                                                                                     
                                  
 
                                                       
                                                    

                       
                                            








                                                                            

       
                                              

                                                                                        

                                      
                                    
                                               
                            
                                                                      
                                                  
                                           
                                              
                             
                                                           
                                                    
                                                                                 




                                                                         
                                                                                                                                                                                   
                               
               
       
                                         
                   

                                                            

            
                                                                                                            

               
     
                                                           
                                               
                                                                           







                                                                                     
       
                                      
                   

                                                      

            
                                                                                                         

               

     
                                           
                                                                                            

 
                                                                                                  
                
                                                                                                                                       
                           

                
                             
                                 
                                      

                                 
 
 
                                                                           
                                     

 
                                                                        


                                      
                                              


                                                                 
                                     

                                       



                                

 
                                                                                            
                                            
                                                      
                                                        
                                                                                                                          


            
                                            
                                  

                                                                       
                            


                                          
                                  

                                            
                             

 
                                                                                      

                                       
                            
                                      


               


                                               
                 






                                                  
                           
                 




                                                          
                                        
                                                   
          
                       


                 
 
                                                                    
                
                                      
                     
          
                     

                 
                                                          
 
                      

                                                                         
          
                     
 
                                                         
 

                                                                           
          

                     
 
                                                         
 
                                                                             
          
                         
 

                                                         
 
                                                                        
          
                 
 

                                                         
 

                                                                                
 


                                                
                                                                                                                                             




                              
                                                         
          


                                   
 

                                             
 
                                                   
                                                   
                                                                              




                                                                              
                                          
                                     

                                                                                          
                                                                         



                                                                                                                                                                                               
   

 






                                                       
                                                   
                      
                                              
          
                          
                        


                 
 
                                                                       

                
                                                        
          


                   
                                                                         
 
                                                  
                              

                               
 
                                                   
                                                
                                   
                                    
                                                                                                                               

          
                                             

                                                                                                     
                                                                         



                                                                                                                                                                                          
   
 






                                                                  
//: A big convenience high-level languages provide is the ability to name memory
//: locations. In Mu, a transform called 'transform_names' provides this
//: convenience.

:(scenario transform_names)
def main [
  x:num <- copy 0
]
+name: assign x 1
+mem: storing 0 in location 1

:(scenarios transform)
:(scenario transform_names_fails_on_use_before_define)
% Hide_errors = true;
def main [
  x:num <- copy y:num
]
+error: main: tried to read ingredient 'y' in 'x:num <- copy y:num' but it hasn't been written to yet
# todo: detect conditional defines

:(after "Transform.push_back(compute_container_sizes)")
Transform.push_back(transform_names);  // idempotent

:(before "End Globals")
map<recipe_ordinal, map<string, int> > Name;

//: the Name map is a global, so save it before tests and reset it for every
//: test, just to be safe.
:(before "End Globals")
map<recipe_ordinal, map<string, int> > Name_snapshot;
:(before "End save_snapshots")
Name_snapshot = Name;
:(before "End restore_snapshots")
Name = Name_snapshot;

:(code)
void transform_names(const recipe_ordinal r) {
  recipe& caller = get(Recipe, r);
  trace(9991, "transform") << "--- transform names for recipe " << caller.name << end();
  bool names_used = false;
  bool numeric_locations_used = false;
  map<string, int>& names = Name[r];
  // store the indices 'used' so far in the map
  int& curr_idx = names[""];
  ++curr_idx;  // avoid using index 0, benign skip in some other cases
  for (int i = 0;  i < SIZE(caller.steps);  ++i) {
    instruction& inst = caller.steps.at(i);
    // End transform_names(inst) Special-cases
    // map names to addresses
    for (int in = 0;  in < SIZE(inst.ingredients);  ++in) {
      reagent& ingredient = inst.ingredients.at(in);
      // Begin transform_names Ingredient Special-cases(ingredient, inst, caller)
      if (is_disqualified(ingredient, inst, caller.name)) continue;
      if (is_numeric_location(ingredient)) numeric_locations_used = true;
      if (is_named_location(ingredient)) names_used = true;
      if (is_integer(ingredient.name)) continue;
      if (!already_transformed(ingredient, names)) {
        raise << maybe(caller.name) << "tried to read ingredient '" << ingredient.name << "' in '" << to_original_string(inst) << "' but it hasn't been written to yet\n" << end();
        // use-before-set Error
        return;
      }
      int v = lookup_name(ingredient, r);
      if (v >= 0) {
        ingredient.set_value(v);
        // Done Placing Ingredient(ingredient, inst, caller)
      }
      else {
        raise << maybe(caller.name) << "can't find a place to store '" << ingredient.name << "'\n" << end();
        return;
      }
    }
    for (int out = 0;  out < SIZE(inst.products);  ++out) {
      reagent& product = inst.products.at(out);
      // Begin transform_names Product Special-cases(product, inst, caller)
      if (is_disqualified(product, inst, caller.name)) continue;
      if (is_numeric_location(product)) numeric_locations_used = true;
      if (is_named_location(product)) names_used = true;
      if (is_integer(product.name)) continue;
      if (names.find(product.name) == names.end()) {
        trace(9993, "name") << "assign " << product.name << " " << curr_idx << end();
        names[product.name] = curr_idx;
        curr_idx += size_of(product);
      }
      int v = lookup_name(product, r);
      if (v >= 0) {
        product.set_value(v);
        // Done Placing Product(product, inst, caller)
      }
      else {
        raise << maybe(caller.name) << "can't find a place to store '" << product.name << "'\n" << end();
        return;
      }
    }
  }
  if (names_used && numeric_locations_used)
    raise << maybe(caller.name) << "mixing variable names and numeric addresses\n" << end();
}

bool is_disqualified(/*mutable*/ reagent& x, const instruction& inst, const string& recipe_name) {
  if (!x.type) {
    raise << maybe(recipe_name) << "missing type for '" << x.original_string << "' in '" << to_original_string(inst) << "'\n" << end();
    // missing-type Error 1
    return true;
  }
  if (is_raw(x)) return true;
  if (is_literal(x)) return true;
  // End is_disqualified Special-cases
  if (x.initialized) return true;
  return false;
}

bool already_transformed(const reagent& r, const map<string, int>& names) {
  return contains_key(names, r.name);
}

int lookup_name(const reagent& r, const recipe_ordinal default_recipe) {
  return Name[default_recipe][r.name];
}

type_ordinal skip_addresses(type_tree* type) {
  while (type && is_compound_type_starting_with(type, "address"))
    type = type->right;
  if (!type) return -1;  // error handled elsewhere
  if (type->atom) return type->value;
  const type_tree* base_type = type;
  // Update base_type in skip_addresses
  if (base_type->atom)
    return base_type->value;
  assert(base_type->left->atom);
  return base_type->left->value;
}

int find_element_name(const type_ordinal t, const string& name, const string& recipe_name) {
  const type_info& container = get(Type, t);
  for (int i = 0;  i < SIZE(container.elements);  ++i)
    if (container.elements.at(i).name == name) return i;
  raise << maybe(recipe_name) << "unknown element '" << name << "' in container '" << get(Type, t).name << "'\n" << end();
  return -1;
}

bool is_numeric_location(const reagent& x) {
  if (is_literal(x)) return false;
  if (is_raw(x)) return false;
  if (x.name == "0") return false;  // used for chaining lexical scopes
  return is_integer(x.name);
}

bool is_named_location(const reagent& x) {
  if (is_literal(x)) return false;
  if (is_raw(x)) return false;
  if (is_special_name(x.name)) return false;
  return !is_integer(x.name);
}

// all names here should either be disqualified or also in bind_special_scenario_names
bool is_special_name(const string& s) {
  if (s == "_") return true;
  if (s == "0") return true;
  // End is_special_name Special-cases
  return false;
}

:(scenario transform_names_supports_containers)
def main [
  x:point <- merge 34, 35
  y:num <- copy 3
]
+name: assign x 1
# skip location 2 because x occupies two locations
+name: assign y 3

:(scenario transform_names_supports_static_arrays)
def main [
  x:@:num:3 <- create-array
  y:num <- copy 3
]
+name: assign x 1
# skip locations 2, 3, 4 because x occupies four locations
+name: assign y 5

:(scenario transform_names_passes_dummy)
# _ is just a dummy result that never gets consumed
def main [
  _, x:num <- copy 0, 1
]
+name: assign x 1
-name: assign _ 1

//: an escape hatch to suppress name conversion that we'll use later
:(scenarios run)
:(scenario transform_names_passes_raw)
% Hide_errors = true;
def main [
  x:num/raw <- copy 0
]
-name: assign x 1
+error: can't write to location 0 in 'x:num/raw <- copy 0'

:(scenarios transform)
:(scenario transform_names_fails_when_mixing_names_and_numeric_locations)
% Hide_errors = true;
def main [
  x:num <- copy 1:num
]
+error: main: mixing variable names and numeric addresses

:(scenario transform_names_fails_when_mixing_names_and_numeric_locations_2)
% Hide_errors = true;
def main [
  x:num <- copy 1
  1:num <- copy x:num
]
+error: main: mixing variable names and numeric addresses

:(scenario transform_names_does_not_fail_when_mixing_names_and_raw_locations)
def main [
  x:num <- copy 1:num/raw
]
-error: main: mixing variable names and numeric addresses
$error: 0

:(scenario transform_names_does_not_fail_when_mixing_names_and_literals)
def main [
  x:num <- copy 1
]
-error: main: mixing variable names and numeric addresses
$error: 0

//:: Support element names for containers in 'get' and 'get-location' and 'put'.
//: (get-location is implemented later)

:(before "End update GET offset_value in Check")
else {
  if (!offset.initialized) {
    raise << maybe(get(Recipe, r).name) << "uninitialized offset '" << offset.name << "' in '" << to_original_string(inst) << "'\n" << end();
    break;
  }
  offset_value = offset.value;
}

:(scenario transform_names_transforms_container_elements)
def main [
  p:&:point <- copy 0
  a:num <- get *p:&:point, y:offset
  b:num <- get *p:&:point, x:offset
]
+name: element y of type point is at offset 1
+name: element x of type point is at offset 0

:(before "End transform_names(inst) Special-cases")
// replace element names of containers with offsets
if (inst.name == "get" || inst.name == "get-location" || inst.name == "put") {
  //: avoid raising any errors here; later layers will support overloading new
  //: instructions with the same names (static dispatch), which could lead to
  //: spurious errors
  if (SIZE(inst.ingredients) < 2)
    break;  // error raised elsewhere
  if (!is_literal(inst.ingredients.at(1)))
    break;  // error raised elsewhere
  if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) {
    // since first non-address in base type must be a container, we don't have to canonize
    type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type);
    if (contains_key(Type, base_type)) {  // otherwise we'll raise an error elsewhere
      inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name));
      trace(9993, "name") << "element " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " is at offset " << no_scientific(inst.ingredients.at(1).value) << end();
    }
  }
}

:(scenario missing_type_in_get)
% Hide_errors = true;
def main [
  get a, x:offset
]
+error: main: missing type for 'a' in 'get a, x:offset'

//: this test is actually illegal so can't call run
:(scenarios transform)
:(scenario transform_names_handles_containers)
def main [
  a:point <- copy 0/unsafe
  b:num <- copy 0/unsafe
]
+name: assign a 1
+name: assign b 3

//:: Support variant names for exclusive containers in 'maybe-convert'.

:(scenarios run)
:(scenario transform_names_handles_exclusive_containers)
def main [
  12:num <- copy 1
  13:num <- copy 35
  14:num <- copy 36
  20:point, 22:bool <- maybe-convert 12:number-or-point/unsafe, p:variant
]
+name: variant p of type number-or-point has tag 1
+mem: storing 1 in location 22
+mem: storing 35 in location 20
+mem: storing 36 in location 21

:(before "End transform_names(inst) Special-cases")
// convert variant names of exclusive containers
if (inst.name == "maybe-convert") {
  if (SIZE(inst.ingredients) != 2) {
    raise << maybe(get(Recipe, r).name) << "exactly 2 ingredients expected in '" << to_original_string(inst) << "'\n" << end();
    break;
  }
  assert(is_literal(inst.ingredients.at(1)));
  if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) {
    // since first non-address in base type must be an exclusive container, we don't have to canonize
    type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type);
    if (contains_key(Type, base_type)) {  // otherwise we'll raise an error elsewhere
      inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name));
      trace(9993, "name") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end();
    }
  }
}

:(scenario missing_type_in_maybe_convert)
% Hide_errors = true;
def main [
  maybe-convert a, x:variant
]
+error: main: missing type for 'a' in 'maybe-convert a, x:variant'