diff options
Diffstat (limited to 'html/subx/011run.cc.html')
-rw-r--r-- | html/subx/011run.cc.html | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/html/subx/011run.cc.html b/html/subx/011run.cc.html index f1137805..c06a3b32 100644 --- a/html/subx/011run.cc.html +++ b/html/subx/011run.cc.html @@ -15,18 +15,18 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } +.cSpecial { color: #008000; } .traceContains { color: #008000; } -.PreProc { color: #800080; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } -.Special { color: #c00000; } -.Delimiter { color: #800080; } .SalientComment { color: #00ffff; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } +.PreProc { color: #800080; } --> </style> @@ -67,39 +67,39 @@ if ('onhashchange' in window) { <span id="L4" class="LineNr"> 4 </span><span class="Comment">//: the VM. That comes later.)</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> -<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"syntax"</span><span class="Delimiter">,</span> -<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"SubX programs consist of <a href='011run.cc.html#L100'>segments</a>, each segment in turn consisting of lines.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"Line-endings are significant; each <a href='011run.cc.html#L117'>line</a> should contain a single</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"instruction, macro or directive.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"Comments start with the '#' character. It should be at the start of a <a href='011run.cc.html#L123'>word</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"(start of <a href='011run.cc.html#L117'>line</a>, or following a space).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"Each segment starts with a header <a href='011run.cc.html#L117'>line</a>: a '==' delimiter followed by the name of</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"the segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"Currently SubX assumes the first segment encountered contains executable <a href='031check_operands.cc.html#L11'>code</a>, and</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"the second contains global variables. By convention we call them 'code' and 'data'</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"respectively.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"The first instruction executed in the resulting binary is always the first</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"instruction of the first segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"Segments with the same name get merged together. This rule helps keep functions and</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"their data close together in .subx files.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L26" class="LineNr"> 26 </span> <span class="Constant">"Later <a href='011run.cc.html#L100'>segments</a> with the same name get their <a href='003trace.cc.html#L74'>contents</a> *prepended* to earlier ones.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L27" class="LineNr"> 27 </span> <span class="Constant">"This rule helps each .subx file to <a href='001help.cc.html#L243'>put</a> forth a different entrypoint for the binary,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L28" class="LineNr"> 28 </span> <span class="Constant">"overriding previously loaded files.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"Lines consist of a series of words. Words can contain arbitrary metadata</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L31" class="LineNr"> 31 </span> <span class="Constant">"after a '/', but they can never contain whitespace. Metadata has no effect</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L32" class="LineNr"> 32 </span> <span class="Constant">"at runtime, but can be handy when rewriting macros.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L34" class="LineNr"> 34 </span> <span class="Constant">"Check out the examples in the examples/ directory.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"Programming in machine <a href='031check_operands.cc.html#L11'>code</a> can be annoying, but let's see if we can make</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Constant">"it nice enough to be able to write a compiler in it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"syntax"</span><span class="Delimiter">,</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"SubX programs consist of <a href='011run.cc.html#L100'>segments</a>, each segment in turn consisting of lines.\n"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"Line-endings are significant; each <a href='011run.cc.html#L117'>line</a> should contain a single\n"</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"instruction, macro or directive.\n"</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"\n"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"Comments start with the '#' character. It should be at the start of a word\n"</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"(start of <a href='011run.cc.html#L117'>line</a>, or following a space).\n"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"\n"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"Each segment starts with a header <a href='011run.cc.html#L117'>line</a>: a '==' delimiter followed by the name of\n"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"the segment.\n"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"\n"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"Currently SubX assumes the first segment encountered contains executable <a href='031check_operands.cc.html#L11'>code</a>, and\n"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"the second contains global variables. By convention we call them 'code' and 'data'\n"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"respectively.\n"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"The first instruction executed in the resulting binary is always the first\n"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"instruction of the first segment.\n"</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"\n"</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"Segments with the same name get merged together. This rule helps keep functions and\n"</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"their data close together in .subx files.\n"</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Constant">"Later <a href='011run.cc.html#L100'>segments</a> with the same name get their <a href='003trace.cc.html#L74'>contents</a> *prepended* to earlier ones.\n"</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Constant">"This rule helps each .subx file to <a href='001help.cc.html#L243'>put</a> forth a different entrypoint for the binary,\n"</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Constant">"overriding previously loaded files.\n"</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"\n"</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"Lines consist of a series of words. Words can contain arbitrary metadata\n"</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Constant">"after a '/', but they can never contain whitespace. Metadata has no effect\n"</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Constant">"at runtime, but can be handy when rewriting macros.\n"</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Constant">"\n"</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Constant">"Check out the examples in the examples/ directory.\n"</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"Programming in machine <a href='031check_operands.cc.html#L11'>code</a> can be annoying, but let's see if we can make\n"</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Constant">"it nice enough to be able to write a compiler in it.\n"</span> <span id="L37" class="LineNr"> 37 </span><span class="Delimiter">);</span> <span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> -<span id="L39" class="LineNr"> 39 </span>cerr << <span class="Constant">" syntax</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L39" class="LineNr"> 39 </span>cerr << <span class="Constant">" syntax\n"</span><span class="Delimiter">;</span> <span id="L40" class="LineNr"> 40 </span> <span id="L41" class="LineNr"> 41 </span><span class="Delimiter">:(scenario add_imm32_to_eax)</span> <span id="L42" class="LineNr"> 42 </span><span class="Comment"># At the lowest level, SubX programs are a series of hex bytes, each</span> @@ -152,8 +152,8 @@ if ('onhashchange' in window) { <span id="L89" class="LineNr"> 89 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L90" class="LineNr"> 90 </span> <a href='011run.cc.html#L240'>load</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> <span id="L91" class="LineNr"> 91 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <a href='010---vm.cc.html#L185'>End_of_program</a><span class="Delimiter">)</span> -<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L287'>run_one_instruction</a><span class="Delimiter">();</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span><span class="Delimiter">)</span> +<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L296'>run_one_instruction</a><span class="Delimiter">();</span> <span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> <span id="L95" class="LineNr"> 95 </span> <span id="L96" class="LineNr"> 96 </span><span class="SalientComment">//:: core data structures</span> @@ -218,7 +218,7 @@ if ('onhashchange' in window) { <span id="L155" class="LineNr">155 </span> s<span class="Delimiter">.</span>start = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>segment_title<span class="Delimiter">);</span> <span id="L156" class="LineNr">156 </span> <a href='011run.cc.html#L201'>sanity_check_program_segment</a><span class="Delimiter">(</span>out<span class="Delimiter">,</span> s<span class="Delimiter">.</span>start<span class="Delimiter">);</span> <span id="L157" class="LineNr">157 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment from 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << s<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> +<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment from 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << s<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> <span id="L159" class="LineNr">159 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>s<span class="Delimiter">);</span> <span id="L160" class="LineNr">160 </span> <span class="Delimiter">}</span> <span id="L161" class="LineNr">161 </span> <span class="Comment">// End Segment Parsing Special-cases(segment_title)</span> @@ -243,7 +243,7 @@ if ('onhashchange' in window) { <span id="L180" class="LineNr">180 </span><span class="Normal">void</span> <a href='011run.cc.html#L180'>flush</a><span class="Delimiter">(</span>program& p<span class="Delimiter">,</span> vector<line>& <a href='011run.cc.html#L109'>lines</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L181" class="LineNr">181 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L182" class="LineNr">182 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L183" class="LineNr">183 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L183" class="LineNr">183 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header\n"</span> << end<span class="Delimiter">();</span> <span id="L184" class="LineNr">184 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L185" class="LineNr">185 </span> <span class="Delimiter">}</span> <span id="L186" class="LineNr">186 </span> <span class="Comment">// End flush(p, lines) Special-cases</span> @@ -289,12 +289,12 @@ if ('onhashchange' in window) { <span id="L226" class="LineNr">226 </span><span class="Delimiter">:(before "End Types")</span> <span id="L227" class="LineNr">227 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>program&<span class="Delimiter">);</span> <span id="L228" class="LineNr">228 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L229" class="LineNr">229 </span>vector<transform_fn> <a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span>vector<transform_fn> <span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">;</span> <span id="L230" class="LineNr">230 </span> <span id="L231" class="LineNr">231 </span><span class="Normal">void</span> <a href='011run.cc.html#L231'>transform</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L232" class="LineNr">232 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> -<span id="L233" class="LineNr">233 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> -<span id="L234" class="LineNr">234 </span> <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>p<span class="Delimiter">);</span> +<span id="L233" class="LineNr">233 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> +<span id="L234" class="LineNr">234 </span> <span class="Delimiter">(</span>*<span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>p<span class="Delimiter">);</span> <span id="L235" class="LineNr">235 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"done"</span> << end<span class="Delimiter">();</span> <span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> <span id="L237" class="LineNr">237 </span> @@ -303,7 +303,7 @@ if ('onhashchange' in window) { <span id="L240" class="LineNr">240 </span><span class="Normal">void</span> <a href='011run.cc.html#L240'>load</a><span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L241" class="LineNr">241 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> <span id="L242" class="LineNr">242 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no <a href='031check_operands.cc.html#L11'>code</a> to <a href='011run.cc.html#L83'>run</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no <a href='031check_operands.cc.html#L11'>code</a> to run\n"</span> << end<span class="Delimiter">();</span> <span id="L244" class="LineNr">244 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L245" class="LineNr">245 </span> <span class="Delimiter">}</span> <span id="L246" class="LineNr">246 </span> <span class="Comment">// Ensure segments are disjoint.</span> @@ -312,8 +312,8 @@ if ('onhashchange' in window) { <span id="L249" class="LineNr">249 </span> <span class="Normal">const</span> segment& seg = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span id="L250" class="LineNr">250 </span> <span class="Normal">uint32_t</span> addr = seg<span class="Delimiter">.</span>start<span class="Delimiter">;</span> <span id="L251" class="LineNr">251 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!already_allocated<span class="Delimiter">(</span>addr<span class="Delimiter">))</span> -<span id="L252" class="LineNr">252 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>seg<span class="Delimiter">.</span>start<span class="Delimiter">));</span> -<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"loading segment "</span> << i << <span class="Constant">" from "</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> +<span id="L252" class="LineNr">252 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>seg<span class="Delimiter">.</span>start<span class="Delimiter">));</span> +<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"loading segment "</span> << i << <span class="Constant">" from "</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> <span id="L254" class="LineNr">254 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>seg<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L255" class="LineNr">255 </span> <span class="Normal">const</span> line& l = seg<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> <span id="L256" class="LineNr">256 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> k = <span class="Constant">0</span><span class="Delimiter">;</span> k < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++k<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -321,13 +321,13 @@ if ('onhashchange' in window) { <span id="L258" class="LineNr">258 </span> <span class="Normal">uint8_t</span> val = <a href='011run.cc.html#L273'>hex_byte</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> <span id="L259" class="LineNr">259 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L260" class="LineNr">260 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>addr<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L261" class="LineNr">261 </span> <a href='010---vm.cc.html#L254'>write_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">,</span> val<span class="Delimiter">);</span> +<span id="L261" class="LineNr">261 </span> <a href='010---vm.cc.html#L263'>write_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">,</span> val<span class="Delimiter">);</span> <span id="L262" class="LineNr">262 </span> overlap<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" -> "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> +<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" -> "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> <span id="L264" class="LineNr">264 </span> ++addr<span class="Delimiter">;</span> <span id="L265" class="LineNr">265 </span> <span class="Delimiter">}</span> <span id="L266" class="LineNr">266 </span> <span class="Delimiter">}</span> -<span id="L267" class="LineNr">267 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <span class="Constant">0</span><span class="Delimiter">)</span> <a href='010---vm.cc.html#L185'>End_of_program</a> = addr<span class="Delimiter">;</span> +<span id="L267" class="LineNr">267 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> = addr<span class="Delimiter">;</span> <span id="L268" class="LineNr">268 </span> <span class="Delimiter">}</span> <span id="L269" class="LineNr">269 </span> <a href='010---vm.cc.html#L29'>EIP</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>start<span class="Delimiter">;</span> <span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"done"</span> << end<span class="Delimiter">();</span> @@ -338,11 +338,11 @@ if ('onhashchange' in window) { <span id="L275" class="LineNr">275 </span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L276" class="LineNr">276 </span> in >> std::hex >> result<span class="Delimiter">;</span> <span id="L277" class="LineNr">277 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!in || !in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L278" class="LineNr">278 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L278" class="LineNr">278 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte\n"</span> << end<span class="Delimiter">();</span> <span id="L279" class="LineNr">279 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span id="L280" class="LineNr">280 </span> <span class="Delimiter">}</span> <span id="L281" class="LineNr">281 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result > <span class="Constant">0xff</span> || result < -<span class="Constant">0x8f</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L282" class="LineNr">282 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L282" class="LineNr">282 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte\n"</span> << end<span class="Delimiter">();</span> <span id="L283" class="LineNr">283 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span id="L284" class="LineNr">284 </span> <span class="Delimiter">}</span> <span id="L285" class="LineNr">285 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">uint8_t</span>><span class="Delimiter">(</span>result<span class="Delimiter">);</span> @@ -390,24 +390,24 @@ if ('onhashchange' in window) { <span id="L327" class="LineNr">327 </span><span class="SalientComment">//:: run</span> <span id="L328" class="LineNr">328 </span> <span id="L329" class="LineNr">329 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L330" class="LineNr">330 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">"add imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (add)"</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">"add imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (add)"</span><span class="Delimiter">);</span> <span id="L331" class="LineNr">331 </span> <span id="L332" class="LineNr">332 </span><span class="Comment">//: our first opcode</span> <span id="L333" class="LineNr">333 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L334" class="LineNr">334 </span><span class="Normal">case</span> <span class="Constant">0x05</span>: <span class="Delimiter">{</span> <span class="Comment">// add imm32 to EAX</span> <span id="L335" class="LineNr">335 </span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L336" class="LineNr">336 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" to <a href='010---vm.cc.html#L23'>reg</a> EAX"</span> << end<span class="Delimiter">();</span> -<span id="L337" class="LineNr">337 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L336" class="LineNr">336 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" to <a href='010---vm.cc.html#L23'>reg</a> EAX"</span> << end<span class="Delimiter">();</span> +<span id="L337" class="LineNr">337 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L338" class="LineNr">338 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L339" class="LineNr">339 </span><span class="Delimiter">}</span> <span id="L340" class="LineNr">340 </span> <span id="L341" class="LineNr">341 </span><span class="Delimiter">:(code)</span> <span id="L342" class="LineNr">342 </span><span class="Comment">// read a 32-bit int in little-endian order from the instruction stream</span> <span id="L343" class="LineNr">343 </span><span class="Normal">int32_t</span> <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L344" class="LineNr">344 </span> <span class="Normal">int32_t</span> result = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> -<span id="L345" class="LineNr">345 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">8</span><span class="Delimiter">);</span> -<span id="L346" class="LineNr">346 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">16</span><span class="Delimiter">);</span> -<span id="L347" class="LineNr">347 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">24</span><span class="Delimiter">);</span> +<span id="L344" class="LineNr">344 </span> <span class="Normal">int32_t</span> result = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> +<span id="L345" class="LineNr">345 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L346" class="LineNr">346 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">16</span><span class="Delimiter">);</span> +<span id="L347" class="LineNr">347 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">24</span><span class="Delimiter">);</span> <span id="L348" class="LineNr">348 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span id="L349" class="LineNr">349 </span><span class="Delimiter">}</span> <span id="L350" class="LineNr">350 </span> |