diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-09-17 15:01:51 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-09-17 15:01:51 -0700 |
commit | f344b250f6f062a1a1902bf69b23ebf9b565de0e (patch) | |
tree | 199bd32a9aee198d5028b1c21b83d2cf0944b2b6 /html/043space.cc.html | |
parent | 897ae8c1855f830d8819759ea327d147f28a09bf (diff) | |
download | mu-f344b250f6f062a1a1902bf69b23ebf9b565de0e.tar.gz |
3395
Diffstat (limited to 'html/043space.cc.html')
-rw-r--r-- | html/043space.cc.html | 116 |
1 files changed, 61 insertions, 55 deletions
diff --git a/html/043space.cc.html b/html/043space.cc.html index 221f4ff2..036f7def 100644 --- a/html/043space.cc.html +++ b/html/043space.cc.html @@ -38,29 +38,35 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Comment">//: and all addresses in arguments are implicitly based on the 'default-space'</span> <span class="Comment">//: (unless they have the /raw property)</span> +<span class="Comment">//: A space is just an array of any scalar location.</span> +<span class="Delimiter">:(before "End Mu Types Initialization")</span> +put<span class="Delimiter">(</span>Type_abbreviations<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">,</span> new_type_tree<span class="Delimiter">(</span><span class="Constant">"address:array:location"</span><span class="Delimiter">));</span> +<span class="Comment">//: Spaces are often called 'scopes' in other languages.</span> +put<span class="Delimiter">(</span>Type_abbreviations<span class="Delimiter">,</span> <span class="Constant">"scope"</span><span class="Delimiter">,</span> new_type_tree<span class="Delimiter">(</span><span class="Constant">"address:array:location"</span><span class="Delimiter">));</span> + <span class="Delimiter">:(scenario set_default_space)</span> <span class="Comment"># if default-space is 10, and if an array of 5 locals lies from location 12 to 16 (inclusive),</span> <span class="Comment"># then local 0 is really location 12, local 1 is really location 13, and so on.</span> def main [ <span class="Comment"># pretend address:array:location; in practice we'll use new</span> - <span class="Constant">10</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> - <span class="Constant">11</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe - <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span> + <span class="Constant">10</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">11</span>:num<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Normal">default</span>-space:space<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe + <span class="Constant">1</span>:num<span class="Special"> <- </span>copy <span class="Constant">23</span> ] <span class="traceContains">+mem: storing 23 in location 13</span> <span class="Delimiter">:(scenario lookup_sidesteps_default_space)</span> def main [ <span class="Comment"># pretend pointer from outside (2000 reserved for refcount)</span> - <span class="Constant">2001</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2001</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># pretend address:array:location; in practice we'll use new</span> - <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> - <span class="Constant">1001</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Constant">1000</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">1001</span>:num<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe - <span class="Constant">1</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe <span class="Comment"># even local variables always contain raw addresses</span> - <span class="Constant">8</span>:number/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:address:number + <span class="Normal">default</span>-space:space<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe + <span class="Constant">1</span>:&:num<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe <span class="Comment"># even local variables always contain raw addresses</span> + <span class="Constant">8</span>:num/<span class="Special">raw <- </span>copy *<span class="Constant">1</span>:&:num ] <span class="traceContains">+mem: storing 34 in location 8</span> @@ -68,7 +74,7 @@ def main [ <span class="Delimiter">:(scenario convert_names_passes_default_space)</span> <span class="Special">% Hide_errors = true;</span> def main [ - <span class="Normal">default</span>-space:number<span class="Delimiter">,</span> x:number<span class="Special"> <- </span>copy <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> + <span class="Normal">default</span>-space:num<span class="Delimiter">,</span> x:num<span class="Special"> <- </span>copy <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+name: assign x 1</span> <span class="traceAbsent">-name: assign default-space 1</span> @@ -131,8 +137,8 @@ absolutize<span class="Delimiter">(</span>x<span class="Delimiter">);</span> <span class="Delimiter">:(scenario get_default_space)</span> def main [ - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe - <span class="Constant">1</span>:address:array:location/<span class="Special">raw <- </span>copy <span class="Normal">default</span>-space:address:array:location + <span class="Normal">default</span>-space:space<span class="Special"> <- </span>copy <span class="Constant">10</span>/unsafe + <span class="Constant">1</span>:space/<span class="Special">raw <- </span>copy <span class="Normal">default</span>-space:space ] <span class="traceContains">+mem: storing 10 in location 1</span> @@ -148,15 +154,15 @@ def main [ <span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_get)</span> def main [ <span class="Comment"># pretend pointer to container from outside (2000 reserved for refcount)</span> - <span class="Constant">2001</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> - <span class="Constant">2002</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">2001</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2002</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Comment"># pretend address:array:location; in practice we'll use new</span> - <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> - <span class="Constant">1001</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Constant">1000</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">1001</span>:num<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe - <span class="Constant">1</span>:address:point<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe - <span class="Constant">9</span>:number/<span class="Special">raw <- </span>get *<span class="Constant">1</span>:address:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset + <span class="Normal">default</span>-space:space<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe + <span class="Constant">1</span>:&:point<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe + <span class="Constant">9</span>:num/<span class="Special">raw <- </span>get *<span class="Constant">1</span>:&:point<span class="Delimiter">,</span> <span class="Constant">1</span>:offset ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -168,16 +174,16 @@ element<span class="Delimiter">.</span>properties<span class="Delimiter">.</span <span class="Delimiter">:(scenario lookup_sidesteps_default_space_in_index)</span> def main [ <span class="Comment"># pretend pointer to array from outside (2000 reserved for refcount)</span> - <span class="Constant">2001</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span> <span class="Comment"># length</span> - <span class="Constant">2002</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> - <span class="Constant">2003</span>:number<span class="Special"> <- </span>copy <span class="Constant">35</span> + <span class="Constant">2001</span>:num<span class="Special"> <- </span>copy <span class="Constant">2</span> <span class="Comment"># length</span> + <span class="Constant">2002</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Constant">2003</span>:num<span class="Special"> <- </span>copy <span class="Constant">35</span> <span class="Comment"># pretend address:array:location; in practice we'll use new</span> - <span class="Constant">1000</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> - <span class="Constant">1001</span>:number<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> + <span class="Constant">1000</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Comment"># refcount</span> + <span class="Constant">1001</span>:num<span class="Special"> <- </span>copy <span class="Constant">5</span> <span class="Comment"># length</span> <span class="Comment"># actual start of this recipe</span> - <span class="Normal">default</span>-space:address:array:location<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe - <span class="Constant">1</span>:address:array:number<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe - <span class="Constant">9</span>:number/<span class="Special">raw <- </span>index *<span class="Constant">1</span>:address:array:number<span class="Delimiter">,</span> <span class="Constant">1</span> + <span class="Normal">default</span>-space:space<span class="Special"> <- </span>copy <span class="Constant">1000</span>/unsafe + <span class="Constant">1</span>:&:@:num<span class="Special"> <- </span>copy <span class="Constant">2000</span>/unsafe + <span class="Constant">9</span>:num/<span class="Special">raw <- </span>index *<span class="Constant">1</span>:&:@:num<span class="Delimiter">,</span> <span class="Constant">1</span> ] <span class="traceContains">+mem: storing 35 in location 9</span> @@ -190,8 +196,8 @@ element<span class="Delimiter">.</span>properties<span class="Delimiter">.</span <span class="Delimiter">:(scenario new_default_space)</span> def main [ <span class="Normal">new</span>-<span class="Normal">default</span>-space - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span> - <span class="Normal">y</span>:number<span class="Special"> <- </span>copy <span class="Constant">3</span> + <span class="Normal">x</span>:num<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Normal">y</span>:num<span class="Special"> <- </span>copy <span class="Constant">3</span> ] <span class="Comment"># allocate space for x and y, as well as the chaining slot at 0</span> <span class="traceContains">+mem: array length is 3</span> @@ -204,7 +210,7 @@ def main [ <span class="Delimiter">:(before "End Rewrite Instruction(curr, recipe result)")</span> <span class="Comment">// rewrite `new-default-space` to</span> -<span class="Comment">// `default-space:address:array:location <- new location:type, number-of-locals:literal`</span> +<span class="Comment">// `default-space:space <- new location:type, number-of-locals:literal`</span> <span class="Comment">// where N is Name[recipe][""]</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"new-default-space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> rewrite_default_space_instruction<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> @@ -228,14 +234,14 @@ def main [ <span class="Delimiter">:(scenario local_scope)</span> def main [ - <span class="Constant">1</span>:address<span class="Special"> <- </span>foo - <span class="Constant">2</span>:address<span class="Special"> <- </span>foo - <span class="Constant">3</span>:boolean<span class="Special"> <- </span>equal <span class="Constant">1</span>:address<span class="Delimiter">,</span> <span class="Constant">2</span>:address + <span class="Constant">1</span>:&<span class="Special"> <- </span>foo + <span class="Constant">2</span>:&<span class="Special"> <- </span>foo + <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> <- </span>equal <span class="Constant">1</span>:&<span class="Delimiter">,</span> <span class="Constant">2</span>:& ] def foo [ local-scope - <span class="Normal">x</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span> - <span class="Identifier">return</span> <span class="Normal">default</span>-space:address:array:location + <span class="Normal">x</span>:num<span class="Special"> <- </span>copy <span class="Constant">34</span> + <span class="Identifier">return</span> <span class="Normal">default</span>-space:space ] <span class="Comment"># both calls to foo should have received the same default-space</span> <span class="traceContains">+mem: storing 1 in location 3</span> @@ -243,9 +249,9 @@ def foo [ <span class="Delimiter">:(scenario local_scope_frees_up_addresses)</span> def main [ local-scope - <span class="Normal">x</span>:address:array:character<span class="Special"> <- </span><span class="Normal">new</span> [abc] + <span class="Normal">x</span>:text<span class="Special"> <- </span><span class="Normal">new</span> [abc] ] -<span class="traceContains">+mem: clearing x:address:array:character</span> +<span class="traceContains">+mem: clearing x:text</span> <span class="Delimiter">:(before "End Rewrite Instruction(curr, recipe result)")</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">"local-scope"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -340,21 +346,21 @@ Update_refcounts_in_write_memory = <span class="Constant">true</span><span class curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"number-of-locals:literal"</span><span class="Delimiter">));</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> raise << <span class="Constant">"new-default-space can't take any results</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> - curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"default-space:address:array:location"</span><span class="Delimiter">));</span> + curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">"default-space:space"</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> <span class="Delimiter">:(scenario local_scope_frees_up_addresses_inside_containers)</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:address:number + <span class="Normal">x</span>:num + <span class="Normal">y</span>:&:num ] def main [ local-scope - <span class="Normal">x</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type - <span class="Normal">y</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> x:address:number + <span class="Normal">x</span>:&:num<span class="Special"> <- </span><span class="Normal">new</span> number:type + <span class="Normal">y</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> x:&:num <span class="Comment"># x and y are both cleared when main returns</span> ] -<span class="traceContains">+mem: clearing x:address:number</span> +<span class="traceContains">+mem: clearing x:&:num</span> <span class="traceContains">+mem: decrementing refcount of 1006: 2 -> 1</span> <span class="traceContains">+mem: clearing y:foo</span> <span class="traceContains">+mem: decrementing refcount of 1006: 1 -> 0</span> @@ -362,24 +368,24 @@ def main [ <span class="Delimiter">:(scenario local_scope_returns_addresses_inside_containers)</span> container foo [ - <span class="Normal">x</span>:number - <span class="Normal">y</span>:address:number + <span class="Normal">x</span>:num + <span class="Normal">y</span>:&:num ] def f [ local-scope - <span class="Normal">x</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type - *x:address:number<span class="Special"> <- </span>copy <span class="Constant">12</span> - <span class="Normal">y</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> x:address:number + <span class="Normal">x</span>:&:num<span class="Special"> <- </span><span class="Normal">new</span> number:type + *x:&:num<span class="Special"> <- </span>copy <span class="Constant">12</span> + <span class="Normal">y</span>:foo<span class="Special"> <- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> x:&:num <span class="Comment"># since y is 'escaping' f, it should not be cleared</span> <span class="Identifier">return</span> y:foo ] def main [ <span class="Constant">1</span>:foo<span class="Special"> <- </span>f - <span class="Constant">3</span>:number<span class="Special"> <- </span>get <span class="Constant">1</span>:foo<span class="Delimiter">,</span> x:offset - <span class="Constant">4</span>:address:number<span class="Special"> <- </span>get <span class="Constant">1</span>:foo<span class="Delimiter">,</span> y:offset - <span class="Constant">5</span>:number<span class="Special"> <- </span>copy *<span class="Constant">4</span>:address:number + <span class="Constant">3</span>:num<span class="Special"> <- </span>get <span class="Constant">1</span>:foo<span class="Delimiter">,</span> x:offset + <span class="Constant">4</span>:&:num<span class="Special"> <- </span>get <span class="Constant">1</span>:foo<span class="Delimiter">,</span> y:offset + <span class="Constant">5</span>:num<span class="Special"> <- </span>copy *<span class="Constant">4</span>:&:num <span class="Constant">1</span>:foo<span class="Special"> <- </span>put <span class="Constant">1</span>:foo<span class="Delimiter">,</span> y:offset<span class="Delimiter">,</span> <span class="Constant">0</span> - <span class="Constant">4</span>:address:number<span class="Special"> <- </span>copy <span class="Constant">0</span> + <span class="Constant">4</span>:&:num<span class="Special"> <- </span>copy <span class="Constant">0</span> ] <span class="traceContains">+mem: storing 34 in location 1</span> <span class="traceContains">+mem: storing 1006 in location 2</span> @@ -399,8 +405,8 @@ def main [ <span class="Delimiter">:(scenario local_scope_claims_return_values_when_not_saved)</span> def f [ local-scope - <span class="Normal">x</span>:address:number<span class="Special"> <- </span><span class="Normal">new</span> number:type - reply x:address:number + <span class="Normal">x</span>:&:num<span class="Special"> <- </span><span class="Normal">new</span> number:type + reply x:&:num ] def main [ f <span class="Comment"># doesn't save result</span> |