diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-18 15:22:49 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-18 15:22:49 -0700 |
commit | 762b099ef6c6ad5b6b61d29e473baa6df8d64ab9 (patch) | |
tree | 8075befbcc8ef2784616c4937793ebed9d21123d /html/032array.cc.html | |
parent | 614ea44bc2708a687ba10b162a6dc70e48dfac59 (diff) | |
download | mu-762b099ef6c6ad5b6b61d29e473baa6df8d64ab9.tar.gz |
1818
Diffstat (limited to 'html/032array.cc.html')
-rw-r--r-- | html/032array.cc.html | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/html/032array.cc.html b/html/032array.cc.html index 101bd958..fddb6a17 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -122,8 +122,11 @@ case INDEX: <span class="Delimiter">{</span> vector<type_ordinal> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> <span class="CommentedCode">//? trace(Primitive_recipe_depth, "run") << "offset: " << offset_val.at(0); //? 1</span> <span class="CommentedCode">//? trace(Primitive_recipe_depth, "run") << "size of elements: " << size_of(element_type); //? 1</span> - assert<span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= <span class="Constant">0</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < Memory[base_address]*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">)</span> + <span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": invalid index "</span> << offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> long long int src = base_address + <span class="Constant">1</span> + offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">);</span> trace<span class="Delimiter">(</span>Primitive_recipe_depth<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> trace<span class="Delimiter">(</span>Primitive_recipe_depth<span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << Type[element_type<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> @@ -139,28 +142,58 @@ vector<type_ordinal> array_element<span class="Delimiter">(</span>const ve <span class="Identifier">return</span> vector<type_ordinal><span class="Delimiter">(</span>++types<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> types<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Delimiter">}</span> -<span class="Delimiter">:(scenario index_address)</span> +<span class="Delimiter">:(scenario index_indirect)</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:number<span class="Special"> <- </span>index-address <span class="Constant">1</span>:array:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>index <span class="Constant">5</span>:address:array:number/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal ] -<span class="traceContains">+mem: storing 2 in location 5</span> +<span class="traceContains">+mem: storing 15 in location 6</span> + +<span class="Delimiter">:(scenario index_out_of_bounds)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + index <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> <span class="Constant">4</span>:literal <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> +] +<span class="traceContains">+warn: main: invalid index 4</span> + +<span class="Delimiter">:(scenario index_out_of_bounds2)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + index <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> -<span class="Constant">1</span>:literal +] +<span class="traceContains">+warn: main: invalid index -1</span> <span class="SalientComment">//:: To write to elements of containers, you need their address.</span> -<span class="Delimiter">:(scenario index_indirect)</span> +<span class="Delimiter">:(scenario index_address)</span> recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># length</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal - <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal - <span class="Constant">6</span>:number<span class="Special"> <- </span>index <span class="Constant">5</span>:address:array:number/deref<span class="Delimiter">,</span> <span class="Constant">1</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>index-address <span class="Constant">1</span>:array:number/<span class="Special">raw</span><span class="Delimiter">,</span> <span class="Constant">0</span>:literal <span class="Comment"># unsafe</span> ] -<span class="traceContains">+mem: storing 15 in location 6</span> +<span class="traceContains">+mem: storing 2 in location 5</span> <span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> INDEX_ADDRESS<span class="Delimiter">,</span> @@ -174,14 +207,47 @@ case INDEX_ADDRESS: <span class="Delimiter">{</span> reagent offset = canonize<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> vector<double> offset_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>offset<span class="Delimiter">));</span> vector<type_ordinal> element_type = array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>types<span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= <span class="Constant">0</span><span class="Delimiter">);</span> - assert<span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < Memory[base_address]*size_of<span class="Delimiter">(</span>element_type<span class="Delimiter">)</span> + <span class="Constant">1</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> < <span class="Constant">0</span> || offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> >= Memory[base_address]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << current_recipe_name<span class="Delimiter">()</span> << <span class="Constant">": invalid index "</span> << offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> + products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> long long int result = base_address + <span class="Constant">1</span> + offset_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>*size_of<span class="Delimiter">(</span>element_type<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="Delimiter">:(scenario index_address_out_of_bounds)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + index-address <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> <span class="Constant">4</span>:literal <span class="Comment"># less than size of array in locations, but larger than its length in elements</span> +] +<span class="traceContains">+warn: main: invalid index 4</span> + +<span class="Delimiter">:(scenario index_address_out_of_bounds2)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span>:literal <span class="Comment"># 3 points</span> + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span>:literal + <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span>:literal + <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span>:literal + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>:literal + index-address <span class="Constant">8</span>:address:array:point/deref<span class="Delimiter">,</span> -<span class="Constant">1</span>:literal +] +<span class="traceContains">+warn: main: invalid index -1</span> + <span class="SalientComment">//:: compute the length of an array</span> <span class="Delimiter">:(scenario array_length)</span> |