diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-29 14:18:52 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-29 14:18:52 -0800 |
commit | db1f56c8449d2ea3d158753fe37bac5a750a2566 (patch) | |
tree | 508a24c522c040498dbe7d60036035f3c4ae440a /html/032array.cc.html | |
parent | 3670fb87f6d38c9ba4fcbb1eaa6439b4007a194e (diff) | |
download | mu-db1f56c8449d2ea3d158753fe37bac5a750a2566.tar.gz |
2611
Diffstat (limited to 'html/032array.cc.html')
-rw-r--r-- | html/032array.cc.html | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/html/032array.cc.html b/html/032array.cc.html index 8c0ce105..d2689076 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -119,7 +119,7 @@ recipe main [ <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:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe <span class="Constant">6</span>:array:number<span class="Special"> <- </span>copy *<span class="Constant">5</span>:address:array:number ] <span class="traceContains">+mem: storing 3 in location 6</span> @@ -194,7 +194,7 @@ case INDEX: <span class="Delimiter">{</span> canonize_type<span class="Delimiter">(</span>product<span class="Delimiter">);</span> reagent element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">));</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise_error << 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << debug_string<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -238,7 +238,7 @@ recipe main [ <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:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">5</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe <span class="Constant">6</span>:number<span class="Special"> <- </span>index *<span class="Constant">5</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 15 in location 6</span> @@ -268,7 +268,7 @@ recipe main [ <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe index *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> -<span class="Constant">1</span> ] <span class="traceContains">+error: main: invalid index -1</span> @@ -283,11 +283,23 @@ recipe main [ <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe <span class="Constant">9</span>:number<span class="Special"> <- </span>index *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> <span class="Constant">0</span> ] <span class="traceContains">+error: main: 'index' on *8:address:array:point can't be saved in 9:number; type should be point</span> +<span class="Comment">//: we might want to call 'index' without saving the results, say in a sandbox</span> + +<span class="Delimiter">:(scenario index_without_product)</span> +recipe main [ + <span class="Constant">1</span>:array:number:<span class="Constant">3</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> + index <span class="Constant">1</span>:array:number:<span class="Constant">3</span><span class="Delimiter">,</span> <span class="Constant">0</span> +] +<span class="Comment"># just don't die</span> + <span class="SalientComment">//:: To write to elements of containers, you need their address.</span> <span class="Delimiter">:(scenario index_address)</span> @@ -322,7 +334,7 @@ case INDEX_ADDRESS: <span class="Delimiter">{</span> reagent element<span class="Delimiter">;</span> element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>*array_element<span class="Delimiter">(</span>base<span class="Delimiter">.</span>type<span class="Delimiter">));</span> element<span class="Delimiter">.</span>type = new type_tree<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"address"</span><span class="Delimiter">),</span> element<span class="Delimiter">.</span>type<span class="Delimiter">);</span> - if <span class="Delimiter">(</span>!types_match<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<span class="Delimiter">))</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>!types_coercible<span class="Delimiter">(</span>product<span class="Delimiter">,</span> element<span class="Delimiter">))</span> <span class="Delimiter">{</span> raise_error << 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">"'index' on "</span> << base<span class="Delimiter">.</span>original_string << <span class="Constant">" can't be saved in "</span> << product<span class="Delimiter">.</span>original_string << <span class="Constant">"; type should be "</span> << debug_string<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -376,7 +388,7 @@ recipe main [ <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe index-address *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> -<span class="Constant">1</span> ] <span class="traceContains">+error: main: invalid index -1</span> @@ -391,7 +403,7 @@ recipe main [ <span class="Constant">5</span>:number<span class="Special"> <- </span>copy <span class="Constant">14</span> <span class="Constant">6</span>:number<span class="Special"> <- </span>copy <span class="Constant">15</span> <span class="Constant">7</span>:number<span class="Special"> <- </span>copy <span class="Constant">16</span> - <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/<span class="Special">raw</span> + <span class="Constant">8</span>:address:array:point<span class="Special"> <- </span>copy <span class="Constant">1</span>/unsafe <span class="Constant">9</span>:address:number<span class="Special"> <- </span>index-address *<span class="Constant">8</span>:address:array:point<span class="Delimiter">,</span> <span class="Constant">0</span> ] <span class="traceContains">+error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be <address : <point : <>>></span> @@ -445,6 +457,18 @@ case LENGTH: <span class="Delimiter">{</span> recipe_ordinal r = current_instruction<span class="Delimiter">().</span>operation<span class="Delimiter">;</span> if <span class="Delimiter">(</span>r == CREATE_ARRAY || r == INDEX || r == INDEX_ADDRESS || r == LENGTH<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> + +<span class="Comment">//: a particularly common array type is the string, or address:array:character</span> +<span class="Delimiter">:(code)</span> +bool is_mu_string<span class="Delimiter">(</span>const reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Identifier">return</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">"address"</span><span class="Delimiter">)</span> + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<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> + && 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>value == get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> <span class="Constant">"character"</span><span class="Delimiter">)</span> + && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right == <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> </pre> </body> </html> |