diff options
Diffstat (limited to 'html/034exclusive_container.cc.html')
-rw-r--r-- | html/034exclusive_container.cc.html | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/html/034exclusive_container.cc.html b/html/034exclusive_container.cc.html index f8387563..32576bd7 100644 --- a/html/034exclusive_container.cc.html +++ b/html/034exclusive_container.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 034exclusive_container.cc</title> +<title>~/Desktop/s/mu/034exclusive_container.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,12 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .Identifier { color: #008080; } -.SalientComment { color: #00ffff; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } --> </style> @@ -39,15 +39,15 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Comment">//: currently stored in them.</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> +<span class="Comment">//: We'll use this container as a running example, with two number elements.</span> <span class="Delimiter">{</span> -type_number tmp = Type_number[<span class="Constant">"integer-or-point"</span>] = Next_type_number++<span class="Delimiter">;</span> +type_number tmp = Type_number[<span class="Constant">"number-or-point"</span>] = Next_type_number++<span class="Delimiter">;</span> Type[tmp]<span class="Delimiter">.</span>size = <span class="Constant">2</span><span class="Delimiter">;</span> Type[tmp]<span class="Delimiter">.</span>kind = exclusive_container<span class="Delimiter">;</span> -Type[tmp]<span class="Delimiter">.</span>name = <span class="Constant">"integer-or-point"</span><span class="Delimiter">;</span> +Type[tmp]<span class="Delimiter">.</span>name = <span class="Constant">"number-or-point"</span><span class="Delimiter">;</span> <span class="CommentedCode">//? cout << tmp << ": " << Type[tmp].elements.size() << '\n'; //? 1</span> vector<type_number> t1<span class="Delimiter">;</span> -t1<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>integer<span class="Delimiter">);</span> +t1<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>number<span class="Delimiter">);</span> Type[tmp]<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>t1<span class="Delimiter">);</span> <span class="CommentedCode">//? cout << Type[tmp].elements.size() << '\n'; //? 1</span> vector<type_number> t2<span class="Delimiter">;</span> @@ -62,10 +62,10 @@ Type[tmp]<span class="Delimiter">.</span>element_names<span class="Delimiter">.< <span class="Delimiter">:(scenario copy_exclusive_container)</span> <span class="Comment"># Copying exclusive containers copies all their contents and an extra location for the tag.</span> recipe main [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal <span class="Comment"># 'point' variant</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal - <span class="Constant">4</span>:integer-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer-or-point + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal <span class="Comment"># 'point' variant</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">4</span>:number-or-point<span class="Special"> <- </span>copy <span class="Constant">1</span>:number-or-point ] <span class="traceContains">+mem: storing 1 in location 4</span> <span class="traceContains">+mem: storing 34 in location 5</span> @@ -75,13 +75,13 @@ recipe main [ if <span class="Delimiter">(</span>t<span class="Delimiter">.</span>kind == exclusive_container<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// size of an exclusive container is the size of its largest variant</span> <span class="Comment">// (So like containers, it can't contain arrays.)</span> -<span class="CommentedCode">//? cout << "--- " << types[0] << ' ' << t.size << '\n'; //? 1</span> +<span class="CommentedCode">//? cout << "--- " << types.at(0) << ' ' << t.size << '\n'; //? 1</span> <span class="CommentedCode">//? cout << "point: " << Type_number["point"] << " " << Type[Type_number["point"]].name << " " << Type[Type_number["point"]].size << '\n'; //? 1</span> <span class="CommentedCode">//? cout << t.name << ' ' << t.size << ' ' << t.elements.size() << '\n'; //? 1</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>size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - size_t tmp = size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements[i]<span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << i << ": " << t.elements[i][0] << ' ' << tmp << ' ' << result << '\n'; //? 1</span> + size_t tmp = size_of<span class="Delimiter">(</span>t<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span class="CommentedCode">//? cout << i << ": " << t.elements.at(i).at(0) << ' ' << tmp << ' ' << result << '\n'; //? 1</span> if <span class="Delimiter">(</span>tmp > result<span class="Delimiter">)</span> result = tmp<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// ...+1 for its tag.</span> @@ -100,19 +100,19 @@ Type_number[<span class="Constant">"variant"</span>] = <span class="Co <span class="Delimiter">:(scenario maybe_convert)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</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">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> <span class="Constant">1</span>:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> <span class="Constant">1</span>:variant ] <span class="traceContains">+mem: storing 13 in location 20</span> <span class="Delimiter">:(scenario maybe_convert_fail)</span> recipe main [ - <span class="Constant">12</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</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">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:integer-or-point<span class="Delimiter">,</span> <span class="Constant">0</span>:variant + <span class="Constant">12</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">13</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal + <span class="Constant">14</span>:number<span class="Special"> <- </span>copy <span class="Constant">36</span>:literal + <span class="Constant">20</span>:address:point<span class="Special"> <- </span>maybe-convert <span class="Constant">12</span>:number-or-point<span class="Delimiter">,</span> <span class="Constant">0</span>:variant ] <span class="traceContains">+mem: storing 0 in location 20</span> @@ -122,24 +122,41 @@ MAYBE_CONVERT<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"maybe-convert"</span>] = MAYBE_CONVERT<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case MAYBE_CONVERT: <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 = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent base = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><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> + type_number base_type = base<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> assert<span class="Delimiter">(</span>Type[base_type]<span class="Delimiter">.</span>kind == exclusive_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 tag = current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - vector<long long int> result<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)));</span> + index_t tag = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>value<span class="Delimiter">;</span> + long long int result<span class="Delimiter">;</span> if <span class="Delimiter">(</span>tag == static_cast<index_t><span class="Delimiter">(</span>Memory[base_address]<span class="Delimiter">))</span> <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>base_address+<span class="Constant">1</span><span class="Delimiter">);</span> + result = base_address+<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + result = <span class="Constant">0</span><span class="Delimiter">;</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> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> + +<span class="SalientComment">//:: Allow exclusive containers to be defined in mu code.</span> + +<span class="Delimiter">:(scenario exclusive_container)</span> +exclusive-container foo [ + x:number + y:number +] +<span class="traceContains">+parse: reading exclusive-container foo</span> +<span class="traceContains">+parse: element name: x</span> +<span class="traceContains">+parse: type: 1</span> +<span class="traceContains">+parse: element name: y</span> +<span class="traceContains">+parse: type: 1</span> + +<span class="Delimiter">:(before "End Command Handlers")</span> +else if <span class="Delimiter">(</span>command == <span class="Constant">"exclusive-container"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + insert_container<span class="Delimiter">(</span>command<span class="Delimiter">,</span> exclusive_container<span class="Delimiter">,</span> in<span class="Delimiter">);</span> +<span class="Delimiter">}</span> </pre> </body> </html> |