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/030container.cc.html | |
parent | 20d1c9057a559ce8db83bbc2787ca91348bcb16f (diff) | |
download | mu-672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9.tar.gz |
1279 - colorized rendering of the source files
Diffstat (limited to 'html/030container.cc.html')
-rw-r--r-- | html/030container.cc.html | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/html/030container.cc.html b/html/030container.cc.html new file mode 100644 index 00000000..8efeb1bb --- /dev/null +++ b/html/030container.cc.html @@ -0,0 +1,206 @@ +<!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/030container.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; } +.SalientComment { color: #00ffff; } +.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">//: Containers contain a fixed number of elements of different types.</span> + +<span class="Delimiter">:(before "End Mu Types Initialization")</span> +<span class="Comment">//: We'll use this container as a running example, with two integer elements.</span> +type_number point = Type_number[<span class="Constant">"point"</span>] = Next_type_number++<span class="Delimiter">;</span> +Type[point]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> +Type[point]<span class="Delimiter">.</span>kind = container<span class="Delimiter">;</span> +Type[point]<span class="Delimiter">.</span>name = <span class="Constant">"point"</span><span class="Delimiter">;</span> +vector<type_number> i<span class="Delimiter">;</span> +i<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> +Type[point]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +Type[point]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i<span class="Delimiter">);</span> + +<span class="Delimiter">:(scenario copy_multiple_locations)</span> +<span class="Comment"># Containers can be copied around with a single instruction just like integers,</span> +<span class="Comment"># no matter how large they are.</span> +recipe main [ + <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">3</span>:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:point +] +<span class="traceContains">+run: ingredient 0 is 1</span> +<span class="traceContains">+mem: location 1 is 34</span> +<span class="traceContains">+mem: location 2 is 35</span> +<span class="traceContains">+mem: storing 34 in location 3</span> +<span class="traceContains">+mem: storing 35 in location 4</span> + +<span class="Delimiter">:(before "End Mu Types Initialization")</span> +<span class="Comment">// A more complex container, containing another container as one of its</span> +<span class="Comment">// elements.</span> +type_number point_integer = Type_number[<span class="Constant">"point-integer"</span>] = Next_type_number++<span class="Delimiter">;</span> +Type[point_integer]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> +Type[point_integer]<span class="Delimiter">.</span>kind = container<span class="Delimiter">;</span> +Type[point_integer]<span class="Delimiter">.</span>name = <span class="Constant">"point-integer"</span><span class="Delimiter">;</span> +vector<type_number> p2<span class="Delimiter">;</span> +p2<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>point<span class="Delimiter">);</span> +Type[point_integer]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>p2<span class="Delimiter">);</span> +vector<type_number> i2<span class="Delimiter">;</span> +i2<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> +Type[point_integer]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>i2<span class="Delimiter">);</span> + +<span class="Delimiter">:(scenario copy_handles_nested_container_elements)</span> +recipe main [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">15</span>:point-integer<span class="Special"> <- </span>copy <span class="Constant">12</span>:point-integer +] +<span class="traceContains">+mem: storing 36 in location 17</span> + +<span class="Delimiter">:(before "End size_of(types) Cases")</span> +type_info t = Type[types[<span class="Constant">0</span>]]<span class="Delimiter">;</span> +if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == container<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// size of a container is the sum of the sizes of its elements</span> + size_t result = <span class="Constant">0</span><span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + result += size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="SalientComment">//:: To access elements of a container, use 'get'</span> +<span class="Delimiter">:(scenario get)</span> +recipe main [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">15</span>:integer<span class="Special"> <- </span>get <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset +] +<span class="traceContains">+run: instruction main/2</span> +<span class="traceContains">+run: ingredient 0 is 12</span> +<span class="traceContains">+run: ingredient 1 is 1</span> +<span class="traceContains">+run: address to copy is 13</span> +<span class="traceContains">+run: its type is 1</span> +<span class="traceContains">+mem: location 13 is 35</span> +<span class="traceContains">+run: product 0 is 35</span> +<span class="traceContains">+mem: storing 35 in location 15</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +GET<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"get"</span>] = GET<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case GET: <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + reagent base = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">;</span> + index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number base_type = base<span class="Delimiter">.</span>types[<span class="Constant">0</span>]<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> + index_t offset = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + index_t src = base_address<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + src += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements[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">"address to copy is "</span> << src<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>size<span class="Delimiter">()</span> > offset<span class="Delimiter">);</span> + type_number src_type = Type[base_type]<span class="Delimiter">.</span>elements[offset][<span class="Constant">0</span>]<span class="Delimiter">;</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << src_type<span class="Delimiter">;</span> + reagent tmp<span class="Delimiter">;</span> + tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> + tmp<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>src_type<span class="Delimiter">);</span> + vector<long long int> result<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>tmp<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> << result[<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> result<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Comment">//: 'get' requires a literal in ingredient 1. We'll use a synonym called</span> +<span class="Comment">//: 'offset'.</span> +<span class="Delimiter">:(before "End Mu Types Initialization")</span> +Type_number[<span class="Constant">"offset"</span>] = <span class="Constant">0</span><span class="Delimiter">;</span> + +<span class="Delimiter">:(scenario get_handles_nested_container_elements)</span> +recipe main [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:integer<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">15</span>:integer<span class="Special"> <- </span>get <span class="Constant">12</span>:point-integer<span class="Delimiter">,</span> <span class="Constant">1</span>:offset +] +<span class="traceContains">+run: instruction main/2</span> +<span class="traceContains">+run: ingredient 0 is 12</span> +<span class="traceContains">+run: ingredient 1 is 1</span> +<span class="traceContains">+run: address to copy is 14</span> +<span class="traceContains">+run: its type is 1</span> +<span class="traceContains">+mem: location 14 is 36</span> +<span class="traceContains">+run: product 0 is 36</span> +<span class="traceContains">+mem: storing 36 in location 15</span> + +<span class="SalientComment">//:: To write to elements of containers, you need their address.</span> + +<span class="Delimiter">:(scenario get_address)</span> +recipe main [ + <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">13</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">15</span>:address:integer<span class="Special"> <- </span>get-address <span class="Constant">12</span>:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset +] +<span class="traceContains">+run: instruction main/2</span> +<span class="traceContains">+run: ingredient 0 is 12</span> +<span class="traceContains">+run: ingredient 1 is 1</span> +<span class="traceContains">+run: address to copy is 13</span> +<span class="traceContains">+mem: storing 13 in location 15</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +GET_ADDRESS<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"get-address"</span>] = GET_ADDRESS<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case GET_ADDRESS: <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 0 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + reagent base = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">;</span> + index_t base_address = base<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + type_number base_type = base<span class="Delimiter">.</span>types[<span class="Constant">0</span>]<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == container<span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ingredient 1 is "</span> << current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">));</span> + index_t offset = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + index_t src = base_address<span class="Delimiter">;</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < offset<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + src += size_of<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>elements[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">"address to copy is "</span> << src<span class="Delimiter">;</span> + vector<long long int> result<span class="Delimiter">;</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>src<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> << result[<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> result<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |