diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-10 10:43:19 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-10 10:43:19 -0700 |
commit | 44c1aeef226542d692f0002b5cca5a3c30935d18 (patch) | |
tree | 46452902ff779d93e4adcb57cda29d923766a5be /html/032array.cc.html | |
parent | c7db6a160a9a43d0905d5dea44e742b47acfa42f (diff) | |
download | mu-44c1aeef226542d692f0002b5cca5a3c30935d18.tar.gz |
3315
Diffstat (limited to 'html/032array.cc.html')
-rw-r--r-- | html/032array.cc.html | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/html/032array.cc.html b/html/032array.cc.html index 921247a6..d78f29ab 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -69,11 +69,14 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Comment">// 'create-array' will need to check properties rather than types</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> + type_tree* array_length_from_type = product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!array_length_from_type<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"create array of what size? '"</span> << inst<span class="Delimiter">.</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + array_length_from_type = array_length_from_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>array_length_from_type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"'create-array' product should specify size of array after its element type, but got '"</span> << product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -84,7 +87,10 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> product = current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// Update CREATE_ARRAY product in Run</span> <span class="Normal">int</span> base_address = product<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - <span class="Normal">int</span> array_length = to_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">);</span> + type_tree* array_length_from_type = product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> + array_length_from_type = array_length_from_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> + <span class="Normal">int</span> array_length = to_integer<span class="Delimiter">(</span>array_length_from_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span class="Comment">// initialize array length, so that size_of will work</span> trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << array_length << <span class="Constant">" in location "</span> << base_address << end<span class="Delimiter">();</span> put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base_address<span class="Delimiter">,</span> array_length<span class="Delimiter">);</span> <span class="Comment">// in array elements</span> @@ -128,7 +134,7 @@ def main [ <span class="traceContains">+app: foo: 3 14 15 16</span> <span class="Delimiter">:(before "End size_of(reagent r) Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"'"</span> << r<span class="Delimiter">.</span>original_string << <span class="Constant">"' is an array of what?</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> @@ -142,7 +148,7 @@ def main [ <span class="Comment">//: disable the size mismatch check for arrays since the destination array</span> <span class="Comment">//: need not be initialized</span> <span class="Delimiter">:(before "End size_mismatch(x) Cases")</span> -<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"array"</span><span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">//: arrays are disallowed inside containers unless their length is fixed in</span> <span class="Comment">//: advance</span> @@ -182,12 +188,16 @@ def main [ <span class="Delimiter">:(before "End Load Container Element Definition")</span> <span class="Delimiter">{</span> <span class="Normal">const</span> type_tree* type = info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>type<span class="Delimiter">;</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type && type<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type && type<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"container '"</span> << name << <span class="Constant">"' doesn't specify type of array elements for '"</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type && !type<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"array"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> raise << <span class="Constant">"container '"</span> << name << <span class="Constant">"' doesn't specify type of array elements for '"</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array has no length</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// array has no length</span> raise << <span class="Constant">"container '"</span> << name << <span class="Constant">"' cannot determine size of element '"</span> << info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>back<span class="Delimiter">().</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -217,6 +227,16 @@ def main [ ] <span class="traceContains">+mem: storing 14 in location 5</span> +<span class="Delimiter">:(scenario index_compound_element)</span> +def main [ + <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)}</span><span class="Special"> <- </span>create-array + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> + <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> + <span class="Constant">5</span>:address:number<span class="Special"> <- </span>index <span class="Delimiter">{</span><span class="Constant">1</span>: <span class="Delimiter">(</span>array <span class="Delimiter">(</span>address number<span class="Delimiter">)</span> <span class="Constant">3</span><span class="Delimiter">)},</span> <span class="Constant">0</span> +] +<span class="traceContains">+mem: storing 14 in location 5</span> + <span class="Delimiter">:(scenario index_direct_offset)</span> def main [ <span class="Constant">1</span>:array:number:<span class="Constant">3</span><span class="Special"> <- </span>create-array @@ -281,7 +301,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span type_tree* element_type = copy_array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">);</span> <span class="Normal">int</span> src = base_address + <span class="Constant">1</span> + index_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><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"address to copy is "</span> << src << end<span class="Delimiter">();</span> - trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> element_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name << end<span class="Delimiter">();</span> + trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"its type is "</span> << to_string<span class="Delimiter">(</span>element_type<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> reagent element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>src<span class="Delimiter">);</span> element<span class="Delimiter">.</span>type = element_type<span class="Delimiter">;</span> @@ -292,19 +312,15 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span <span class="Delimiter">:(code)</span> type_tree* copy_array_element<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">);</span> - <span class="Delimiter">}</span> assert<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> - <span class="Comment">// array:<type>:<size>? return just <type></span> - <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> - <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">,</span> type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span class="Comment">// snip type->right->right</span> + <span class="Comment">// hack: don't require parens for either array:number:3 array:address:number</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> + <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">);</span> <span class="Identifier">return</span> <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*type<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span class="Delimiter">}</span> <span class="Normal">int</span> array_length<span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right <span class="Comment">// exactly 3 types</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom <span class="Comment">// exactly 3 types</span> && is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> <span class="Comment">// get size from type</span> <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>name<span class="Delimiter">);</span> |