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/037call_reply.cc.html | |
parent | 20d1c9057a559ce8db83bbc2787ca91348bcb16f (diff) | |
download | mu-672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9.tar.gz |
1279 - colorized rendering of the source files
Diffstat (limited to 'html/037call_reply.cc.html')
-rw-r--r-- | html/037call_reply.cc.html | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/html/037call_reply.cc.html b/html/037call_reply.cc.html new file mode 100644 index 00000000..0359d9fe --- /dev/null +++ b/html/037call_reply.cc.html @@ -0,0 +1,132 @@ +<!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/037call_reply.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; } +.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 also generate products, using 'reply'.</span> + +<span class="Delimiter">:(scenario reply)</span> +recipe main [ + <span class="Constant">3</span>:integer<span class="Delimiter">,</span> <span class="Constant">4</span>:integer<span class="Special"> <- </span>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 + reply <span class="Constant">12</span>:integer<span class="Delimiter">,</span> <span class="Constant">13</span>:integer +] +<span class="traceContains">+run: instruction main/0</span> +<span class="traceContains">+run: result 0 is 2</span> +<span class="traceContains">+mem: storing 2 in location 3</span> +<span class="traceContains">+run: result 1 is 3</span> +<span class="traceContains">+mem: storing 3 in location 4</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +REPLY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"reply"</span>] = REPLY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case REPLY: <span class="Delimiter">{</span> + vector<vector<long long int> > callee_results<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_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_results<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> + const instruction& reply_inst = current_instruction<span class="Delimiter">();</span> <span class="Comment">// save pointer into recipe before pop</span> + Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + assert<span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>calls<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + const instruction& caller_instruction = current_instruction<span class="Delimiter">();</span> + assert<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">()</span> <= callee_results<span class="Delimiter">.</span>size<span class="Delimiter">());</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < caller_instruction<span class="Delimiter">.</span>products<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<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">"result "</span> << i << <span class="Constant">" is "</span> << to_string<span class="Delimiter">(</span>callee_results[i]<span class="Delimiter">);</span> + <span class="Comment">// check that any reply ingredients with /same-as-ingredient connect up</span> + <span class="Comment">// the corresponding ingredient and product in the caller.</span> + if <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients[i]<span class="Delimiter">,</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> + vector<string> tmp = property<span class="Delimiter">(</span>reply_inst<span class="Delimiter">.</span>ingredients[i]<span class="Delimiter">,</span> <span class="Constant">"same-as-ingredient"</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> + long long int ingredient_index = to_int<span class="Delimiter">(</span>tmp[<span class="Constant">0</span>]<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">.</span>value != caller_instruction<span class="Delimiter">.</span>ingredients[ingredient_index]<span class="Delimiter">.</span>value<span class="Delimiter">)</span> + raise << <span class="Constant">"'same-as-ingredient' result "</span> << caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">.</span>value << <span class="Constant">" must be location "</span> << caller_instruction<span class="Delimiter">.</span>ingredients[ingredient_index]<span class="Delimiter">.</span>value << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + write_memory<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>products[i]<span class="Delimiter">,</span> callee_results[i]<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// instruction loop will increment caller's step_index</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: Products can include containers and exclusive containers, addresses and arrays.</span> +<span class="Delimiter">:(scenario reply_container)</span> +recipe main [ + <span class="Constant">3</span>:point<span class="Special"> <- </span>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>copy <span class="Constant">35</span>:literal + reply <span class="Constant">12</span>:point +] +<span class="traceContains">+run: instruction main/0</span> +<span class="traceContains">+run: result 0 is [2, 35]</span> +<span class="traceContains">+mem: storing 2 in location 3</span> +<span class="traceContains">+mem: storing 35 in location 4</span> + +<span class="Comment">//: In mu we'd like to assume that any instruction doesn't modify its</span> +<span class="Comment">//: ingredients unless they're also products. The /same-as-ingredient inside</span> +<span class="Comment">//: the recipe's 'reply' will help catch accidental misuse of such</span> +<span class="Comment">//: 'ingredient-results' (sometimes called in-out parameters in other languages).</span> +<span class="Delimiter">:(scenario reply_same_as_ingredient)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Constant">1</span>:address:integer<span class="Special"> <- </span>new integer:type + <span class="Constant">2</span>:address:integer<span class="Special"> <- </span>test1 <span class="Constant">1</span>:address:integer <span class="Comment"># call with different ingredient and product</span> +] +recipe test1 [ + <span class="Constant">10</span>:address:integer<span class="Special"> <- </span>next-ingredient + reply <span class="Constant">10</span>:address:integer/same-as-ingredient:<span class="Constant">0</span> +] +<span class="traceContains">+warn: 'same-as-ingredient' result 2 must be location 1</span> + +<span class="Delimiter">:(code)</span> +string to_string<span class="Delimiter">(</span>const vector<long long int>& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">"[]"</span><span class="Delimiter">;</span> + ostringstream out<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>in<span class="Delimiter">.</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + out << in[<span class="Constant">0</span>]<span class="Delimiter">;</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + out << <span class="Constant">"["</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < in<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">", "</span><span class="Delimiter">;</span> + out << in[i]<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + out << <span class="Constant">"]"</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |