diff options
Diffstat (limited to 'html/031address.cc.html')
-rw-r--r-- | html/031address.cc.html | 145 |
1 files changed, 65 insertions, 80 deletions
diff --git a/html/031address.cc.html b/html/031address.cc.html index 2f88d3e2..1709e1a1 100644 --- a/html/031address.cc.html +++ b/html/031address.cc.html @@ -13,16 +13,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> </style> @@ -35,14 +34,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } <body> <pre id='vimCodeElement'> <span class="Comment">//: Instructions can read from addresses pointing at other locations using the</span> -<span class="Comment">//: 'deref' property.</span> +<span class="Comment">//: 'lookup' property.</span> <span class="Delimiter">:(scenario copy_indirect)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</span>:number<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">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/deref + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:number/lookup ] <span class="traceContains">+mem: storing 34 in location 3</span> @@ -50,11 +49,11 @@ recipe main [ x = 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">//: 'deref' property</span> +<span class="Comment">//: 'lookup' property</span> <span class="Delimiter">:(scenario store_indirect)</span> recipe main [ - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">1</span>:address:number/deref<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">1</span>:address:number/lookup<span class="Special"> <- </span>copy <span class="Constant">34</span> ] <span class="traceContains">+mem: storing 34 in location 2</span> @@ -63,26 +62,26 @@ x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> reagent 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> x<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> x<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << "canonize\n"; //? 1</span> reagent r = x<span class="Delimiter">;</span> <span class="CommentedCode">//? cout << x.to_string() << " => " << r.to_string() << '\n'; //? 1</span> - <span class="Normal">while</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"deref"</span><span class="Delimiter">))</span> - r = deref<span class="Delimiter">(</span>r<span class="Delimiter">);</span> + while <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"lookup"</span><span class="Delimiter">))</span> + r = lookup_memory<span class="Delimiter">(</span>r<span class="Delimiter">);</span> <span class="Identifier">return</span> r<span class="Delimiter">;</span> <span class="Delimiter">}</span> -reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "deref: " << x.to_string() << "\n"; //? 2</span> - <span class="Normal">static</span> <span class="Normal">const</span> type_ordinal ADDRESS = Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">;</span> +reagent lookup_memory<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? cout << "lookup_memory: " << x.to_string() << "\n"; //? 2</span> + static const type_ordinal ADDRESS = Type_ordinal[<span class="Constant">"address"</span>]<span class="Delimiter">;</span> reagent result<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != ADDRESS<span class="Delimiter">)</span> <span class="Delimiter">{</span> - raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /deref "</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> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != ADDRESS<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << 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> result<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 << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": tried to /deref 0</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << 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> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> result<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span> @@ -91,15 +90,15 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< <span class="Comment">// populate types</span> copy<span class="Delimiter">(</span>++x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>result<span class="Delimiter">.</span>types<span class="Delimiter">,</span> result<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span> - <span class="Comment">// drop-one 'deref'</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> - <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> len = SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> - <span class="Normal">for</span> <span class="Delimiter">(</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"deref"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Comment">// drop-one 'lookup'</span> + long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> + long long int len = SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> + for <span class="Delimiter">(</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"lookup"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> - ++i<span class="Delimiter">;</span> <span class="Comment">// skip first deref</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + ++i<span class="Delimiter">;</span> <span class="Comment">// skip first lookup</span> + for <span class="Delimiter">(;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> @@ -108,19 +107,19 @@ reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)< <span class="SalientComment">//:: 'get' can read from container address</span> <span class="Delimiter">:(scenario get_indirect)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</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">35</span> + <span class="Constant">4</span>:number<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 4</span> -<span class="Delimiter">:(scenario include_nonderef_properties)</span> +<span class="Delimiter">:(scenario include_nonlookup_properties)</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</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">35</span> + <span class="Constant">4</span>:number<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 4</span> @@ -130,78 +129,64 @@ base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</s <span class="Delimiter">:(scenario get_address_indirect)</span> <span class="Comment"># 'get' can read from container address</span> recipe main [ - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal - <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:number<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</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">35</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/lookup<span class="Delimiter">,</span> <span class="Constant">0</span>:offset ] <span class="traceContains">+mem: storing 2 in location 4</span> <span class="Delimiter">:(after "reagent base = " following "case GET_ADDRESS:")</span> base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span> -<span class="SalientComment">//:: Helpers for debugging</span> +<span class="SalientComment">//:: abbreviation for '/lookup': a prefix '*'</span> -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_DUMP_TRACE<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$dump-trace"</span>] = _DUMP_TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP_TRACE: <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> - DUMP<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> - DUMP<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="Delimiter">);</span> - <span class="Delimiter">}</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> -<span class="Delimiter">}</span> +<span class="Delimiter">:(scenario lookup_abbreviation)</span> +recipe main [ + <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2</span> + <span class="Constant">2</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">+mem: storing 34 in location 3</span> -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_CLEAR_TRACE<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$clear-trace"</span>] = _CLEAR_TRACE<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _CLEAR_TRACE: <span class="Delimiter">{</span> - CLEAR_TRACE<span class="Delimiter">;</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Parsing reagent")</span> +<span class="Delimiter">{</span> + while <span class="Delimiter">(</span>!name<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && name<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><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> vector<string> ><span class="Delimiter">(</span><span class="Constant">"lookup"</span><span class="Delimiter">,</span> vector<string><span class="Delimiter">()));</span> + <span class="Delimiter">}</span> + if <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="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> -_DUMP_MEMORY<span class="Delimiter">,</span> -<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_ordinal[<span class="Constant">"$dump-memory"</span>] = _DUMP_MEMORY<span class="Delimiter">;</span> -<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _DUMP_MEMORY: <span class="Delimiter">{</span> - dump_memory<span class="Delimiter">();</span> - <span class="Identifier">break</span><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> Recipe_ordinal[<span class="Constant">"$dump"</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> +case _DUMP: <span class="Delimiter">{</span> reagent after_canonize = canonize<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> cerr << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": "</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> << 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="Constant">" => "</span> << after_canonize<span class="Delimiter">.</span>value << <span class="Constant">" => "</span> << Memory[after_canonize<span class="Delimiter">.</span>value] << <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">long</span> <span class="Normal">long</span> <span class="Normal">int</span> foo = -<span class="Constant">1</span><span class="Delimiter">;</span> +long long int foo = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> _FOO<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> Recipe_ordinal[<span class="Constant">"$foo"</span>] = _FOO<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> -<span class="Normal">case</span> _FOO: <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>foo != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr << foo << <span class="Constant">": "</span> << Memory[foo] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> - <span class="Normal">else</span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +case _FOO: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>foo != -<span class="Constant">1</span><span class="Delimiter">)</span> cerr << foo << <span class="Constant">": "</span> << Memory[foo] << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + else cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">else</span> <span class="Delimiter">{</span> + else <span class="Delimiter">{</span> foo = canonize<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="Delimiter">}</span> <span class="Identifier">break</span><span class="Delimiter">;</span> |