# primitive for editing text
type gap-buffer {
left: grapheme-stack
right: grapheme-stack
# some fields for scanning incrementally through a gap-buffer
left-read-index: int
right-read-index: int
}
fn initialize-gap-buffer _self: (addr gap-buffer), capacity: int {
var self/esi: (addr gap-buffer) <- copy _self
var left/eax: (addr grapheme-stack) <- get self, left
initialize-grapheme-stack left, capacity
var right/eax: (addr grapheme-stack) <- get self, right
initialize-grapheme-stack right, capacity
}
fn clear-gap-buffer _self: (addr gap-buffer) {
var self/esi: (addr gap-buffer) <- copy _self
var left/eax: (addr grapheme-stack) <- get self, left
clear-grapheme-stack left
var right/eax: (addr grapheme-stack) <- get self, right
clear-grapheme-stack right
}
fn gap-buffer-empty? _self: (addr gap-buffer) -> _/eax: boolean {
var self/esi: (addr gap-buffer) <- copy _self
# if !empty?(left) return false
{
var left/eax: (addr grapheme-stack) <- get self, left
var result/eax: boolean <- grapheme-stack-empty? left
compare result, 0/false
break-if-!=
return 0/false
}
# return empty?(right)
var left/eax: (addr grapheme-stack) <- get self, left
var result/eax: boolean <- grapheme-stack-empty? left
return result
}
fn gap-buffer-capacity _gap: (addr gap-buffer) -> _/edx: int {
var gap/esi: (addr gap-buffer) <- copy _gap
var left/eax: (addr grapheme-stack) <- get gap, left
var left-data-ah/eax: (addr handle array grapheme) <- get left, data
var left-data/eax: (addr array grapheme) <- lookup *left-data-ah
var result/eax: int <- length left-data
return result
}
# just for tests
fn initialize-gap-buffer-with self: (addr gap-buffer), keys: (addr array byte) {
initialize-gap-buffer self, 0x40/capacity
var input-stream-storage: (stream byte 0x40/capacity)
var input-stream/ecx: (addr stream byte) <- address input-stream-storage
write input-stream, keys
{
var done?/eax: boolean <- stream-empty? input-stream
compare done?, 0/false
break-if-!=
var g/eax: grapheme <- read-grapheme input-stream
add-grapheme-at-gap self, g
loop
}
}
fn load-gap-buffer-from-stream self: (addr gap-buffer), in: (addr streampre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */<!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 - 035lookup.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; }
.traceAbsent { color: #c00000; }
.cSpecial { color: #008000; }
.traceContains { color: #008000; }
.SalientComment { color: #00ffff; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.Identifier { color: #fcb165; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Go from an address to the payload it points at (skipping the refcount)</span>
<span class="Comment">//: using /lookup.</span>
<span class="Comment">//:</span>
<span class="Comment">//: Let's say we have this address (read the top of the address layer for</span>
<span class="Comment">//: details on these diagrams):</span>
<span class="Comment">//:</span>
<span class="Comment">//: +---+------------+</span>
<span class="Comment">//: x -------> | 1 | number |</span>
<span class="Comment">//: +---+------------+</span>
<span class="Comment">//:</span>
<span class="Comment">//: Once you have an address you can read or modify its payload by performing</span>
<span class="Comment">//: a lookup:</span>
<span class="Comment">//:</span>
<span class="Comment">//: x/lookup <- copy 34</span>
<span class="Comment">//:</span>
<span class="Comment">//: or more concisely:</span>
<span class="Comment">//:</span>
<span class="Comment">//: *x <- copy 34</span>
<span class="Comment">//:</span>
<span class="Comment">//: This modifies not x, but the payload x points to:</span>
<span class="Comment">//:</span>
<span class="Comment">//: +---+------------+</span>
<span class="Comment">//: x -------> | 1 | 34 |</span>
<span class="Comment">//: +---+------------+</span>
<span class="Comment">//:</span>
<span class="Comment">//: You can also read from the payload in instructions like this:</span>
<span class="Comment">//:</span>
<span class="Comment">//: z:num <- add *x, 1</span>
<span class="Comment">//:</span>
<span class="Comment">//: After this instruction runs the value of z will be 35.</span>
<span class="Comment">//:</span>
<span class="Comment">//: The tests in this layer use unsafe operations so as to stay decoupled from</span>
<span class="Comment">//: 'new'.</span>
<span class="Delimiter">:(scenario copy_indirect)</span>
def main [
<span class="Constant">1</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Comment"># This loads location 1 as an address and looks up *that* location.</span>
<span class="Constant">2</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:num/lookup
]
<span class="Comment"># 1 contains 10. Skip refcount and lookup location 11.</span>
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(before "End Preprocess read_memory(x)")</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Comment">//: similarly, write to addresses pointing at other locations using the</span>
<span class="Comment">//: 'lookup' property</span>
<span class="Delimiter">:(scenario store_indirect)</span>
def main [
<span class="Constant">1</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">1</span>:address:num/lookup<span class="Special"> <- </span>copy <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 11</span>
<span class="Delimiter">:(before "End Preprocess write_memory(x, data)")</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Comment">//: writes to address 0 always loudly fail</span>
<span class="Delimiter">:(scenario store_to_0_fails)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
<span class="Constant">1</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">0</span>
<span class="Constant">1</span>:address:num/lookup<span class="Special"> <- </span>copy <span class="Constant">34</span>
]
<span class="traceAbsent">-mem: storing 34 in location 0</span>
<span class="traceContains">+error: can't write to location 0 in '1:address:num/lookup <- copy 34'</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> canonize<span class="Delimiter">(</span>reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Comment">// End canonize(x) Special-cases</span>
<span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">))</span>
lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> lookup_memory<span class="Delimiter">(</span>reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type || x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom || x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to /lookup '"</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">"' but it isn't an address</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Comment">// compute value</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"tried to /lookup 0</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
lookup_memory_core<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> lookup_memory_core<span class="Delimiter">(</span>reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"location "</span> << x<span class="Delimiter">.</span>value << <span class="Constant">" is "</span> << no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">))</span> << end<span class="Delimiter">();</span>
x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">));</span>
drop_from_type<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">)</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"skipping refcount at "</span> << x<span class="Delimiter">.</span>value << end<span class="Delimiter">();</span>
x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// skip refcount</span>
<span class="Delimiter">}</span>
drop_one_lookup<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> test_lookup_address_skips_refcount<span class="Delimiter">()</span> <span class="Delimiter">{</span>
reagent x<span class="Delimiter">(</span><span class="Constant">"*x:address:num"</span><span class="Delimiter">);</span>
x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">34</span><span class="Delimiter">);</span> <span class="Comment">// unsafe</span>
put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">1000</span><span class="Delimiter">);</span>
lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
CHECK_TRACE_CONTENTS<span class="Delimiter">(</span><span class="Constant">"mem: skipping refcount at 1000"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> <span class="Constant">1001</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> test_lookup_zero_address_does_not_skip_refcount<span class="Delimiter">()</span> <span class="Delimiter">{</span>
reagent x<span class="Delimiter">(</span><span class="Constant">"*x:address:num"</span><span class="Delimiter">);</span>
x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">34</span><span class="Delimiter">);</span> <span class="Comment">// unsafe</span>
put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
lookup_memory<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
CHECK_TRACE_DOESNT_CONTAIN<span class="Delimiter">(</span><span class="Constant">"mem: skipping refcount at 0"</span><span class="Delimiter">);</span>
CHECK_EQ<span class="Delimiter">(</span>x<span class="Delimiter">.</span>value<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Preprocess types_strictly_match(reagent to, reagent from)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>to<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>from<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Preprocess is_mu_array(reagent r)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Preprocess is_mu_address(reagent r)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Preprocess is_mu_number(reagent r)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Preprocess is_mu_boolean(reagent r)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Preprocess is_mu_character(reagent r)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update product While Type-checking Merge")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Compute Call Ingredient")</span>
canonize_type<span class="Delimiter">(</span>ingredient<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Preprocess NEXT_INGREDIENT product")</span>
canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Check RETURN Copy(lhs, rhs)</span>
canonize_type<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span>
canonize_type<span class="Delimiter">(</span>rhs<span class="Delimiter">);</span>
<span class="Delimiter">:(before "Compute Container Size(reagent rcopy)")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>rcopy<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Compute Container Size(element, full_type)")</span>
assert<span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">));</span>
<span class="Delimiter">:(before "Compute Exclusive Container Size(element, full_type)")</span>
assert<span class="Delimiter">(</span>!has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">));</span>
<span class="Delimiter">:(code)</span>
<span class="Normal">bool</span> canonize_type<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type || r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom || !r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left || !r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom || r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value != get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
raise << <span class="Constant">"can't lookup non-address: '"</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">)</span> << <span class="Constant">"': '"</span> << to_string<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">);</span>
drop_one_lookup<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Normal">void</span> drop_one_lookup<span class="Delimiter">(</span>reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">for</span> <span class="Delimiter">(</span>vector<pair<string<span class="Delimiter">,</span> string_tree*> >::iterator p = r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">-></span>first == <span class="Constant">"lookup"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>p<span class="Delimiter">);</span>
<span class="Identifier">return</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">}</span>
assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Comment">//: Tedious fixup to support addresses in container/array instructions of previous layers.</span>
<span class="Comment">//: Most instructions don't require fixup if they use the 'ingredients' and</span>
<span class="Comment">//: 'products' variables in run_current_routine().</span>
<span class="Delimiter">:(scenario get_indirect)</span>
def main [
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span>
<span class="Constant">2</span>:num<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(scenario get_indirect2)</span>
def main [
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span>
<span class="Constant">2</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">20</span>/unsafe
<span class="Constant">2</span>:address:num/lookup<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+mem: storing 34 in location 21</span>
<span class="Delimiter">:(scenario include_nonlookup_properties)</span>
def main [
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span>
<span class="Constant">2</span>:num<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/lookup/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(after "Update GET base in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update GET product in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update GET base in Run")</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario put_indirect)</span>
def main [
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span>
<span class="Constant">1</span>:address:point/lookup<span class="Special"> <- </span>put <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset<span class="Delimiter">,</span> <span class="Constant">36</span>
]
<span class="traceContains">+mem: storing 36 in location 11</span>
<span class="Delimiter">:(after "Update PUT base in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update PUT offset in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>offset<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update PUT base in Run")</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario put_product_error_with_lookup)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span>
<span class="Constant">1</span>:address:point<span class="Special"> <- </span>put <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> x:offset<span class="Delimiter">,</span> <span class="Constant">36</span>
]
<span class="traceContains">+error: main: product of 'put' must be first ingredient '1:address:point/lookup', but got '1:address:point'</span>
<span class="Delimiter">:(before "End PUT Product Checks")</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> p = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>p<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> i = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>p<span class="Delimiter">,</span> i<span class="Delimiter">))</span> <span class="Delimiter">{</span>
raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"product of 'put' must be first ingredient '"</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="Constant">"', but got '"</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario new_error)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
<span class="Constant">1</span>:num/<span class="Special">raw <- </span><span class="Normal">new</span> number:type
]
<span class="traceContains">+error: main: product of 'new' has incorrect type: '1:num/raw <- new number:type'</span>
<span class="Delimiter">:(after "Update NEW product in Check")</span>
canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario copy_array_indirect)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">13</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">14</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:array:num<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:array:num/lookup
]
<span class="traceContains">+mem: storing 3 in location 2</span>
<span class="traceContains">+mem: storing 14 in location 3</span>
<span class="traceContains">+mem: storing 15 in location 4</span>
<span class="traceContains">+mem: storing 16 in location 5</span>
<span class="Delimiter">:(scenario create_array_indirect)</span>
def main [
<span class="Constant">1000</span>:num/<span class="Special">raw <- </span>copy <span class="Constant">1</span> <span class="Comment"># pretend refcount</span>
<span class="Constant">1</span>:address:array:num:<span class="Constant">3</span><span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe <span class="Comment"># pretend allocation</span>
<span class="Constant">1</span>:address:array:num:<span class="Constant">3</span>/lookup<span class="Special"> <- </span>create-array
]
<span class="traceContains">+mem: storing 3 in location 1001</span>
<span class="Delimiter">:(after "Update CREATE_ARRAY product in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(after "Update CREATE_ARRAY product in Run")</span>
canonize<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario index_indirect)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">13</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">14</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:num<span class="Special"> <- </span>index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 15 in location 2</span>
<span class="Delimiter">:(before "Update INDEX base in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update INDEX index in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>index<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update INDEX product in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update INDEX base in Run")</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before "Update INDEX index in Run")</span>
canonize<span class="Delimiter">(</span>index<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario put_index_indirect)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">13</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">14</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">1</span>:address:array:num/lookup<span class="Special"> <- </span>put-index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 13</span>
<span class="Delimiter">:(scenario put_index_indirect_2)</span>
def main [
<span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">2</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">3</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">4</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">5</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
<span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>put-index <span class="Constant">1</span>:array:num:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">5</span>:address:num/lookup<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+mem: storing 34 in location 3</span>
<span class="Delimiter">:(scenario put_index_product_error_with_lookup)</span>
<span class="Special">% Hide_errors = true;</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">13</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">14</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>put-index <span class="Constant">1</span>:address:array:num/lookup<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="traceContains">+error: main: product of 'put-index' must be first ingredient '1:address:array:num/lookup', but got '1:address:array:num'</span>
<span class="Delimiter">:(before "End PUT_INDEX Product Checks")</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> p = inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>p<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> i = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>i<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// error raised elsewhere</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>p<span class="Delimiter">,</span> i<span class="Delimiter">))</span> <span class="Delimiter">{</span>
raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"product of 'put-index' must be first ingredient '"</span> << inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="Constant">"', but got '"</span> << inst<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario dilated_reagent_in_static_array)</span>
def main [
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)}</span><span class="Special"> <- </span>create-array
<span class="Constant">5</span>:address:num<span class="Special"> <- </span><span class="Normal">new</span> number:type
<span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)}</span><span class="Special"> <- </span>put-index <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)},</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">5</span>:address:num
*<span class="Constant">5</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">6</span>:num<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:num
]
<span class="traceContains">+run: creating array of size 4</span>
<span class="traceContains">+mem: storing 34 in location 6</span>
<span class="Delimiter">:(before "Update PUT_INDEX base in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update PUT_INDEX index in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>index<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update PUT_INDEX value in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>value<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update PUT_INDEX base in Run")</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before "Update PUT_INDEX index in Run")</span>
canonize<span class="Delimiter">(</span>index<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario length_indirect)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:array:num:<span class="Constant">3</span><span class="Special"> <- </span>create-array
<span class="Constant">12</span>:num<span class="Special"> <- </span>copy <span class="Constant">14</span>
<span class="Constant">13</span>:num<span class="Special"> <- </span>copy <span class="Constant">15</span>
<span class="Constant">14</span>:num<span class="Special"> <- </span>copy <span class="Constant">16</span>
<span class="Constant">1</span>:address:array:num<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:num<span class="Special"> <- </span>length <span class="Constant">1</span>:address:array:num/lookup
]
<span class="traceContains">+mem: storing 3 in location 2</span>
<span class="Delimiter">:(before "Update LENGTH array in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>array<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update LENGTH array in Run")</span>
canonize<span class="Delimiter">(</span>array<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario maybe_convert_indirect)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
<span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> <- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> i:variant
]
<span class="traceContains">+mem: storing 1 in location 3</span>
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(scenario maybe_convert_indirect_2)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
<span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:address:num<span class="Special"> <- </span>copy <span class="Constant">20</span>/unsafe
<span class="Constant">2</span>:address:num/lookup<span class="Delimiter">,</span> <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> <- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> i:variant
]
<span class="traceContains">+mem: storing 1 in location 3</span>
<span class="traceContains">+mem: storing 34 in location 21</span>
<span class="Delimiter">:(scenario maybe_convert_indirect_3)</span>
def main [
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
<span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">2</span>:address:<span class="Normal">bool</span><span class="Special"> <- </span>copy <span class="Constant">20</span>/unsafe
<span class="Constant">3</span>:num<span class="Delimiter">,</span> <span class="Constant">2</span>:address:<span class="Normal">bool</span>/lookup<span class="Special"> <- </span>maybe-convert <span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Delimiter">,</span> i:variant
]
<span class="traceContains">+mem: storing 1 in location 21</span>
<span class="traceContains">+mem: storing 34 in location 3</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT base in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>base<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT product in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT status in Check")</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!canonize_type<span class="Delimiter">(</span>status<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT base in Run")</span>
canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT product in Run")</span>
canonize<span class="Delimiter">(</span>product<span class="Delimiter">);</span>
<span class="Delimiter">:(before "Update MAYBE_CONVERT status in Run")</span>
canonize<span class="Delimiter">(</span>status<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario merge_exclusive_container_indirect)</span>
def main [
<span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Constant">1</span>:address:number-<span class="Normal">or</span>-point/lookup<span class="Special"> <- </span>merge <span class="Constant">0</span>/number<span class="Delimiter">,</span> <span class="Constant">34</span>
]
<span class="Comment"># skip 10 for refcount</span>
<span class="traceContains">+mem: storing 0 in location 11</span>
<span class="traceContains">+mem: storing 34 in location 12</span>
<span class="Delimiter">:(before "Update size_mismatch Check for MERGE(x)</span>
canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Comment">//: abbreviation for '/lookup': a prefix '*'</span>
<span class="Delimiter">:(scenario lookup_abbreviation)</span>
def main [
<span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe
<span class="Comment"># 10 reserved for refcount</span>
<span class="Constant">11</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>
<span class="Constant">3</span>:number<span class="Special"> <- </span>copy *<span class="Constant">1</span>:address:number
]
<span class="traceContains">+parse: ingredient: {1: ("address" "number"), "lookup": ()}</span>
<span class="traceContains">+mem: storing 34 in location 3</span>
<span class="Delimiter">:(before "End Parsing reagent")</span>
<span class="Delimiter">{</span>
<span class="Normal">while</span> <span class="Delimiter">(</span>starts_with<span class="Delimiter">(</span>name<span class="Delimiter">,</span> <span class="Constant">"*"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
name<span class="Delimiter">.</span>erase<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span>
properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span><span class="Constant">"lookup"</span><span class="Delimiter">,</span> <span class="Constant">NULL</span><span class="Delimiter">));</span>
<span class="Delimiter">}</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>name<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
raise << <span class="Constant">"illegal name '"</span> << original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
<span class="SalientComment">//:: helpers for debugging</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
_DUMP<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"$dump"</span><span class="Delimiter">,</span> _DUMP<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> _DUMP: <span class="Delimiter">{</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> after_canonize = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
canonize<span class="Delimiter">(</span>after_canonize<span class="Delimiter">);</span>
cerr << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name << <span class="Constant">' '</span> << no_scientific<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>value<span class="Delimiter">)</span> << <span class="Constant">" => "</span> << no_scientific<span class="Delimiter">(</span>after_canonize<span class="Delimiter">.</span>value<span class="Delimiter">)</span> << <span class="Constant">" => "</span> << no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> after_canonize<span class="Delimiter">.</span>value<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Comment">//: grab an address, and then dump its value at intervals</span>
<span class="Comment">//: useful for tracking down memory corruption (writing to an out-of-bounds address)</span>
<span class="Delimiter">:(before "End Globals")</span>
<span class="Normal">int</span> Bar = -<span class="Constant">1</span><span class="Delimiter">;</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
_BAR<span class="Delimiter">,</span>
<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">"$bar"</span><span class="Delimiter">,</span> _BAR<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> _BAR: <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>Bar != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr << Bar << <span class="Constant">": "</span> << no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> Bar<span class="Delimiter">))</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
<span class="Normal">else</span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Normal">else</span> <span class="Delimiter">{</span>
reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> tmp = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
canonize<span class="Delimiter">(</span>tmp<span class="Delimiter">);</span>
Bar = tmp<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->