about summary refs log tree commit diff stats
path: root/html/035call.cc.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-06 00:19:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-06 00:19:03 -0700
commit672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9 (patch)
tree5fa3d82e40137b15dec2941a3446e838ce43d3e5 /html/035call.cc.html
parent20d1c9057a559ce8db83bbc2787ca91348bcb16f (diff)
downloadmu-672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9.tar.gz
1279 - colorized rendering of the source files
Diffstat (limited to 'html/035call.cc.html')
-rw-r--r--html/035call.cc.html144
1 files changed, 144 insertions, 0 deletions
diff --git a/html/035call.cc.html b/html/035call.cc.html
new file mode 100644
index 00000000..43c4a42b
--- /dev/null
+++ b/html/035call.cc.html
@@ -0,0 +1,144 @@
+<!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>~/Desktop/s/mu/035call.cc.html</title>
+<meta name="Generator" content="Vim/7.4">
+<meta name="plugin-version" content="vim7.4_v1">
+<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: #d0d0d0; background-color: #000000; }
+body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
+* { font-size: 1em; }
+.cSpecial { color: #008000; }
+.SalientComment { color: #00ffff; }
+.Constant { color: #008080; }
+.Comment { color: #8080ff; }
+.Delimiter { color: #c000c0; }
+.Special { color: #ff6060; }
+.Identifier { color: #008080; }
+.traceContains { color: #008000; }
+.PreProc { color: #c000c0; }
+-->
+</style>
+
+<script type='text/javascript'>
+<!--
+
+-->
+</script>
+</head>
+<body>
+<pre id='vimCodeElement'>
+<span class="Comment">//: So far the recipes we define can't run each other. Let's fix that.</span>
+
+<span class="Delimiter">:(scenario calling_recipe)</span>
+recipe main [
+  f
+]
+recipe f [
+  <span class="Constant">3</span>:integer<span class="Special"> &lt;- </span>add <span class="Constant">2</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal
+]
+<span class="traceContains">+mem: storing 4 in location 3</span>
+
+<span class="Delimiter">:(scenario return_on_fallthrough)</span>
+recipe main [
+  f
+  <span class="Constant">1</span>:integer<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>:literal
+  <span class="Constant">2</span>:integer<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>:literal
+  <span class="Constant">3</span>:integer<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>:literal
+]
+recipe f [
+  <span class="Constant">4</span>:integer<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>:literal
+  <span class="Constant">5</span>:integer<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>:literal
+]
+<span class="traceContains">+run: instruction main/0</span>
+<span class="traceContains">+run: instruction f/0</span>
+<span class="traceContains">+run: instruction f/1</span>
+<span class="traceContains">+run: instruction main/1</span>
+<span class="traceContains">+run: instruction main/2</span>
+<span class="traceContains">+run: instruction main/3</span>
+
+<span class="Delimiter">:(before &quot;struct routine {&quot;)</span>
+<span class="Comment">// Everytime a recipe runs another, we interrupt it and start running the new</span>
+<span class="Comment">// recipe. When that finishes, we continue this one where we left off.</span>
+<span class="Comment">// This requires maintaining a 'stack' of interrupted recipes or 'calls'.</span>
+struct call <span class="Delimiter">{</span>
+  recipe_number running_recipe<span class="Delimiter">;</span>
+  index_t running_step_index<span class="Delimiter">;</span>
+  <span class="Comment">// End call Fields</span>
+  call<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> :running_recipe<span class="Delimiter">(</span>r<span class="Delimiter">),</span> running_step_index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span>
+<span class="Delimiter">};</span>
+typedef stack&lt;call&gt; call_stack<span class="Delimiter">;</span>
+
+<span class="Delimiter">:(replace{} &quot;struct routine&quot;)</span>
+struct routine <span class="Delimiter">{</span>
+  call_stack calls<span class="Delimiter">;</span>
+  <span class="Comment">// End routine Fields</span>
+  routine<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">);</span>
+  bool completed<span class="Delimiter">()</span> const<span class="Delimiter">;</span>
+  const vector&lt;instruction&gt;&amp; steps<span class="Delimiter">()</span> const<span class="Delimiter">;</span>
+<span class="Delimiter">};</span>
+<span class="Delimiter">:(code)</span>
+routine::routine<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+  calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span>
+  <span class="Comment">// End routine Constructor</span>
+<span class="Delimiter">}</span>
+
+<span class="SalientComment">//:: now update routine's helpers</span>
+
+<span class="Delimiter">:(replace{} &quot;inline index_t&amp; current_step_index()&quot;)</span>
+inline index_t&amp; current_step_index<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  <span class="Identifier">return</span> Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_step_index<span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+<span class="Delimiter">:(replace{} &quot;inline const string&amp; current_recipe_name()&quot;)</span>
+inline const string&amp; current_recipe_name<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>name<span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+<span class="Delimiter">:(replace{} &quot;inline const instruction&amp; current_instruction()&quot;)</span>
+inline const instruction&amp; current_instruction<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  <span class="Identifier">return</span> Recipe[Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps[Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_step_index]<span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+
+<span class="Delimiter">:(replace{} &quot;default:&quot; following &quot;End Primitive Recipe Implementations&quot;)</span>
+default: <span class="Delimiter">{</span>
+  <span class="Comment">// not a primitive; try to look up the book of recipes</span>
+  if <span class="Delimiter">(</span>Recipe<span class="Delimiter">.</span>find<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">)</span> == Recipe<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; <span class="Constant">&quot;undefined operation &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>operation &lt;&lt; <span class="Constant">&quot;: &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>name &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
+    <span class="Identifier">break</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>call<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">));</span>
+  <span class="Identifier">continue</span><span class="Delimiter">;</span>  <span class="Comment">// not done with caller; don't increment current_step_index()</span>
+<span class="Delimiter">}</span>
+
+<span class="SalientComment">//:: finally, we need to fix the termination conditions for the run loop</span>
+
+<span class="Delimiter">:(replace{} &quot;inline bool routine::completed() const&quot;)</span>
+inline bool routine::completed<span class="Delimiter">()</span> const <span class="Delimiter">{</span>
+  <span class="Identifier">return</span> calls<span class="Delimiter">.</span>empty<span class="Delimiter">();</span>
+<span class="Delimiter">}</span>
+
+inline const vector&lt;instruction&gt;&amp; routine::steps<span class="Delimiter">()</span> const <span class="Delimiter">{</span>
+  <span class="Identifier">return</span> Recipe[calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>running_recipe]<span class="Delimiter">.</span>steps<span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+
+<span class="Delimiter">:(before &quot;Running One Instruction&quot;)</span>
+<span class="Comment">// when we reach the end of one call, we may reach the end of the one below</span>
+<span class="Comment">// it, and the one below that, and so on</span>
+while <span class="Delimiter">(</span>current_step_index<span class="Delimiter">()</span> &gt;= Current_routine<span class="Delimiter">-&gt;</span>steps<span class="Delimiter">().</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span>
+  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>pop<span class="Delimiter">();</span>
+  if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
+  <span class="Comment">// todo: no results returned warning</span>
+  ++current_step_index<span class="Delimiter">();</span>
+<span class="Delimiter">}</span>
+
+<span class="Delimiter">:(before &quot;End Includes&quot;)</span>
+<span class="PreProc">#include </span><span class="Constant">&lt;stack&gt;</span>
+using std::stack<span class="Delimiter">;</span>
+</pre>
+</body>
+</html>
+<!-- vim: set foldmethod=manual : -->