|
|
<!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 - 024jump.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; }
.muRecipe { color: #ff8700; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.traceContains { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.Identifier { color: #c0a020; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Jump primitives</span>
<span class="Delimiter">:(scenario jump_can_skip_instructions)</span>
<span class="muRecipe">def</span> main [
jump <span class="Constant">1:offset</span>
<span class="Constant">1</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
]
<span class="traceContains">+run: jump {1: "offset"}</span>
<span class="traceAbsent">-run: {1: "number"} <- copy {1: "literal"}</span>
<span class="traceAbsent">-mem: storing 1 in location 1</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
JUMP<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">"jump"</span><span class="Delimiter">,</span> JUMP<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Checks")</span>
<span class="Normal">case</span> JUMP: <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><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">"'jump' requires exactly one ingredient, but got '"</span> << inst<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="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</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> <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">"first ingredient of 'jump' should be a label or offset, but got '"</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">"'</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="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> JUMP: <span class="Delimiter">{</span>
assert<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>initialized<span class="Delimiter">);</span>
current_step_index<span class="Delimiter">()</span> += ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>+<span class="Constant">1</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span> << end<span class="Delimiter">();</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of this instruction</span>
<span class="Delimiter">}</span>
<span class="Comment">//: special type to designate jump targets</span>
<span class="Delimiter">:(before "End Mu Types Initialization")</span>
put<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"offset"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
<span class="Delimiter">:(scenario jump_backward)</span>
<span class="muRecipe">def</span> main [
jump <span class="Constant">1:offset</span> <span class="Comment"># 0 -+</span>
jump <span class="Constant">3:offset</span> <span class="Comment"># | +-+ 1</span>
<span class="Comment"># \/ /\ |</span>
jump <span class="Constant">-2:offset</span> <span class="Comment"># 2 +-->+ |</span>
] <span class="Comment"># \/ 3</span>
<span class="traceContains">+run: jump {1: "offset"}</span>
<span class="traceContains">+run: jump {-2: "offset"}</span>
<span class="traceContains">+run: jump {3: "offset"}</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
JUMP_IF<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">"jump-if"</span><span class="Delimiter">,</span> JUMP_IF<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Checks")</span>
<span class="Normal">case</span> JUMP_IF: <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><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">"'jump-if' requires exactly two ingredients, but got '"</span> << inst<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="Normal">if</span> <span class="Delimiter">(</span>!is_mu_scalar<span class="Delimiter">(</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> <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">"'jump-if' requires a boolean for its first ingredient, but got '"</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">"'</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="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><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">"'jump-if' requires a label or offset for its second ingredient, but got '"</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">"'</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="Comment">// End JUMP_IF Checks</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> JUMP_IF: <span class="Delimiter">{</span>
assert<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>initialized<span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if fell through"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
current_step_index<span class="Delimiter">()</span> += ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>+<span class="Constant">1</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span> << end<span class="Delimiter">();</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of this instruction</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario jump_if)</span>
<span class="muRecipe">def</span> main [
jump-<span class="Normal">if</span> <span class="Constant">999</span><span class="Delimiter">,</span> <span class="Constant">1:offset</span>
<span class="Constant">123</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
]
<span class="traceContains">+run: jump-if {999: "literal"}, {1: "offset"}</span>
<span class="traceContains">+run: jumping to instruction 2</span>
<span class="traceAbsent">-run: {1: "number"} <- copy {1: "literal"}</span>
<span class="traceAbsent">-mem: storing 1 in location 123</span>
<span class="Delimiter">:(scenario jump_if_fallthrough)</span>
<span class="muRecipe">def</span> main [
jump-<span class="Normal">if</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1:offset</span>
<span class="Constant">123</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
]
<span class="traceContains">+run: jump-if {0: "literal"}, {1: "offset"}</span>
<span class="traceContains">+run: jump-if fell through</span>
<span class="traceContains">+run: {123: "number"} <- copy {1: "literal"}</span>
<span class="traceContains">+mem: storing 1 in location 123</span>
<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span>
JUMP_UNLESS<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">"jump-unless"</span><span class="Delimiter">,</span> JUMP_UNLESS<span class="Delimiter">);</span>
<span class="Delimiter">:(before "End Primitive Recipe Checks")</span>
<span class="Normal">case</span> JUMP_UNLESS: <span class="Delimiter">{</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">2</span><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">"'jump-unless' requires exactly two ingredients, but got '"</span> << inst<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="Normal">if</span> <span class="Delimiter">(</span>!is_mu_scalar<span class="Delimiter">(</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> <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">"'jump-unless' requires a boolean for its first ingredient, but got '"</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">"'</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="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><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">"'jump-unless' requires a label or offset for its second ingredient, but got '"</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">"'</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="Comment">// End JUMP_UNLESS Checks</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span>
<span class="Normal">case</span> JUMP_UNLESS: <span class="Delimiter">{</span>
assert<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>initialized<span class="Delimiter">);</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless fell through"</span> << end<span class="Delimiter">();</span>
<span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
current_step_index<span class="Delimiter">()</span> += ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>+<span class="Constant">1</span><span class="Delimiter">;</span>
trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to instruction "</span> << current_step_index<span class="Delimiter">()</span> << end<span class="Delimiter">();</span>
<span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// skip rest of this instruction</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(scenario jump_unless)</span>
<span class="muRecipe">def</span> main [
jump-unless <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1:offset</span>
<span class="Constant">123</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
]
<span class="traceContains">+run: jump-unless {0: "literal"}, {1: "offset"}</span>
<span class="traceContains">+run: jumping to instruction 2</span>
<span class="traceAbsent">-run: {123: "number"} <- copy {1: "literal"}</span>
<span class="traceAbsent">-mem: storing 1 in location 123</span>
<span class="Delimiter">:(scenario jump_unless_fallthrough)</span>
<span class="muRecipe">def</span> main [
jump-unless <span class="Constant">999</span><span class="Delimiter">,</span> <span class="Constant">1:offset</span>
<span class="Constant">123</span>:num<span class="Special"> <- </span>copy <span class="Constant">1</span>
]
<span class="traceContains">+run: jump-unless {999: "literal"}, {1: "offset"}</span>
<span class="traceContains">+run: jump-unless fell through</span>
<span class="traceContains">+run: {123: "number"} <- copy {1: "literal"}</span>
<span class="traceContains">+mem: storing 1 in location 123</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|