diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-01-26 23:47:23 -0800 |
commit | d009e158803956c76adbf8f58a62884c3e7affb3 (patch) | |
tree | b88198e28d15cd1fc064f5300365a190decc4c50 /html/044space_surround.cc.html | |
parent | 2da43c9462c7b7c1bb78d2f2826b3b97b4874973 (diff) | |
download | mu-d009e158803956c76adbf8f58a62884c3e7affb3.tar.gz |
2605
Diffstat (limited to 'html/044space_surround.cc.html')
-rw-r--r-- | html/044space_surround.cc.html | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/html/044space_surround.cc.html b/html/044space_surround.cc.html new file mode 100644 index 00000000..47e01b94 --- /dev/null +++ b/html/044space_surround.cc.html @@ -0,0 +1,103 @@ +<!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 - 044space_surround.cc</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: #eeeeee; background-color: #080808; } +body { font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 1.05em; } +.traceContains { color: #008000; } +.cSpecial { color: #008000; } +.CommentedCode { color: #6c6c6c; } +.Comment { color: #9090ff; } +.Delimiter { color: #a04060; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } +.Constant { color: #00a0a0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: So far you can have global variables by not setting default-space, and</span> +<span class="Comment">//: local variables by setting default-space. You can isolate variables</span> +<span class="Comment">//: between those extremes by creating 'surrounding' spaces.</span> +<span class="Comment">//:</span> +<span class="Comment">//: (Surrounding spaces are like lexical scopes in other languages.)</span> + +<span class="Delimiter">:(scenario surrounding_space)</span> +<span class="Comment"># location 1 in space 1 refers to the space surrounding the default space, here 20.</span> +recipe main [ + <span class="Comment"># pretend shared:array:location; in practice we'll use new</span> + <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">11</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Comment"># pretend shared:array:location; in practice we'll use new</span> + <span class="Constant">20</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">21</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Comment"># actual start of this recipe</span> + default-space:address:shared:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe + <span class="Constant">0</span>:address:shared:array:location/names:dummy<span class="Special"> <- </span>copy <span class="Constant">20</span>/unsafe <span class="Comment"># later layers will explain the /names: property</span> + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">32</span> + <span class="Constant">1</span>:number/space:<span class="Constant">1</span><span class="Special"> <- </span>copy <span class="Constant">33</span> +] +recipe dummy [ <span class="Comment"># just for the /names: property above</span> +] +<span class="Comment"># chain space: 10 + /*skip refcount*/1 + /*skip length*/1</span> +<span class="traceContains">+mem: storing 20 in location 12</span> +<span class="Comment"># store to default space: 10 + /*skip refcount*/1 + /*skip length*/1 + /*index*/1</span> +<span class="traceContains">+mem: storing 32 in location 13</span> +<span class="Comment"># store to chained space: /*contents of location 12*/20 + /*skip refcount*/1 + /*skip length*/1 + /*index*/1</span> +<span class="traceContains">+mem: storing 33 in location 23</span> + +<span class="Comment">//: If you think of a space as a collection of variables with a common</span> +<span class="Comment">//: lifetime, surrounding allows managing shorter lifetimes inside a longer</span> +<span class="Comment">//: one.</span> + +<span class="Delimiter">:(replace{} "long long int space_base(const reagent& x)")</span> +long long int space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + long long int base = current_call<span class="Delimiter">().</span>default_space ? <span class="Delimiter">(</span>current_call<span class="Delimiter">().</span>default_space+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">)</span> : <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index<span class="Delimiter">(</span>x<span class="Delimiter">),</span> base<span class="Delimiter">);</span> +<span class="Delimiter">}</span> + +long long int space_base<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">,</span> long long int space_index<span class="Delimiter">,</span> long long int base<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace(9999, "space") << "space-base: " << space_index << " " << base << end();</span> + if <span class="Delimiter">(</span>space_index == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</span> base<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + long long int result = space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index-<span class="Constant">1</span><span class="Delimiter">,</span> get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base+<span class="Comment">/*</span><span class="Comment">skip length</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">))</span>+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? trace(9999, "space") << "space-base: " << space_index << " " << base << " => " << result << end();</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +long long int space_index<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second || x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + raise_error << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"/space metadata should take exactly one value in "</span> << x<span class="Delimiter">.</span>original_string << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>value<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(scenario permit_space_as_variable_name)</span> +recipe main [ + space:number<span class="Special"> <- </span>copy <span class="Constant">0</span> +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |