about summary refs log tree commit diff stats
path: root/html/013update_operation.cc.html
blob: 7dd7e69fb2d500ed8a7f1c1a1950d7962cad49d8 (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
<!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 - 013update_operation.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.Special { color: #c00000; }
.muRecipe { color: #ff8700; }
.traceContains { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.cSpecial { color: #008000; }
.CommentedCode { color: #6c6c6c; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.Identifier { color: #c0a020; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Once all code is loaded, save operation ids of instructions and check that</span>
<span class="Comment">//: nothing's undefined.</span>

<span class="Delimiter">:(before &quot;End Instruction Modifying Transforms&quot;)</span>
Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>update_instruction_operations<span class="Delimiter">);</span>  <span class="Comment">// idempotent</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> update_instruction_operations<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">&quot;transform&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;--- compute instruction operations for recipe &quot;</span> &lt;&lt; get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name &lt;&lt; end<span class="Delimiter">();</span>
  recipe&amp; caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;--- compute instruction operations for recipe &quot; &lt;&lt; caller.name &lt;&lt; '\n';</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> index = <span class="Constant">0</span><span class="Delimiter">;</span>  index &lt; SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>steps<span class="Delimiter">);</span>  ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    instruction&amp; inst = caller<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span>
      raise &lt;&lt; maybe<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;instruction '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>name &lt;&lt; <span class="Constant">&quot;' has no recipe</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Identifier">continue</span><span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    inst<span class="Delimiter">.</span>operation = get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>name<span class="Delimiter">);</span>
    <span class="Comment">// End Instruction Operation Checks</span>
  <span class="Delimiter">}</span>
<span class="Delimiter">}</span>

<span class="Comment">// hook to suppress inserting recipe name into errors (for later layers)</span>
string maybe<span class="Delimiter">(</span>string s<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Identifier">return</span> s + <span class="Constant">&quot;: &quot;</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenarios transform)</span>
<span class="Delimiter">:(scenario missing_arrow)</span>
<span class="Special">% Hide_errors = true;</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:number <span class="Delimiter">,</span> copy <span class="Constant">0</span>  <span class="Comment"># typo: ',' instead of '&lt;-'</span>
]
<span class="traceContains">+error: main: instruction '1:number' has no recipe</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
><pre id='vimCodeElement'> <span class="Comment">//: Since different layers all carve out different parts of various namespaces</span> <span class="Comment">//: (recipes, memory, etc.) for their own use, there's no previous place where</span> <span class="Comment">//: we can lay out the big picture of what uses what. So we'll do that here</span> <span class="Comment">//: and just have to manually remember to update it when we move boundaries</span> <span class="Comment">//: around.</span> <span class="Comment">//:</span> <span class="SalientComment">//:: Memory</span> <span class="Comment">//:</span> <span class="Comment">//: Location 0 - unused (since it can help uncover bugs)</span> <span class="Comment">//: Locations 1-899 - reserved for tests</span> <span class="Comment">//: Locations 900-999 - reserved for predefined globals in mu scenarios, like keyboard, screen, etc.</span> <span class="Delimiter">:(before &quot;End Setup&quot;)</span> assert<span class="Delimiter">(</span>Max_variables_in_scenarios == <span class="Constant">900</span><span class="Delimiter">);</span> <span class="Comment">//: Locations 1000 ('Reserved_for_tests') onward - available to the allocator in chunks of size Initial_memory_per_routine.</span> assert<span class="Delimiter">(</span>Reserved_for_tests == <span class="Constant">1000</span><span class="Delimiter">);</span> <span class="SalientComment">//:: Recipes</span> <span class="Comment">//:</span> <span class="Comment">//: 0 - unused (IDLE; do nothing)</span> <span class="Comment">//: 1-199 - primitives</span> assert<span class="Delimiter">(</span>MAX_PRIMITIVE_RECIPES &lt; <span class="Constant">200</span><span class="Delimiter">);</span> <span class="Comment">//: 200-999 - defined in .mu files as sequences of primitives</span> assert<span class="Delimiter">(</span>Next_recipe_ordinal == <span class="Constant">1000</span><span class="Delimiter">);</span> <span class="Comment">//: 1000 onwards - reserved for tests, cleared between tests</span> <span class="SalientComment">//:: Depths for tracing</span> <span class="Comment">//:</span> <span class="Comment">//: 0 - unused</span> <span class="Comment">//: 1-100 - app-level trace statements in mu</span> <span class="Comment">//: 101-9989 - call-stack statements (mostly label run)</span> assert<span class="Delimiter">(</span>Initial_callstack_depth == <span class="Constant">101</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Max_callstack_depth == <span class="Constant">9989</span><span class="Delimiter">);</span> <span class="Comment">//: 9990-9999 - intra-instruction lines (mostly label mem)</span> <span class="SalientComment">//:: Summary of transforms and their dependencies</span> <span class="Comment">//: begin transforms</span> <span class="Comment">//: begin instruction inserting transforms</span> <span class="Comment">//: 52 insert fragments</span> <span class="Comment">//: ↳ 52.2 check fragments</span> <span class="Comment">//: ---</span> <span class="Comment">//: 53 rewrite 'stash' instructions</span> <span class="Comment">//: end instruction inserting transforms</span> <span class="Comment">//:</span> <span class="Comment">//: begin instruction modifying transforms</span> <span class="Comment">//: 56.2 check header ingredients</span> <span class="Comment">//: ↳ 56.4 fill in return ingredients</span> <span class="Comment">//: 48 check or set types by name</span> <span class="Comment">//:</span> <span class="Comment">//: begin type modifying transforms</span> <span class="Comment">//: 56.3 deduce types from header</span> <span class="Comment">//: ---</span> <span class="Comment">//: 30 check or set invalid containers</span> <span class="Comment">//: end type modifying transforms</span> <span class="Comment">//: ↱ 46 collect surrounding spaces</span> <span class="Comment">//: ↳ 42 transform names</span> <span class="Comment">//: ↳ 57 static dispatch</span> <span class="Comment">//: ---</span> <span class="Comment">//: 13 update instruction operation</span> <span class="Comment">//: 40 transform braces</span> <span class="Comment">//: 41 transform labels</span> <span class="Comment">//: end instruction modifying transforms</span> <span class="Comment">//: ↳ 60 check immutable ingredients</span> <span class="Comment">//:</span> <span class="Comment">//: begin checks</span> <span class="Comment">//: ---</span> <span class="Comment">//: 21 check instruction</span> <span class="Comment">//: ↳ 61 check indirect calls against header</span> <span class="Comment">//: ↳ 56 check calls against header</span> <span class="Comment">//: ↳ 43 transform 'new' to 'allocate'</span> <span class="Comment">//: 30 check merge calls</span> <span class="Comment">//: 36 check types of return instructions</span> <span class="Comment">//: 43 check default space</span> <span class="Comment">//: 56 check return instructions against header</span> <span class="Comment">//: end checks</span> <span class="Comment">//: end transforms</span> <span class="SalientComment">//:: Summary of type-checking in different phases</span> <span class="Comment">//: when dispatching instructions we accept first recipe that:</span> <span class="Comment">//: strictly matches all types</span> <span class="Comment">//: maps literal 0 or literal 1 to boolean for some ingredients</span> <span class="Comment">//: performs some other acceptable type conversion</span> <span class="Comment">//: literal 0 -&gt; address</span> <span class="Comment">//: literal -&gt; character</span> <span class="Comment">//: when checking instructions we ensure that types match, and that literals map to some scalar</span> <span class="Comment">//: (address can only map to literal 0)</span> <span class="Comment">//: (boolean can only map to literal 0 or literal 1)</span> <span class="Comment">//: (but conditionals can take any scalar)</span> <span class="Comment">//: at runtime we perform no checks</span> </pre> </body> </html> <!-- vim: set foldmethod=manual : -->