diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-06 00:19:03 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-06 00:19:03 -0700 |
commit | 672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9 (patch) | |
tree | 5fa3d82e40137b15dec2941a3446e838ce43d3e5 /html/036call_ingredient.cc.html | |
parent | 20d1c9057a559ce8db83bbc2787ca91348bcb16f (diff) | |
download | mu-672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9.tar.gz |
1279 - colorized rendering of the source files
Diffstat (limited to 'html/036call_ingredient.cc.html')
-rw-r--r-- | html/036call_ingredient.cc.html | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/html/036call_ingredient.cc.html b/html/036call_ingredient.cc.html new file mode 100644 index 00000000..3fc4df85 --- /dev/null +++ b/html/036call_ingredient.cc.html @@ -0,0 +1,165 @@ +<!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/036call_ingredient.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; } +.Constant { color: #008080; } +.Comment { color: #8080ff; } +.Delimiter { color: #c000c0; } +.Special { color: #ff6060; } +.Identifier { color: #008080; } +.traceContains { color: #008000; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: Calls can take ingredients just like primitives. To access a recipe's</span> +<span class="Comment">//: ingredients, use 'next-ingredient'.</span> + +<span class="Delimiter">:(scenario next_ingredient)</span> +recipe main [ + f <span class="Constant">2</span>:literal +] +recipe f [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient + <span class="Constant">13</span>:integer<span class="Special"> <- </span>add <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">12</span>:integer +] +<span class="traceContains">+run: instruction f/1</span> +<span class="traceContains">+mem: location 12 is 2</span> +<span class="traceContains">+mem: storing 3 in location 13</span> + +<span class="Delimiter">:(scenario next_ingredient_missing)</span> +recipe main [ + f +] +recipe f [ + _<span class="Delimiter">,</span> <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient +] +<span class="traceContains">+mem: storing 0 in location 12</span> + +<span class="Delimiter">:(before "End call Fields")</span> +vector<vector<long long int> > ingredient_atoms<span class="Delimiter">;</span> +index_t next_ingredient_to_process<span class="Delimiter">;</span> +<span class="Delimiter">:(replace{} "call(recipe_number r)")</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> next_ingredient_to_process<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> + +<span class="Delimiter">:(replace "Current_routine->calls.push(call(current_instruction().operation))" following "End Primitive Recipe Implementations")</span> +call callee<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">);</span> +for <span class="Delimiter">(</span>size_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + callee<span class="Delimiter">.</span>ingredient_atoms<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[i]<span class="Delimiter">));</span> +<span class="Delimiter">}</span> +Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>push<span class="Delimiter">(</span>callee<span class="Delimiter">);</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +NEXT_INGREDIENT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"next-ingredient"</span>] = NEXT_INGREDIENT<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case NEXT_INGREDIENT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process < Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> + << Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process][<span class="Constant">0</span>]<span class="Delimiter">;</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process]<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<long long int> ingredient_exists<span class="Delimiter">;</span> + ingredient_exists<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> ingredient_exists<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<long long int> no_ingredient<span class="Delimiter">;</span> + no_ingredient<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> no_ingredient<span class="Delimiter">);</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">:(scenario rewind_ingredients)</span> +recipe main [ + f <span class="Constant">2</span>:literal +] +recipe f [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>next-ingredient <span class="Comment"># consume ingredient</span> + _<span class="Delimiter">,</span> <span class="Constant">1</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># will not find any ingredients</span> + rewind-ingredients + <span class="Constant">13</span>:integer<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># will find ingredient again</span> +] +<span class="traceContains">+mem: storing 2 in location 12</span> +<span class="traceContains">+mem: storing 0 in location 1</span> +<span class="traceContains">+mem: storing 2 in location 13</span> +<span class="traceContains">+mem: storing 1 in location 2</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +REWIND_INGREDIENTS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"rewind-ingredients"</span>] = REWIND_INGREDIENTS<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case REWIND_INGREDIENTS: <span class="Delimiter">{</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario ingredient)</span> +recipe main [ + f <span class="Constant">1</span>:literal<span class="Delimiter">,</span> <span class="Constant">2</span>:literal +] +recipe f [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>ingredient <span class="Constant">1</span>:literal <span class="Comment"># consume second ingredient first</span> + <span class="Constant">13</span>:integer<span class="Delimiter">,</span> <span class="Constant">1</span>:boolean<span class="Special"> <- </span>next-ingredient <span class="Comment"># next-ingredient tries to scan past that</span> +] +<span class="traceContains">+mem: storing 2 in location 12</span> +<span class="traceContains">+mem: storing 0 in location 1</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +INGREDIENT<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"ingredient"</span>] = INGREDIENT<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case INGREDIENT: <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>static_cast<index_t><span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">)</span> < Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms<span class="Delimiter">.</span>size<span class="Delimiter">())</span> <span class="Delimiter">{</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"product 0 is "</span> + << Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process][<span class="Constant">0</span>]<span class="Delimiter">;</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>ingredient_atoms[Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process]<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<long long int> ingredient_exists<span class="Delimiter">;</span> + ingredient_exists<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> ingredient_exists<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + ++Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>top<span class="Delimiter">().</span>next_ingredient_to_process<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + vector<long long int> no_ingredient<span class="Delimiter">;</span> + no_ingredient<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> no_ingredient<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |