about summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.gui.bar.html
blob: 988c736be6fc283ae7c8984382374104b10f6120 (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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.bar</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.bar</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/code/ranger/ranger/gui/bar.py">/home/hut/code/ranger/ranger/gui/bar.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#list">builtins.list</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#BarSide">BarSide</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#Bar">Bar</a>
</font></dt><dt><font face="helvetica, arial"><a href="ranger.gui.bar.html#ColoredString">ColoredString</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Bar">class <strong>Bar</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Bar-__init__"><strong>__init__</strong></a>(self, base_color_tag)</dt></dl>

<dl><dt><a name="Bar-add"><strong>add</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-addright"><strong>addright</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-combine"><strong>combine</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-fill_gap"><strong>fill_gap</strong></a>(self, char, wid, gapwidth<font color="#909090">=False</font>)</dt></dl>

<dl><dt><a name="Bar-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-shrink_by_cutting"><strong>shrink_by_cutting</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-shrink_by_removing"><strong>shrink_by_removing</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>gap</strong> = None</dl>

<dl><dt><strong>left</strong> = None</dl>

<dl><dt><strong>right</strong> = None</dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="BarSide">class <strong>BarSide</strong></a>(<a href="builtins.html#list">builtins.list</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.gui.bar.html#BarSide">BarSide</a></dd>
<dd><a href="builtins.html#list">builtins.list</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="BarSide-__init__"><strong>__init__</strong></a>(self, base_color_tag)</dt></dl>

<dl><dt><a name="BarSide-add"><strong>add</strong></a>(self, string, *lst, **kw)</dt></dl>

<dl><dt><a name="BarSide-add_space"><strong>add_space</strong></a>(self, n<font color="#909090">=1</font>)</dt></dl>

<dl><dt><a name="BarSide-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-nonfixed_items"><strong>nonfixed_items</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="builtins.html#list">builtins.list</a>:<br>
<dl><dt><a name="BarSide-__add__"><strong>__add__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__add__">__add__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+y</tt></dd></dl>

<dl><dt><a name="BarSide-__contains__"><strong>__contains__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__contains__">__contains__</a>(y)&nbsp;&lt;==&gt;&nbsp;y&nbsp;in&nbsp;x</tt></dd></dl>

<dl><dt><a name="BarSide-__delitem__"><strong>__delitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__delitem__">__delitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;del&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="BarSide-__eq__"><strong>__eq__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__eq__">__eq__</a>(y)&nbsp;&lt;==&gt;&nbsp;x==y</tt></dd></dl>

<dl><dt><a name="BarSide-__ge__"><strong>__ge__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ge__">__ge__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;=y</tt></dd></dl>

<dl><dt><a name="BarSide-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>

<dl><dt><a name="BarSide-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>

<dl><dt><a name="BarSide-__gt__"><strong>__gt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__gt__">__gt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;y</tt></dd></dl>

<dl><dt><a name="BarSide-__iadd__"><strong>__iadd__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iadd__">__iadd__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+=y</tt></dd></dl>

<dl><dt><a name="BarSide-__imul__"><strong>__imul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__imul__">__imul__</a>(y)&nbsp;&lt;==&gt;&nbsp;x*=y</tt></dd></dl>

<dl><dt><a name="BarSide-__iter__"><strong>__iter__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iter__">__iter__</a>()&nbsp;&lt;==&gt;&nbsp;iter(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__le__"><strong>__le__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__le__">__le__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;=y</tt></dd></dl>

<dl><dt><a name="BarSide-__len__"><strong>__len__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__len__">__len__</a>()&nbsp;&lt;==&gt;&nbsp;len(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__lt__"><strong>__lt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__lt__">__lt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;y</tt></dd></dl>

<dl><dt><a name="BarSide-__mul__"><strong>__mul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__mul__">__mul__</a>(n)&nbsp;&lt;==&gt;&nbsp;x*n</tt></dd></dl>

<dl><dt><a name="BarSide-__ne__"><strong>__ne__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ne__">__ne__</a>(y)&nbsp;&lt;==&gt;&nbsp;x!=y</tt></dd></dl>

<dl><dt><a name="BarSide-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>

<dl><dt><a name="BarSide-__reversed__"><strong>__reversed__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__reversed__">__reversed__</a>()&nbsp;--&nbsp;return&nbsp;a&nbsp;reverse&nbsp;iterator&nbsp;over&nbsp;the&nbsp;<a href="builtins.html#list">list</a></tt></dd></dl>

<dl><dt><a name="BarSide-__rmul__"><strong>__rmul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__rmul__">__rmul__</a>(n)&nbsp;&lt;==&gt;&nbsp;n*x</tt></dd></dl>

<dl><dt><a name="BarSide-__setitem__"><strong>__setitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__setitem__">__setitem__</a>(i,&nbsp;y)&nbsp;&lt;==&gt;&nbsp;x[i]=y</tt></dd></dl>

<dl><dt><a name="BarSide-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__sizeof__">__sizeof__</a>()&nbsp;--&nbsp;size&nbsp;of&nbsp;L&nbsp;in&nbsp;memory,&nbsp;in&nbsp;bytes</tt></dd></dl>

<dl><dt><a name="BarSide-append"><strong>append</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-append">append</a>(<a href="builtins.html#object">object</a>)&nbsp;--&nbsp;append&nbsp;<a href="builtins.html#object">object</a>&nbsp;to&nbsp;end</tt></dd></dl>

<dl><dt><a name="BarSide-count"><strong>count</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-count">count</a>(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value</tt></dd></dl>

<dl><dt><a name="BarSide-extend"><strong>extend</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-extend">extend</a>(iterable)&nbsp;--&nbsp;extend&nbsp;<a href="builtins.html#list">list</a>&nbsp;by&nbsp;appending&nbsp;elements&nbsp;from&nbsp;the&nbsp;iterable</tt></dd></dl>

<dl><dt><a name="BarSide-index"><strong>index</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-index">index</a>(value,&nbsp;[start,&nbsp;[stop]])&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;first&nbsp;index&nbsp;of&nbsp;value.<br>
Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl>

<dl><dt><a name="BarSide-insert"><strong>insert</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-insert">insert</a>(index,&nbsp;<a href="builtins.html#object">object</a>)&nbsp;--&nbsp;insert&nbsp;<a href="builtins.html#object">object</a>&nbsp;before&nbsp;index</tt></dd></dl>

<dl><dt><a name="BarSide-pop"><strong>pop</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-pop">pop</a>([index])&nbsp;-&gt;&nbsp;item&nbsp;--&nbsp;remove&nbsp;and&nbsp;return&nbsp;item&nbsp;at&nbsp;index&nbsp;(default&nbsp;last).<br>
Raises&nbsp;IndexError&nbsp;if&nbsp;<a href="builtins.html#list">list</a>&nbsp;is&nbsp;empty&nbsp;or&nbsp;index&nbsp;is&nbsp;out&nbsp;of&nbsp;range.</tt></dd></dl>

<dl><dt><a name="BarSide-remove"><strong>remove</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-remove">remove</a>(value)&nbsp;--&nbsp;remove&nbsp;first&nbsp;occurrence&nbsp;of&nbsp;value.<br>
Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl>

<dl><dt><a name="BarSide-reverse"><strong>reverse</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-reverse">reverse</a>()&nbsp;--&nbsp;reverse&nbsp;*IN&nbsp;PLACE*</tt></dd></dl>

<dl><dt><a name="BarSide-sort"><strong>sort</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-sort">sort</a>(key=None,&nbsp;reverse=False)&nbsp;--&nbsp;stable&nbsp;sort&nbsp;*IN&nbsp;PLACE*</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="builtins.html#list">builtins.list</a>:<br>
<dl><dt><strong>__hash__</strong> = None</dl>

<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#BarSide-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="builtins.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="ColoredString">class <strong>ColoredString</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="ColoredString-__init__"><strong>__init__</strong></a>(self, string, *lst)</dt></dl>

<dl><dt><a name="ColoredString-__len__"><strong>__len__</strong></a>(self)</dt></dl>

<dl><dt><a name="ColoredString-__str__"><strong>__str__</strong></a>(self)</dt></dl>

<dl><dt><a name="ColoredString-cut_off"><strong>cut_off</strong></a>(self, n)</dt></dl>

<dl><dt><a name="ColoredString-cut_off_to"><strong>cut_off_to</strong></a>(self, n)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table>
</body></html>










































                                                              

































                                                                                                                                                     
















                                                    


                                                         





























                                                                            





















                                                                                                                                                                                                                                 





























                                                        

















                                                                                                                                                                                               
//: So far we've been calling a fixed recipe in each instruction, but we'd
//: also like to make the recipe a variable, pass recipes to "higher-order"
//: recipes, return recipes from recipes and so on.

void test_call_literal_recipe() {
  run(
      "def main [\n"
      "  1:num <- call f, 34\n"
      "]\n"
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

:(before "End Mu Types Initialization")
put(Type_ordinal, "recipe-literal", 0);
// 'recipe' variables can store recipe-literal
type_ordinal recipe = put(Type_ordinal, "recipe", Next_type_ordinal++);
get_or_insert(Type, recipe).name = "recipe";

:(after "Deduce Missing Type(x, caller)")
if (!x.type)
  try_initialize_recipe_literal(x, caller);
:(before "Type Check in Type-ingredient-aware check_or_set_types_by_name")
if (!x.type)
  try_initialize_recipe_literal(x, variant);
:(code)
void try_initialize_recipe_literal(reagent& x, const recipe& caller) {
  if (x.type) return;
  if (!contains_key(Recipe_ordinal, x.name)) return;
  if (contains_reagent_with_non_recipe_literal_type(caller, x.name)) return;
  x.type = new type_tree("recipe-literal");
  x.set_value(get(Recipe_ordinal, x.name));
}
bool contains_reagent_with_non_recipe_literal_type(const recipe& caller, const string& name) {
  for (int i = 0;  i < SIZE(caller.steps);  ++i) {
    const instruction& inst = caller.steps.at(i);
    for (int i = 0;  i < SIZE(inst.ingredients);  ++i)
      if (is_matching_non_recipe_literal(inst.ingredients.at(i), name)) return true;
    for (int i = 0;  i < SIZE(inst.products);  ++i)
      if (is_matching_non_recipe_literal(inst.products.at(i), name)) return true;
  }
  return false;
}
bool is_matching_non_recipe_literal(const reagent& x, const string& name) {
  if (x.name != name) return false;
  if (!x.type) return false;
  return !x.type->atom || x.type->name != "recipe-literal";
}

//: It's confusing to use variable names that are also recipe names. Always
//: assume variable types override recipe literals.
void test_error_on_recipe_literal_used_as_a_variable() {
  Hide_errors = true;
  run(
      "def main [\n"
      "  local-scope\n"
      "  a:bool <- equal break 0\n"
      "  break:bool <- copy 0\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: main: missing type for 'break' in 'a:bool <- equal break, 0'\n"
  );
}

:(before "End Primitive Recipe Declarations")
CALL,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "call", CALL);
:(before "End Primitive Recipe Checks")
case CALL: {
  if (inst.ingredients.empty()) {
    raise << maybe(get(Recipe, r).name) << "'call' requires at least one ingredient (the recipe to call)\n" << end();
    break;
  }
  if (!is_mu_recipe(inst.ingredients.at(0))) {
    raise << maybe(get(Recipe, r).name) << "first ingredient of 'call' should be a recipe, but got '" << inst.ingredients.at(0).original_string << "'\n" << end();
    break;
  }
  break;
}
:(before "End Primitive Recipe Implementations")
case CALL: {
  // Begin Call
  trace(Callstack_depth+1, "trace") << "indirect 'call': incrementing callstack depth to " << Callstack_depth << end();
  ++Callstack_depth;
  assert(Callstack_depth < Max_depth);
  if (!ingredients.at(0).at(0)) {
    raise << maybe(current_recipe_name()) << "tried to call empty recipe in '" << to_string(current_instruction()) << "'" << end();
    break;
  }
  const call& caller_frame = current_call();
  instruction/*copy*/ call_instruction = to_instruction(caller_frame);
  call_instruction.operation = ingredients.at(0).at(0);
  call_instruction.ingredients.erase(call_instruction.ingredients.begin());
  Current_routine->calls.push_front(call(ingredients.at(0).at(0)));
  ingredients.erase(ingredients.begin());  // drop the callee
  finish_call_housekeeping(call_instruction, ingredients);
  // not done with caller
  write_products = false;
  fall_through_to_next_instruction = false;
  break;
}

:(code)
void test_call_variable() {
  run(
      "def main [\n"
      "  {1: (recipe number -> number)} <- copy f\n"
      "  2:num <- call {1: (recipe number -> number)}, 34\n"
      "]\n"
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 2\n"
  );
}

void test_call_literal_recipe_repeatedly() {
  run(
      "def main [\n"
      "  1:num <- call f, 34\n"
      "  1:num <- call f, 35\n"
      "]\n"
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
      "mem: storing 35 in location 1\n"
  );
}

void test_call_shape_shifting_recipe() {
  run(
      "def main [\n"
      "  1:num <- call f, 34\n"
      "]\n"
      "def f x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

void test_call_shape_shifting_recipe_inside_shape_shifting_recipe() {
  run(
      "def main [\n"
      "  1:num <- f 34\n"
      "]\n"
      "def f x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- call g x\n"
      "]\n"
      "def g x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

void test_call_shape_shifting_recipe_repeatedly_inside_shape_shifting_recipe() {
  run(
      "def main [\n"
      "  1:num <- f 34\n"
      "]\n"
      "def f x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- call g x\n"
      "  y <- call g x\n"
      "]\n"
      "def g x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

//:: check types for 'call' instructions

void test_call_check_literal_recipe() {
  Hide_errors = true;
  run(
      "def main [\n"
      "  1:num <- call f, 34\n"
      "]\n"
      "def f x:point -> y:point [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: main: ingredient 0 has the wrong type at '1:num <- call f, 34'\n"
      "error: main: product 0 has the wrong type at '1:num <- call f, 34'\n"
  );
}

void test_call_check_variable_recipe() {
  Hide_errors = true;
  run(
      "def main [\n"
      "  {1: (recipe point -> point)} <- copy f\n"
      "  2:num <- call {1: (recipe point -> point)}, 34\n"
      "]\n"
      "def f x:point -> y:point [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: main: ingredient 0 has the wrong type at '2:num <- call {1: (recipe point -> point)}, 34'\n"
      "error: main: product 0 has the wrong type at '2:num <- call {1: (recipe point -> point)}, 34'\n"
  );
}

:(before "End resolve_ambiguous_call(r, index, inst, caller_recipe) Special-cases")
if (inst.name == "call" && !inst.ingredients.empty() && is_recipe_literal(inst.ingredients.at(0))) {
  resolve_indirect_ambiguous_call(r, index, inst, caller_recipe);
  return;
}
:(code)
bool is_recipe_literal(const reagent& x) {
  return x.type && x.type->atom && x.type->name == "recipe-literal";
}
void resolve_indirect_ambiguous_call(const recipe_ordinal r, int index, instruction& inst, const recipe& caller_recipe) {
  instruction inst2;
  inst2.name = inst.ingredients.at(0).name;
  for (int i = /*skip recipe*/1;  i < SIZE(inst.ingredients);  ++i)
    inst2.ingredients.push_back(inst.ingredients.at(i));
  for (int i = 0;  i < SIZE(inst.products);  ++i)
    inst2.products.push_back(inst.products.at(i));
  resolve_ambiguous_call(r, index, inst2, caller_recipe);
  inst.ingredients.at(0).name = inst2.name;
  inst.ingredients.at(0).set_value(get(Recipe_ordinal, inst2.name));
}

:(after "Transform.push_back(check_instruction)")
Transform.push_back(check_indirect_calls_against_header);  // idempotent
:(code)
void check_indirect_calls_against_header(const recipe_ordinal r) {
  trace(101, "transform") << "--- type-check 'call' instructions inside recipe " << get(Recipe, r).name << end();
  const recipe& caller = get(Recipe, r);
  for (int i = 0;  i < SIZE(caller.steps);  ++i) {
    const instruction& inst = caller.steps.at(i);
    if (!is_indirect_call(inst.operation)) continue;
    if (inst.ingredients.empty()) continue;  // error raised above
    const reagent& callee = inst.ingredients.at(0);
    if (!is_mu_recipe(callee)) continue;  // error raised above
    const recipe callee_header = is_literal(callee) ? get(Recipe, callee.value) : from_reagent(inst.ingredients.at(0));
    if (!callee_header.has_header) continue;
    if (is_indirect_call_with_ingredients(inst.operation)) {
      for (long int i = /*skip callee*/1;  i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1);  ++i) {
        if (!types_coercible(callee_header.ingredients.at(i-/*skip callee*/1), inst.ingredients.at(i)))
          raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << to_original_string(inst) << "'\n" << end();
      }
    }
    if (is_indirect_call_with_products(inst.operation)) {
      for (long int i = 0;  i < min(SIZE(inst.products), SIZE(callee_header.products));  ++i) {
        if (is_dummy(inst.products.at(i))) continue;
        if (!types_coercible(callee_header.products.at(i), inst.products.at(i)))
          raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << to_original_string(inst) << "'\n" << end();
      }
    }
  }
}

bool is_indirect_call(const recipe_ordinal r) {
  return is_indirect_call_with_ingredients(r) || is_indirect_call_with_products(r);
}

bool is_indirect_call_with_ingredients(const recipe_ordinal r) {
  if (r == CALL) return true;
  // End is_indirect_call_with_ingredients Special-cases
  return false;
}
bool is_indirect_call_with_products(const recipe_ordinal r) {
  if (r == CALL) return true;
  // End is_indirect_call_with_products Special-cases
  return false;
}

recipe from_reagent(const reagent& r) {
  assert(r.type);
  recipe result_header;  // will contain only ingredients and products, nothing else
  result_header.has_header = true;
  // Begin Reagent->Recipe(r, recipe_header)
  if (r.type->atom) {
    assert(r.type->name == "recipe");
    return result_header;
  }
  const type_tree* root_type = r.type->atom ? r.type : r.type->left;
  assert(root_type->atom);
  assert(root_type->name == "recipe");
  const type_tree* curr = r.type->right;
  for (/*nada*/;  curr && !curr->atom;  curr = curr->right) {
    if (curr->left->atom && curr->left->name == "->") {
      curr = curr->right;  // skip delimiter
      goto read_products;
    }
    result_header.ingredients.push_back(next_recipe_reagent(curr->left));
  }
  if (curr) {
    assert(curr->atom);
    result_header.ingredients.push_back(next_recipe_reagent(curr));
    return result_header;  // no products
  }
  read_products:
  for (/*nada*/;  curr && !curr->atom;  curr = curr->right)
    result_header.products.push_back(next_recipe_reagent(curr->left));
  if (curr) {
    assert(curr->atom);
    result_header.products.push_back(next_recipe_reagent(curr));
  }
  return result_header;
}

:(before "End Unit Tests")
void test_from_reagent_atomic() {
  reagent a("{f: recipe}");
  recipe r_header = from_reagent(a);
  CHECK(r_header.ingredients.empty());
  CHECK(r_header.products.empty());
}
void test_from_reagent_non_atomic() {
  reagent a("{f: (recipe number -> number)}");
  recipe r_header = from_reagent(a);
  CHECK_EQ(SIZE(r_header.ingredients), 1);
  CHECK_EQ(SIZE(r_header.products), 1);
}
void test_from_reagent_reads_ingredient_at_end() {
  reagent a("{f: (recipe number number)}");
  recipe r_header = from_reagent(a);
  CHECK_EQ(SIZE(r_header.ingredients), 2);
  CHECK(r_header.products.empty());
}
void test_from_reagent_reads_sole_ingredient_at_end() {
  reagent a("{f: (recipe number)}");
  recipe r_header = from_reagent(a);
  CHECK_EQ(SIZE(r_header.ingredients), 1);
  CHECK(r_header.products.empty());
}

:(code)
reagent next_recipe_reagent(const type_tree* curr) {
  if (!curr->left) return reagent("recipe:"+curr->name);
  return reagent(new type_tree(*curr));
}

bool is_mu_recipe(const reagent& r) {
  if (!r.type) return false;
  if (r.type->atom) {
    // End is_mu_recipe Atom Cases(r)
    return r.type->name == "recipe-literal";
  }
  return r.type->left->atom && r.type->left->name == "recipe";
}

void test_copy_typecheck_recipe_variable() {
  Hide_errors = true;
  run(
      "def main [\n"
      "  3:num <- copy 34\n"
      "  {1: (recipe number -> number)} <- copy f\n"  // store literal in a matching variable
      "  {2: (recipe boolean -> boolean)} <- copy {1: (recipe number -> number)}\n"  // mismatch between recipe variables
      "]\n"
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: main: can't copy '{1: (recipe number -> number)}' to '{2: (recipe boolean -> boolean)}'; types don't match\n"
  );
}

void test_copy_typecheck_recipe_variable_2() {
  Hide_errors = true;
  run(
      "def main [\n"
      "  {1: (recipe number -> number)} <- copy f\n"  // mismatch with a recipe literal
      "]\n"
      "def f x:bool -> y:bool [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: main: can't copy 'f' to '{1: (recipe number -> number)}'; types don't match\n"
  );
}

:(before "End Matching Types For Literal(to)")
if (is_mu_recipe(to)) {
  if (!contains_key(Recipe, from.value)) {
    raise << "trying to store recipe " << from.name << " into " << to_string(to) << " but there's no such recipe\n" << end();
    return false;
  }
  const recipe& rrhs = get(Recipe, from.value);
  const recipe& rlhs = from_reagent(to);
  for (long int i = 0;  i < min(SIZE(rlhs.ingredients), SIZE(rrhs.ingredients));  ++i) {
    if (!types_match(rlhs.ingredients.at(i), rrhs.ingredients.at(i)))
      return false;
  }
  for (long int i = 0;  i < min(SIZE(rlhs.products), SIZE(rrhs.products));  ++i) {
    if (!types_match(rlhs.products.at(i), rrhs.products.at(i)))
      return false;
  }
  return true;
}

:(code)
void test_call_variable_compound_ingredient() {
  run(
      "def main [\n"
      "  {1: (recipe (address number) -> number)} <- copy f\n"
      "  2:&:num <- copy null\n"
      "  3:num <- call {1: (recipe (address number) -> number)}, 2:&:num\n"
      "]\n"
      "def f x:&:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- deaddress x\n"
      "]\n"
  );
  CHECK_TRACE_COUNT("error", 0);
}

//: make sure we don't accidentally break on a recipe literal
void test_jump_forbidden_on_recipe_literals() {
  Hide_errors = true;
  run(
      "def foo [\n"
      "  local-scope\n"
      "]\n"
      "def main [\n"
      "  local-scope\n"
      "  {\n"
      "    break-if foo\n"
      "  }\n"
      "]\n"
  );
  // error should be as if foo is not a recipe
  CHECK_TRACE_CONTENTS(
      "error: main: missing type for 'foo' in 'break-if foo'\n"
  );
}

:(before "End JUMP_IF Checks")
check_for_recipe_literals(inst, get(Recipe, r));
:(before "End JUMP_UNLESS Checks")
check_for_recipe_literals(inst, get(Recipe, r));
:(code)
void check_for_recipe_literals(const instruction& inst, const recipe& caller) {
  for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
    if (is_mu_recipe(inst.ingredients.at(i))) {
      raise << maybe(caller.name) << "missing type for '" << inst.ingredients.at(i).original_string << "' in '" << to_original_string(inst) << "'\n" << end();
      if (is_present_in_ingredients(caller, inst.ingredients.at(i).name))
        raise << "  did you forget 'load-ingredients'?\n" << end();
    }
  }
}

void test_load_ingredients_missing_error_3() {
  Hide_errors = true;
  run(
      "def foo {f: (recipe num -> num)} [\n"
      "  local-scope\n"
      "  b:num <- call f, 1\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "error: foo: missing type for 'f' in 'b:num <- call f, 1'\n"
      "error:   did you forget 'load-ingredients'?\n"
  );
}

:(before "End Mu Types Initialization")
put(Type_abbreviations, "function", new_type_tree("recipe"));
put(Type_abbreviations, "fn", new_type_tree("recipe"));

//: copying functions to variables

:(code)
void test_copy_recipe_to_variable() {
  run(
      "def main [\n"
      "  {1: (fn number -> number)} <- copy f\n"
      "  2:num <- call {1: (function number -> number)}, 34\n"
      "]\n"
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 2\n"
  );
}

void test_copy_overloaded_recipe_to_variable() {
  run(
      "def main [\n"
      "  local-scope\n"
      "  {x: (fn num -> num)} <- copy f\n"
      "  1:num/raw <- call x, 34\n"
      "]\n"
      // variant f
      "def f x:bool -> y:bool [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
      // variant f_2
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  // x contains f_2
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

:(before "End resolve_ambiguous_call(r, index, inst, caller_recipe) Special-cases")
if (inst.name == "copy") {
  for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
    if (!is_recipe_literal(inst.ingredients.at(i))) continue;
    if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue;
    // potentially overloaded recipe
    string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, inst.products.at(i), r, index, caller_recipe);
    if (new_name == "") continue;
    inst.ingredients.at(i).name = new_name;
    inst.ingredients.at(i).value = get(Recipe_ordinal, new_name);
  }
  return;
}
:(code)
string resolve_ambiguous_call(const string& recipe_name, const reagent& call_types, const recipe_ordinal r, int index, const recipe& caller_recipe) {
  instruction inst;
  inst.name = recipe_name;
  if (!is_mu_recipe(call_types)) return "";  // error raised elsewhere
  if (is_recipe_literal(call_types)) return "";  // error raised elsewhere
  construct_fake_call(call_types, inst);
  resolve_ambiguous_call(r, index, inst, caller_recipe);
  return inst.name;
}
void construct_fake_call(const reagent& recipe_var, instruction& out) {
  assert(recipe_var.type->left->name == "recipe");
  type_tree* stem = NULL;
  for (stem = recipe_var.type->right;  stem && stem->left->name != "->";  stem = stem->right)
    out.ingredients.push_back(copy(stem->left));
  if (stem == NULL) return;
  for (/*skip '->'*/stem = stem->right;  stem;  stem = stem->right)
    out.products.push_back(copy(stem->left));
}

void test_copy_shape_shifting_recipe_to_variable() {
  run(
      "def main [\n"
      "  local-scope\n"
      "  {x: (fn num -> num)} <- copy f\n"
      "  1:num/raw <- call x, 34\n"
      "]\n"
      "def f x:_elem -> y:_elem [\n"
      "  local-scope\n"
      "  load-inputs\n"
      "  y <- copy x\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

//: passing function literals to (higher-order) functions

void test_pass_overloaded_recipe_literal_to_ingredient() {
  run(
      // like test_copy_overloaded_recipe_to_variable, except we bind 'x' in
      // the course of a 'call' rather than 'copy'
      "def main [\n"
      "  1:num <- g f\n"
      "]\n"
      "def g {x: (fn num -> num)} -> result:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  result <- call x, 34\n"
      "]\n"
      // variant f
      "def f x:bool -> y:bool [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
      // variant f_2
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  // x contains f_2
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

:(after "End resolve_ambiguous_call(r, index, inst, caller_recipe) Special-cases")
for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
  if (!is_mu_recipe(inst.ingredients.at(i))) continue;
  if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue;
  if (get(Recipe_ordinal, inst.name) < MAX_PRIMITIVE_RECIPES) continue;
  if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) > 1) {
    raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to simultaneously guess which overloads you want for '" << inst.name << "' and '" << inst.ingredients.at(i).name << "'\n" << end();
    return;
  }
  const recipe& callee = get(Recipe, get(Recipe_ordinal, inst.name));
  if (!callee.has_header) {
    raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, when the caller '" << inst.name << "' doesn't have a header\n" << end();
    return;
  }
  string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, callee.ingredients.at(i), r, index, caller_recipe);
  if (new_name != "") {
    inst.ingredients.at(i).name = new_name;
    inst.ingredients.at(i).value = get(Recipe_ordinal, new_name);
  }
}

:(code)
void test_return_overloaded_recipe_literal_to_caller() {
  run(
      "def main [\n"
      "  local-scope\n"
      "  {x: (fn num -> num)} <- g\n"
      "  1:num/raw <- call x, 34\n"
      "]\n"
      "def g -> {x: (fn num -> num)} [\n"
      "  local-scope\n"
      "  return f\n"
      "]\n"
      // variant f
      "def f x:bool -> y:bool [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
      // variant f_2
      "def f x:num -> y:num [\n"
      "  local-scope\n"
      "  load-ingredients\n"
      "  y <- copy x\n"
      "]\n"
  );
  // x contains f_2
  CHECK_TRACE_CONTENTS(
      "mem: storing 34 in location 1\n"
  );
}

:(before "End resolve_ambiguous_call(r, index, inst, caller_recipe) Special-cases")
if (inst.name == "return" || inst.name == "reply") {
  for (int i = 0;  i < SIZE(inst.ingredients);  ++i) {
    if (!is_recipe_literal(inst.ingredients.at(i))) continue;
    if (non_ghost_size(get_or_insert(Recipe_variants, inst.ingredients.at(i).name)) < 1) continue;
    // potentially overloaded recipe
    if (!caller_recipe.has_header) {
      raise << maybe(caller_recipe.name) << "sorry, we're not yet smart enough to guess which variant of '" << inst.ingredients.at(i).name << "' you want, without a recipe header\n" << end();
      return;
    }
    string new_name = resolve_ambiguous_call(inst.ingredients.at(i).name, caller_recipe.products.at(i), r, index, caller_recipe);
    if (new_name == "") continue;
    inst.ingredients.at(i).name = new_name;
    inst.ingredients.at(i).value = get(Recipe_ordinal, new_name);
  }
  return;
}