diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-01 15:55:42 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-01 15:55:42 -0700 |
commit | a65fbc8bf91d6cbe7d1d96980c2c0e7c3f6d3713 (patch) | |
tree | 4ada04c92b8dfdda21ef8cbc89e30e33604e94bc /mu.arc.t.html | |
parent | eee42c94115b6aca4b4078b7efc99d313cc097f1 (diff) | |
download | mu-a65fbc8bf91d6cbe7d1d96980c2c0e7c3f6d3713.tar.gz |
211 - update html for reading
Diffstat (limited to 'mu.arc.t.html')
-rw-r--r-- | mu.arc.t.html | 881 |
1 files changed, 600 insertions, 281 deletions
diff --git a/mu.arc.t.html b/mu.arc.t.html index 352419a2..2883aaca 100644 --- a/mu.arc.t.html +++ b/mu.arc.t.html @@ -18,9 +18,11 @@ a { color:#4444ff; } .Comment { color: #8080ff; } .Delimiter { color: #600060; } .Normal { color: #aaaaaa; } +.Identifier { color: #008080; } +.Global { color: #00af87; } +.CommentedCode { color: #666666; } .Mu, .Mu .Normal, .Mu .Constant { color: #eeeeee; } .Op { color: #ff8888; } -.CommentedCode { color: #666666; } --> </style> @@ -143,46 +145,7 @@ a { color:#4444ff; } <span class="Comment">; Other than that, we'll say no more about the code, and focus in the rest of</span> <span class="Comment">; this file on the scenarios the code cares about.</span> -<span class="Mu"> -<span class="Delimiter">(</span>load <span class="MuConstant">"mu.arc"</span><span class="Delimiter">)</span> - -<span class="Comment">; Every test below is conceptually a run right after our virtual machine</span> -<span class="Comment">; starts up. When it starts up we assume it knows about the following types.</span> - -<span class="Delimiter">(</span>on-init - <span class="Delimiter">(</span>= types* <span class="Delimiter">(</span>obj - <span class="Comment">; Each type must be scalar or array, sum or product or primitive</span> - type <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> <span class="Comment">; implicitly scalar and primitive</span> - type-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>type<span class="Delimiter">)</span> - type-array <span class="Delimiter">(</span>obj array <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>type<span class="Delimiter">)</span> - type-array-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>type-array<span class="Delimiter">)</span> - location <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>location<span class="Delimiter">)</span> <span class="Comment">; assume it points to an atom</span> - integer <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> - boolean <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> - boolean-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span><span class="Delimiter">)</span> - byte <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> -<span class="CommentedCode">;? string (obj array <span class="MuConstant">t</span> elem 'byte) ; inspired by Go</span> - character <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> <span class="Comment">; int32 like a Go rune</span> - character-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>character<span class="Delimiter">)</span> - string <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span><span class="Delimiter">)</span> <span class="Comment">; temporary hack</span> - <span class="Comment">; arrays consist of an integer length followed by the right number of elems</span> - integer-array <span class="Delimiter">(</span>obj array <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> - integer-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> <span class="Comment">; pointer to int</span> - <span class="Comment">; records consist of a series of elems, corresponding to a list of types</span> - integer-boolean-pair <span class="Delimiter">(</span>obj size <span class="MuConstant">2</span> record <span class="MuConstant">t</span> elems <span class="Delimiter">'(</span>integer boolean<span class="Delimiter">))</span> - integer-boolean-pair-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>integer-boolean-pair<span class="Delimiter">)</span> - integer-boolean-pair-array <span class="Delimiter">(</span>obj array <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>integer-boolean-pair<span class="Delimiter">)</span> - integer-integer-pair <span class="Delimiter">(</span>obj size <span class="MuConstant">2</span> record <span class="MuConstant">t</span> elems <span class="Delimiter">'(</span>integer integer<span class="Delimiter">))</span> - integer-point-pair <span class="Delimiter">(</span>obj size <span class="MuConstant">2</span> record <span class="MuConstant">t</span> elems <span class="Delimiter">'(</span>integer integer-integer-pair<span class="Delimiter">))</span> - <span class="Comment">; tagged-values are the foundation of dynamic types</span> - tagged-value <span class="Delimiter">(</span>obj size <span class="MuConstant">2</span> record <span class="MuConstant">t</span> elems <span class="Delimiter">'(</span>type location<span class="Delimiter">))</span> - tagged-value-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>tagged-value<span class="Delimiter">)</span> - <span class="Comment">; heterogeneous lists</span> - list <span class="Delimiter">(</span>obj size <span class="MuConstant">2</span> record <span class="MuConstant">t</span> elems <span class="Delimiter">'(</span>tagged-value list-address<span class="Delimiter">))</span> - list-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>list<span class="Delimiter">)</span> - list-address-address <span class="Delimiter">(</span>obj size <span class="MuConstant">1</span> address <span class="MuConstant">t</span> elem <span class="Delimiter">'</span>list-address<span class="Delimiter">)</span> - <span class="Delimiter">)))</span> -</span> +<span class="Delimiter">(</span>load <span class="Constant">"mu.arc"</span><span class="Delimiter">)</span> <span class="Comment">; Our language is assembly-like in that functions consist of series of</span> <span class="Comment">; statements, and statements consist of an operation and its arguments (input</span> @@ -212,8 +175,8 @@ a { color:#4444ff; } <span class="Comment">; lightweight tools that can be combined in various ways, say for using</span> <span class="Comment">; different typecheckers in different subsystems.</span> <span class="Comment">;</span> -<span class="Comment">; In the rest of this file we'll highlight lines of the assembly language</span> -<span class="Comment">; and <span style='color:#aaaaaa'>deemphasize</span> the (ugly) test harness.</span> +<span class="Comment">; In our tests we'll define such mu functions using a call to 'add-fns', so</span> +<span class="Comment">; look for it. Everything outside 'add-fns' is just test-harness details.</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"literal"</span><span class="Delimiter">)</span> @@ -222,7 +185,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">23</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">23</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'copy' writes its lone 'arg' after the instruction name to its lone 'oarg' or output arg before the arrow. After this test, the value 23 is stored in memory address 1."</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -237,7 +200,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'add' operates on two addresses"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -246,7 +209,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">5</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">5</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - ops can take 'literal' operands (but not return them)"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -256,7 +219,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> sub <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">-2</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">-2</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'sub' subtracts the second arg from the first"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -266,7 +229,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> mul <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">6</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">6</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'mul' multiplies like 'add' adds"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -276,22 +239,22 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> div <span class="Delimiter">(</span><span class="MuConstant">8</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Delimiter">(</span>/ real.8 <span class="Constant">3</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Delimiter">(</span><span class="Identifier">/</span> real.8 <span class="Constant">3</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'div' divides like 'sub' subtracts"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"idiv-literal"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> idiv <span class="Delimiter">(</span><span class="MuConstant">8</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> idiv <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">6</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">5</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'idiv' performs integer division, returning quotient and remainder"</span><span class="Delimiter">))</span> <span class="Comment">; Basic boolean operations: and, or, not</span> <span class="Comment">; There are easy ways to encode booleans in binary, but we'll skip past those</span> -<span class="Comment">; details.</span> +<span class="Comment">; details for now.</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"and-literal"</span><span class="Delimiter">)</span> @@ -300,7 +263,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> and <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 nil<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> nil<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - logical 'and' for booleans"</span><span class="Delimiter">))</span> <span class="Comment">; Basic comparison operations: lt, le, gt, ge, eq, neq</span> @@ -312,7 +275,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> lt <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 nil<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> nil<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'lt' is the less-than inequality operator"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -322,7 +285,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> le <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 nil<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> nil<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'le' is the <= inequality operator"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -332,7 +295,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> le <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 t<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> t<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'le' returns true for equal operands"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -342,10 +305,10 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> le <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 t<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> t<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - le is the <= inequality operator - 2"</span><span class="Delimiter">))</span> -<span class="Comment">; Control flow operations: jump, jump-if</span> +<span class="Comment">; Control flow operations: jump, jump-if, jump-unless</span> <span class="Comment">; These introduce a new type -- 'offset' -- for literals that refer to memory</span> <span class="Comment">; locations relative to the current location.</span> @@ -354,12 +317,12 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">8</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span> <span class="Comment">; should be skipped</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">8</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">8</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'jump' skips some instructions"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -367,13 +330,13 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">8</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span> <span class="Comment">; should be skipped</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))))</span> <span class="Comment">; never reached</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">8</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">8</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'jump' doesn't skip too many instructions"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -383,13 +346,13 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> eq <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> t <span class="Constant">2</span> <span class="Constant">1</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> t <span class="Constant">2</span> <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'jump-if' is a conditional 'jump'"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -397,13 +360,13 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> eq <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> nil <span class="Constant">2</span> <span class="Constant">3</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> nil <span class="Constant">2</span> <span class="Constant">3</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - if 'jump-if's first arg is false, it doesn't skip any instructions"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -415,13 +378,13 @@ a { color:#4444ff; } <span class="Comment">; loop</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> eq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">-3</span> offset<span class="Delimiter">))</span> <span class="Comment">; to loop</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">-3</span> offset<span class="Delimiter">))</span> <span class="Comment">; to loop</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">3</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">3</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'jump-if' can take a negative offset to make backward jumps"</span><span class="Delimiter">))</span> <span class="Comment">; Data movement relies on addressing modes:</span> @@ -436,7 +399,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'copy' performs direct addressing"</span><span class="Delimiter">))</span> <span class="Comment">; 'Indirect' addressing refers to an address stored in a memory location.</span> @@ -448,12 +411,12 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"indirect-addressing"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span> <span class="Comment">; unsafe; can't do this in general</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="Constant">1</span> integer-address deref<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">34</span> <span class="Constant">3</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">34</span> <span class="Constant">3</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'copy' performs indirect addressing"</span><span class="Delimiter">))</span> <span class="Comment">; Output args can use indirect addressing. In the test below the value is</span> @@ -468,14 +431,20 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">36</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">36</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - instructions can perform indirect addressing on output arg"</span><span class="Delimiter">))</span> <span class="Comment">; Until now we've dealt with scalar types like integers and booleans and</span> -<span class="Comment">; addresses. We can also have compound types: arrays and records.</span> +<span class="Comment">; addresses, where mu looks like other assembly languages. In addition, mu</span> +<span class="Comment">; provides first-class support for compound types: arrays and records.</span> <span class="Comment">;</span> <span class="Comment">; 'get' accesses fields in records</span> <span class="Comment">; 'index' accesses indices in arrays</span> +<span class="Comment">;</span> +<span class="Comment">; Both operations require knowledge about the types being worked on, so all</span> +<span class="Comment">; types used in mu programs are defined in a single global system-wide table</span> +<span class="Comment">; (see types* in mu.arc for the complete list of types; we'll add to it over</span> +<span class="Comment">; time).</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"get-record"</span><span class="Delimiter">)</span> @@ -485,9 +454,10 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'get' accesses fields of records"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -499,9 +469,10 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-boolean-pair-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">3</span> integer-boolean-pair-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">3</span> integer-boolean-pair-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> nil <span class="Constant">5</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> nil <span class="Constant">5</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'get' accesses fields of record address"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -514,7 +485,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer-integer-pair<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">1</span> integer-point-pair<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> <span class="Constant">35</span> <span class="Constant">3</span> <span class="Constant">36</span> <span class="Constant">4</span> <span class="Constant">35</span> <span class="Constant">5</span> <span class="Constant">36</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> <span class="Constant">35</span> <span class="Constant">3</span> <span class="Constant">36</span> <span class="Constant">4</span> <span class="Constant">35</span> <span class="Constant">5</span> <span class="Constant">36</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'get' accesses fields spanning multiple locations"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -522,11 +493,11 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> t <span class="Constant">3</span> <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> t <span class="Constant">3</span> <span class="Constant">2</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'get-address' returns address of fields of records"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -534,16 +505,16 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-boolean-pair-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">3</span> integer-boolean-pair-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> t <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> t <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'get-address' accesses fields of record address"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"index-array-literal"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"index-literal"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> @@ -554,11 +525,12 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> index <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-array<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">24</span> <span class="Constant">7</span> t<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">24</span> <span class="Constant">7</span> t<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index' accesses indices of arrays"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"index-array-direct"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"index-direct"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> @@ -570,8 +542,29 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> index <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-array<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">24</span> <span class="Constant">8</span> t<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">24</span> <span class="Constant">8</span> t<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index' accesses indices of arrays"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"index-indirect"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">24</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer-boolean-pair-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> index <span class="Delimiter">(</span><span class="Constant">7</span> integer-boolean-pair-array-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))</span> +<span class="CommentedCode">;? (set dump-trace*)</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">1</span> <span class="Constant">8</span> <span class="Constant">24</span> <span class="Constant">9</span> t<span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index' accesses indices of array address"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"index-address"</span><span class="Delimiter">)</span> @@ -586,10 +579,25 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer-boolean-pair-address<span class="Delimiter">)</span> <span class="Op"><-</span> index-address <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-array<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">4</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index-address' returns addresses of indices of arrays"</span><span class="Delimiter">))</span> -<span class="Comment">; todo: test that out-of-bounds access throws an error</span> +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"index-address-indirect"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">24</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer-boolean-pair-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> integer-boolean-pair-address<span class="Delimiter">)</span> <span class="Op"><-</span> index-address <span class="Delimiter">(</span><span class="Constant">7</span> integer-boolean-pair-array-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">1</span> <span class="Constant">8</span> <span class="Constant">4</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index-address' returns addresses of indices of array addresses"</span><span class="Delimiter">))</span> <span class="Comment">; Array values know their length. Record lengths are saved in the types table.</span> @@ -605,9 +613,27 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> len <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-array<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">2</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'len' accesses length of array"</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"len-array-indirect"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">24</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> len <span class="Delimiter">(</span><span class="Constant">6</span> integer-boolean-pair-array-address deref<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (set dump-trace*)</span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">2</span> <span class="Constant">23</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">24</span> <span class="Constant">5</span> t <span class="Constant">6</span> <span class="Constant">1</span> <span class="Constant">7</span> <span class="Constant">2</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'len' accesses length of array address"</span><span class="Delimiter">))</span> + <span class="Comment">; 'sizeof' is a helper to determine the amount of memory required by a type.</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -617,7 +643,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> sizeof <span class="Delimiter">(</span>integer-boolean-pair literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">2</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'sizeof' returns space required by arg"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -627,7 +653,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> sizeof <span class="Delimiter">(</span>integer-point-pair literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.1 <span class="Constant">3</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.1</span> <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'sizeof' is different from number of elems"</span><span class="Delimiter">))</span> <span class="Comment">; Regardless of a type's length, you can move it around just like a primitive.</span> @@ -642,28 +668,28 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">34</span> <span class="Constant">4</span> nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">34</span> <span class="Constant">4</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - ops can operate on records spanning multiple locations"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"compound-arg"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' can copy records spanning multiple locations"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"compound-arg"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"compound-arg-indirect"</span><span class="Delimiter">)</span> <span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer-boolean-pair<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> @@ -671,17 +697,21 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="Constant">3</span> integer-boolean-pair-address deref<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> nil <span class="Constant">3</span> <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' can copy records spanning multiple locations in indirect mode"</span><span class="Delimiter">))</span> <span class="Comment">; A special kind of record is the 'tagged type'. It lets us represent</span> <span class="Comment">; dynamically typed values, which save type information in memory rather than</span> <span class="Comment">; in the code to use them. This will let us do things like create heterogenous</span> -<span class="Comment">; lists containing both integers and strings.</span> +<span class="Comment">; lists containing both integers and strings. Tagged values admit two</span> +<span class="Comment">; operations:</span> +<span class="Comment">;</span> +<span class="Comment">; 'save-type' - turns a regular value into a tagged-value of the appropriate type</span> +<span class="Comment">; 'maybe-coerce' - turns a tagged value into a regular value if the type matches</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"tagged-value"</span><span class="Delimiter">)</span> -<span class="CommentedCode">;? (set dump-trace*)</span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> type<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span>integer-address literal<span class="Delimiter">))</span></span> @@ -689,8 +719,12 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-address<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">1</span> tagged-value<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer-address literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is memory*.3 <span class="Constant">34</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is memory*.4 t<span class="Delimiter">))</span> +<span class="CommentedCode">;? (prn completed-routines*)</span> +<span class="Delimiter">(</span><span class="Normal">let</span> last-routine <span class="Delimiter">(</span>deq <span class="Global">completed-routines*</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>aif rep.last-routine!error <span class="Delimiter">(</span>prn <span class="Constant">"error - "</span> it<span class="Delimiter">)))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.3</span> <span class="Constant">34</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.4</span> t<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'maybe-coerce' copies value only if type tag matches"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"tagged-value-2"</span><span class="Delimiter">)</span> @@ -702,21 +736,33 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-address<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">1</span> tagged-value<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean-address literal<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is memory*.3 <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is memory*.4 nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.3</span> <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.4</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'maybe-coerce' doesn't copy value when type tag doesn't match"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"save-type"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span> <span class="Comment">; pointer to nowhere</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value<span class="Delimiter">)</span> <span class="Op"><-</span> save-type <span class="Delimiter">(</span><span class="Constant">1</span> integer-address<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">34</span> <span class="Constant">2</span> <span class="Delimiter">'</span>integer-address <span class="Constant">3</span> <span class="Constant">34</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'save-type' saves the type of a value at runtime, turning it into a tagged-value"</span><span class="Delimiter">))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"new-tagged-value"</span><span class="Delimiter">)</span> -<span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span> <span class="Comment">; pointer to nowhere</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>integer-address literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">1</span> integer-address<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer-address<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">2</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer-address literal<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1" "sizeof")))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is memory*.3 <span class="Constant">34</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is memory*.4 t<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.3</span> <span class="Constant">34</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.4</span> t<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new-tagged-value' is the converse of 'maybe-coerce'"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> <span class="Comment">; Now that we can record types for values we can construct a dynamically typed</span> <span class="Comment">; list.</span> @@ -727,46 +773,76 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> <span class="Comment">; 1 points at first node: tagged-value (int 34)</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> list-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>list type<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> list-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>list literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> list-value-address <span class="Delimiter">(</span><span class="Constant">1</span> list-address<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> type-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">2</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> type-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> location<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">2</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> location deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> list-address-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">1</span> list-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> list-address-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>list type<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> list-address-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>list literal<span class="Delimiter">))</span></span> <span class="Comment">; 6 points at second node: tagged-value (boolean t)</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> list-address<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="Constant">5</span> list-address-address deref<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> list-value-address <span class="Delimiter">(</span><span class="Constant">6</span> list-address<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> type-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> type-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> location<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> location deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> location deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">10</span> list-address<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">6</span> list-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Delimiter">)))</span> <span class="Delimiter">(</span><span class="Normal">let</span> first Memory-in-use-until <span class="Delimiter">(</span>run <span class="Delimiter">'</span>test1<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~all first <span class="Delimiter">(</span>map memory* <span class="Delimiter">'(</span><span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span><span class="Delimiter">)))</span> - <span class="Delimiter">(</span>~is memory*.first <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> - <span class="Delimiter">(</span>~is memory*.4 <span class="Delimiter">(</span>+ first <span class="Constant">1</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>~is <span class="Delimiter">(</span>memory* <span class="Delimiter">(</span>+ first <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Constant">34</span><span class="Delimiter">)</span> - <span class="Delimiter">(</span>~is memory*.5 <span class="Delimiter">(</span>+ first <span class="Constant">2</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span><span class="Normal">let</span> second memory*.6 - <span class="Delimiter">(</span>~is <span class="Delimiter">(</span>memory* <span class="Delimiter">(</span>+ first <span class="Constant">2</span><span class="Delimiter">))</span> second<span class="Delimiter">)</span> - <span class="Delimiter">(</span>~all second <span class="Delimiter">(</span>map memory* <span class="Delimiter">'(</span><span class="Constant">6</span> <span class="Constant">7</span> <span class="Constant">8</span><span class="Delimiter">)))</span> - <span class="Delimiter">(</span>~is memory*.second <span class="Delimiter">'</span>boolean<span class="Delimiter">)</span> - <span class="Delimiter">(</span>~is memory*.9 <span class="Delimiter">(</span>+ second <span class="Constant">1</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>~is <span class="Delimiter">(</span>memory* <span class="Delimiter">(</span>+ second <span class="Constant">1</span><span class="Delimiter">))</span> t<span class="Delimiter">)))</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'list' constructs a heterogeneous list, which can contain elements of different types"</span><span class="Delimiter">)))</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~all first <span class="Delimiter">(</span><span class="Identifier">map</span> <span class="Global">memory*</span> <span class="Delimiter">'(</span><span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span><span class="Delimiter">)))</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Error">.first</span> <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.4</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">1</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Constant">34</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.5</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">2</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span><span class="Normal">let</span> second <span class="Global">memory*</span><span class="Constant">.6</span> + <span class="Delimiter">(</span><span class="Normal">or</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">2</span><span class="Delimiter">))</span> second<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~all second <span class="Delimiter">(</span><span class="Identifier">map</span> <span class="Global">memory*</span> <span class="Delimiter">'(</span><span class="Constant">6</span> <span class="Constant">7</span> <span class="Constant">8</span><span class="Delimiter">)))</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Error">.second</span> <span class="Delimiter">'</span>boolean<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.9</span> <span class="Delimiter">(</span><span class="Identifier">+</span> second <span class="Constant">1</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> second <span class="Constant">1</span><span class="Delimiter">))</span> t<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.10</span> nil<span class="Delimiter">))))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - lists can contain elements of different types"</span><span class="Delimiter">)))</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test2</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">10</span> list-address<span class="Delimiter">)</span> <span class="Op"><-</span> list-next <span class="Delimiter">(</span><span class="Constant">1</span> list-address<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>test2<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.10 memory*.6<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.10</span> <span class="Global">memory*</span><span class="Constant">.6</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'list-next can move a list pointer to the next node"</span><span class="Delimiter">))</span> +<span class="Comment">; 'new-list' takes a variable number of args and constructs a list containing</span> +<span class="Comment">; them.</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-list"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> new-list <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1" "sizeof")))</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">let</span> first <span class="Global">memory*</span><span class="Constant">.1</span> +<span class="CommentedCode">;? (prn first)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Error">.first</span> <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Constant">3</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span><span class="Normal">let</span> second <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> first <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (prn second)</span> + <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Error">.second</span> <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> second <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Constant">4</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span><span class="Normal">let</span> third <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> second <span class="Constant">2</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (prn third)</span> + <span class="Delimiter">(</span><span class="Normal">or</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Error">.third</span> <span class="Delimiter">'</span>integer<span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> third <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Constant">5</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> third <span class="Constant">2</span><span class="Delimiter">)</span> nil<span class="Delimiter">)))))))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new-list' can construct a list of integers"</span><span class="Delimiter">)))</span> + <span class="Comment">; Just like the table of types is centralized, functions are conceptualized as</span> -<span class="Comment">; a centralized table of operations just like the 'primitives' we've seen so</span> +<span class="Comment">; a centralized table of operations just like the "primitives" we've seen so</span> <span class="Comment">; far. If you create a function you can call it like any other op.</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -780,7 +856,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">(</span>test1<span class="Delimiter">))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - calling a user-defined function runs its instructions"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -806,7 +882,7 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -814,7 +890,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">(</span>test1<span class="Delimiter">))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'reply' stops executing the current function"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -824,13 +900,13 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">`((</span>test1</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test2<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>test2</span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>test1<span class="Delimiter">))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">2</span> <span class="Constant">34</span> <span class="Constant">3</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">2</span> <span class="Constant">34</span> <span class="Constant">3</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'reply' stops executing any callers as necessary"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -839,7 +915,7 @@ a { color:#4444ff; } <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -853,10 +929,10 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-sequential"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -865,7 +941,7 @@ a { color:#4444ff; } <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Comment">; add-fn's temporaries</span> <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> <span class="Constant">3</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' accesses in order the operands of the most recent function call (the caller)"</span><span class="Delimiter">))</span> @@ -873,12 +949,13 @@ a { color:#4444ff; } <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-random-access"</span><span class="Delimiter">)</span> +<span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg <span class="Constant">1</span><span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg <span class="Constant">0</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span> <span class="Comment">; should never run</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -887,7 +964,7 @@ a { color:#4444ff; } <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Comment">; add-fn's temporaries</span> <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> <span class="Constant">3</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' with index can access function call arguments out of order"</span><span class="Delimiter">))</span> @@ -897,13 +974,13 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-status"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> t<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> t<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' sets a second oarg when arg exists"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -911,14 +988,14 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-missing"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - missing 'arg' doesn't cause error"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -926,14 +1003,14 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-missing-2"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">6</span> nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">6</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - missing 'arg' wipes second oarg when provided"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -941,49 +1018,61 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-missing-3"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">6</span> nil<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">6</span> nil<span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - missing 'arg' consistently wipes its oarg"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-missing-3"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-missing-4"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> <span class="Comment">; if given two args, adds them; if given one arg, increments</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">(</span>break-if <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-if</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Error">}</span></span> + <span class="Error">}</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Delimiter">)))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> <span class="Constant">1</span> <span class="Constant">6</span> nil <span class="Constant">7</span> <span class="Constant">35</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">4</span> <span class="Constant">34</span> <span class="Constant">5</span> <span class="Constant">1</span> <span class="Constant">6</span> nil <span class="Constant">7</span> <span class="Constant">35</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - function with optional second arg"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> -<span class="Comment">; how should errors be handled? will be unclear until we support concurrency and routine trees.</span> +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-arg-by-value"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>test1</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">0</span> literal<span class="Delimiter">))</span> <span class="Comment">; overwrite caller memory</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">))</span> <span class="Comment">; arg not clobbered</span></span> + <span class="Mu"><span class="Delimiter">(</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span>test1 <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">0</span> <span class="Constant">2</span> <span class="Constant">34</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'arg' passes by value"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-reply-oarg"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -991,7 +1080,7 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test1 <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Comment">; add-fn's temporaries</span> <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> <span class="Constant">3</span> <span class="Constant">6</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'reply' can take aguments that are returned, or written back into output args of caller"</span><span class="Delimiter">))</span> @@ -1000,10 +1089,10 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-reply-oarg-multiple"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> @@ -1011,11 +1100,32 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">7</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test1 <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Constant">7</span> <span class="Constant">3</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Constant">7</span> <span class="Constant">3</span> <span class="Comment">; add-fn's temporaries</span> <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> <span class="Constant">3</span> <span class="Constant">6</span> <span class="Constant">4</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - 'reply' permits a function to return multiple values at once"</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-fn-prepare-reply"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>test1</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span>prepare-reply <span class="Delimiter">(</span><span class="Constant">6</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">1</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">7</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test1 <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">1</span> <span class="Constant">2</span> <span class="Constant">3</span> <span class="Constant">3</span> <span class="Constant">4</span> <span class="Constant">7</span> <span class="Constant">3</span> + <span class="Comment">; add-fn's temporaries</span> + <span class="Constant">4</span> <span class="Constant">1</span> <span class="Constant">5</span> <span class="Constant">3</span> <span class="Constant">6</span> <span class="Constant">4</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - without args, 'reply' returns values from previous 'prepare-reply'."</span><span class="Delimiter">))</span> + <span class="Comment">; Our control operators are quite inconvenient to use, so mu provides a</span> <span class="Comment">; lightweight tool called 'convert-braces' to work in a slightly more</span> <span class="Comment">; convenient format with nested braces:</span> @@ -1042,19 +1152,19 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">{</span> begin <span class="Comment">; 'begin' is just a hack because racket turns curlies into parens</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> + <span class="Error">}</span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-braces replaces break-if with a jump-if to after the next close curly"</span><span class="Delimiter">))</span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-braces replaces break-if with a jump-if to after the next close-curly"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"convert-braces-empty-block"</span><span class="Delimiter">)</span> @@ -1063,14 +1173,14 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">(</span>break<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break</span><span class="Delimiter">)</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-braces works for degenerate blocks"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -1079,21 +1189,21 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Error">{</span> begin</span> + <span class="Mu"><span class="Mu"><span class="Error">{</span> begin</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">{</span> begin</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">1</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-braces balances curlies when converting break"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -1106,17 +1216,17 @@ a { color:#4444ff; } <span class="Mu"><span class="Error">{</span> begin</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>continue-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span></span> + <span class="Delimiter">(</span><span class="Identifier">continue-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">))</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">3</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>jump-if <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">-3</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">jump-if</span> <span class="Delimiter">(</span><span class="Constant">4</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">-3</span> offset<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">)))</span></span> <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-braces balances curlies when converting continue"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -1129,15 +1239,15 @@ a { color:#4444ff; } <span class="Mu"><span class="Error">{</span> begin</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>continue-if <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">continue-if</span> <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">))))</span></span> <span class="CommentedCode">;? (each stmt function*!main</span> <span class="CommentedCode">;? (prn stmt))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - continue correctly loops"</span><span class="Delimiter">))</span> <span class="Comment">; todo: fuzz-test invariant: convert-braces offsets should be robust to any</span> @@ -1155,15 +1265,15 @@ a { color:#4444ff; } <span class="Mu"><span class="Error">{</span> begin</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>continue-if <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">continue-if</span> <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">))))</span></span> <span class="CommentedCode">;? (each stmt function*!main</span> <span class="CommentedCode">;? (prn stmt))</span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - continue correctly loops"</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> @@ -1177,40 +1287,242 @@ a { color:#4444ff; } <span class="Mu"><span class="Error">{</span> begin</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> neq <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>continue-if <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">continue-if</span> <span class="Delimiter">(</span><span class="Constant">3</span> boolean<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span><span class="Delimiter">))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">4</span> <span class="Constant">2</span> <span class="Constant">4</span> <span class="Constant">3</span> nil <span class="Constant">4</span> <span class="Constant">34</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - continue might never trigger"</span><span class="Delimiter">))</span> -<span class="Comment">; using tagged-values you can define generic functions that run different code</span> -<span class="Comment">; based on the types of their args.</span> +<span class="Comment">; A big convenience high-level languages provide is the ability to name memory</span> +<span class="Comment">; locations. In mu, a lightweight tool called 'convert-names' provides this</span> +<span class="Comment">; convenience.</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"convert-names"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Delimiter">(</span>convert-names + <span class="Mu"><span class="Delimiter">'(((</span>x integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>y integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>z integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>x integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>y integer<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-names renames symbolic names to integer locations"</span><span class="Delimiter">))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"convert-names-nil"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Delimiter">(</span>convert-names + <span class="Mu"><span class="Delimiter">'(((</span>x integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>y integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>nil integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>x integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>y integer<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>nil integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-names never renames nil"</span><span class="Delimiter">))</span> + +<span class="Comment">; A rudimentary memory allocator. Eventually we want to write this in mu.</span> +<span class="Comment">;</span> +<span class="Comment">; No deallocation yet; let's see how much code we can build in mu before we</span> +<span class="Comment">; feel the need for it.</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-primitive"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>integer literal<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span><span class="Constant">.1</span> before<span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' returns current high-water mark"</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">1</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive types increments high-water mark by their size"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-array-literal"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> type-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>type-array literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span><span class="Constant">.1</span> before<span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on array with literal size returns current high-water mark"</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">6</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive arrays increments high-water mark by their size"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"new-array-direct"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> type-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>type-array literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span><span class="Constant">.2</span> before<span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on array with variable size returns current high-water mark"</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">6</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive arrays increments high-water mark by their (variable) size"</span><span class="Delimiter">)))</span> + +<span class="Comment">; Even though our memory locations can now have names, the names are all</span> +<span class="Comment">; globals, accessible from any function. To isolate functions from their</span> +<span class="Comment">; callers we need local variables, and mu provides them using a special</span> +<span class="Comment">; variable called default-scope. When you initialize such a variable (likely</span> +<span class="Comment">; with a call to our just-defined memory allocator) mu interprets memory</span> +<span class="Comment">; locations as offsets from its value. If default-scope is set to 1000, for</span> +<span class="Comment">; example, reads and writes to memory location 1 will really go to 1001.</span> +<span class="Comment">;</span> +<span class="Comment">; 'default-scope' is itself hard-coded to be function-local; it's nil in a new</span> +<span class="Comment">; function, and it's restored when functions return to their callers. But the</span> +<span class="Comment">; actual scope allocation is independent. So you can define closures, or do</span> +<span class="Comment">; even more funky things like share locals between two coroutines.</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"set-default-scope"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until +<span class="CommentedCode">;? (set dump-trace*)</span> + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~and <span class="Delimiter">(</span>~is <span class="Constant">23</span> <span class="Global">memory*</span><span class="Constant">.1</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>is <span class="Constant">23</span> <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">1</span><span class="Delimiter">))))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - default-scope implicitly modifies variable locations"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"set-default-scope-skips-offset"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> offset<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until +<span class="CommentedCode">;? (set dump-trace*)</span> + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~and <span class="Delimiter">(</span>~is <span class="Constant">23</span> <span class="Global">memory*</span><span class="Constant">.1</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>is <span class="Constant">23</span> <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">1</span><span class="Delimiter">))))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - default-scope skips 'offset' types just like literals"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"default-scope-bounds-check"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (set dump-trace*)</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">let</span> last-routine <span class="Delimiter">(</span>deq <span class="Global">completed-routines*</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>no rep.last-routine!error<span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - default-scope checks bounds"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"default-scope-and-get-indirect"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-boolean-pair-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>integer-boolean-pair literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> get-address <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer global<span class="Delimiter">)</span> <span class="Op"><-</span> get <span class="Delimiter">(</span><span class="Constant">1</span> integer-boolean-pair-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">0</span> offset<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="CommentedCode">;? (prn (as cons completed-routines*))</span> +<span class="Delimiter">(</span><span class="Normal">let</span> last-routine <span class="Delimiter">(</span>deq <span class="Global">completed-routines*</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>aif rep.last-routine!error <span class="Delimiter">(</span>prn <span class="Constant">"error - "</span> it<span class="Delimiter">)))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Constant">34</span> <span class="Global">memory*</span><span class="Constant">.3</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - indirect 'get' works in the presence of default-scope"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"default-scope-and-index-indirect"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>integer-array literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> index-address <span class="Delimiter">(</span><span class="Constant">1</span> integer-array-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> offset<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer-address deref<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer global<span class="Delimiter">)</span> <span class="Op"><-</span> index <span class="Delimiter">(</span><span class="Constant">1</span> integer-array-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> offset<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "cvt0" "cvt1")))</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="CommentedCode">;? (prn (as cons completed-routines*))</span> +<span class="Delimiter">(</span><span class="Normal">let</span> last-routine <span class="Delimiter">(</span>deq <span class="Global">completed-routines*</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>aif rep.last-routine!error <span class="Delimiter">(</span>prn <span class="Constant">"error - "</span> it<span class="Delimiter">)))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Constant">34</span> <span class="Global">memory*</span><span class="Constant">.3</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - indirect 'index' works in the presence of default-scope"</span><span class="Delimiter">))</span> +<span class="CommentedCode">;? (quit)</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"convert-names-default-scope"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Delimiter">(</span>convert-names + <span class="Mu"><span class="Delimiter">'(((</span>x integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>y integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Comment">; unsafe in general; don't write random values to 'default-scope'</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>x integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>y integer<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>default-scope integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> integer<span class="Delimiter">))))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-names never renames default-scope"</span><span class="Delimiter">))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"suppress-default-scope"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer global<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">)))))</span></span> +<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until +<span class="CommentedCode">;? (set dump-trace*)</span> + <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~and <span class="Delimiter">(</span>is <span class="Constant">23</span> <span class="Global">memory*</span><span class="Constant">.1</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span>~is <span class="Constant">23</span> <span class="Delimiter">(</span><span class="Global">memory*</span> <span class="Delimiter">(</span><span class="Identifier">+</span> before <span class="Constant">1</span><span class="Delimiter">))))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - default-scope skipped for locations with metadata 'global'"</span><span class="Delimiter">)))</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"convert-names-global"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Delimiter">(</span>convert-names + <span class="Mu"><span class="Delimiter">'(((</span>x integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>y integer global<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>default-scope integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>x integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>y integer global<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>y integer global<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>default-scope integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>y integer global<span class="Delimiter">))))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-names never renames global operands"</span><span class="Delimiter">))</span> + +<span class="Comment">; Putting it all together, here's how you define generic functions that run</span> +<span class="Comment">; different code based on the types of their args.</span> <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Delimiter">(</span>new-trace <span class="Constant">"dispatch-clause"</span><span class="Delimiter">)</span> <span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>add-fns - <span class="Delimiter">'((</span>test1 - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">'((</span>test1</span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">20</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Comment">; if given integers, add them</span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">4</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-unless <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">8</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">9</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>first-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-unless</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg integer<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>second-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>result integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>second-arg integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span>result integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>integer literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">34</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>integer literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">3</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test1 <span class="Delimiter">(</span><span class="Constant">1</span> tagged-value-address<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.3 <span class="Constant">37</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.3</span> <span class="Constant">37</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - an example function that checks that its oarg is an integer"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -1221,24 +1533,27 @@ a { color:#4444ff; } <span class="CommentedCode">;? (set dump-trace*)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">20</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Comment">; if given integers, add them</span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">4</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-unless <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">8</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">9</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>first-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-unless</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg integer<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>second-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>result integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>second-arg integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span>result integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> + <span class="Comment">; if given booleans, or them (it's a silly kind of generic function)</span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">4</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-unless <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> or <span class="Delimiter">(</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">8</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>first-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-unless</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>second-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>result boolean<span class="Delimiter">)</span> <span class="Op"><-</span> or <span class="Delimiter">(</span>first-arg boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span>second-arg boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span>result integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>boolean literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>boolean literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> @@ -1248,7 +1563,7 @@ a { color:#4444ff; } <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (wipe dump-trace*)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is memory*.3 t<span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~is <span class="Global">memory*</span><span class="Constant">.3</span> t<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - an example function that can do different things (dispatch) based on the type of its args or oargs"</span><span class="Delimiter">))</span> <span class="CommentedCode">;? (quit)</span> @@ -1256,24 +1571,27 @@ a { color:#4444ff; } <span class="Delimiter">(</span>new-trace <span class="Constant">"dispatch-multiple-calls"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span>add-fns <span class="Mu"><span class="Delimiter">'((</span>test1</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>default-scope scope-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>scope literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">20</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Comment">; if given integers, add them</span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">4</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-unless <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span><span class="Constant">5</span> integer<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">8</span> integer<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">9</span> integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>first-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-unless</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg integer<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>second-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>integer literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>result integer<span class="Delimiter">)</span> <span class="Op"><-</span> add <span class="Delimiter">(</span>first-arg integer<span class="Delimiter">)</span> <span class="Delimiter">(</span>second-arg integer<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span>result integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> + <span class="Comment">; if given booleans, or them (it's a silly kind of generic function)</span> <span class="Mu"><span class="Error">{</span> begin</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">4</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>break-unless <span class="Delimiter">(</span><span class="Constant">6</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">7</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> arg<span class="Delimiter">)</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">8</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span><span class="Constant">7</span> tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">9</span> boolean<span class="Delimiter">)</span> <span class="Op"><-</span> or <span class="Delimiter">(</span><span class="Constant">5</span> boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">8</span> boolean<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="Constant">9</span> boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>first-arg boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>first-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">break-unless</span> <span class="Delimiter">(</span>match? boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg-box tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> <span class="Identifier">arg</span><span class="Delimiter">)</span></span> + <span class="Mu"><span class="Delimiter">((</span>second-arg boolean<span class="Delimiter">)</span> <span class="Op"><-</span> maybe-coerce <span class="Delimiter">(</span>second-arg-box tagged-value-address deref<span class="Delimiter">)</span> <span class="Delimiter">(</span>boolean literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span>result boolean<span class="Delimiter">)</span> <span class="Op"><-</span> or <span class="Delimiter">(</span>first-arg boolean<span class="Delimiter">)</span> <span class="Delimiter">(</span>second-arg boolean<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span>result integer<span class="Delimiter">))</span></span> <span class="Mu"><span class="Error">}</span></span> - <span class="Mu"><span class="Delimiter">(</span>reply <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> + <span class="Mu"><span class="Delimiter">(</span><span class="Identifier">reply</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">)))</span></span> <span class="Mu"><span class="Delimiter">(</span>main</span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>boolean literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> tagged-value-address<span class="Delimiter">)</span> <span class="Op"><-</span> new-tagged-value <span class="Delimiter">(</span>boolean literal<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">t</span> literal<span class="Delimiter">))</span></span> @@ -1283,55 +1601,15 @@ a { color:#4444ff; } <span class="Mu"><span class="Delimiter">((</span><span class="Constant">12</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> test1 <span class="Delimiter">(</span><span class="Constant">10</span> tagged-value-address<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">11</span> tagged-value-address<span class="Delimiter">)))))</span></span> <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> <span class="CommentedCode">;? (prn memory*)</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~and <span class="Delimiter">(</span>is memory*.3 t<span class="Delimiter">)</span> <span class="Delimiter">(</span>is memory*.12 <span class="Constant">37</span><span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~and <span class="Delimiter">(</span>is <span class="Global">memory*</span><span class="Constant">.3</span> t<span class="Delimiter">)</span> <span class="Delimiter">(</span>is <span class="Global">memory*</span><span class="Constant">.12</span> <span class="Constant">37</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - different calls can exercise different clauses of the same function"</span><span class="Delimiter">))</span> -<span class="Comment">; A rudimentary memory allocator. Eventually we want to write this in mu.</span> - -<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"new-primitive"</span><span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until - <span class="Delimiter">(</span>add-fns - <span class="Mu"><span class="Delimiter">'((</span>main</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>integer type<span class="Delimiter">)))))</span></span> - <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> - <span class="CommentedCode">;? (prn memory*)</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory*.1 before<span class="Delimiter">)</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' returns current high-water mark"</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span>+ before <span class="Constant">1</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive types increments high-water mark by their size"</span><span class="Delimiter">)))</span> - -<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"new-array-literal"</span><span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until - <span class="Delimiter">(</span>add-fns - <span class="Mu"><span class="Delimiter">'((</span>main</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> type-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>type-array type<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">)))))</span></span> - <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> - <span class="CommentedCode">;? (prn memory*)</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory*.1 before<span class="Delimiter">)</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on array with literal size returns current high-water mark"</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span>+ before <span class="Constant">6</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive arrays increments high-water mark by their size"</span><span class="Delimiter">)))</span> - -<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> -<span class="Delimiter">(</span>new-trace <span class="Constant">"new-array-direct"</span><span class="Delimiter">)</span> -<span class="Delimiter">(</span><span class="Normal">let</span> before Memory-in-use-until - <span class="Delimiter">(</span>add-fns - <span class="Mu"><span class="Delimiter">'((</span>main</span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))</span></span> - <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> type-array-address<span class="Delimiter">)</span> <span class="Op"><-</span> new <span class="Delimiter">(</span>type-array type<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">1</span> integer<span class="Delimiter">)))))</span></span> - <span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> - <span class="CommentedCode">;? (prn memory*)</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory*.2 before<span class="Delimiter">)</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on array with variable size returns current high-water mark"</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso Memory-in-use-until <span class="Delimiter">(</span>+ before <span class="Constant">6</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - 'new' on primitive arrays increments high-water mark by their (variable) size"</span><span class="Delimiter">)))</span> - <span class="Comment">; A rudimentary process scheduler. You can 'run' multiple functions at once,</span> <span class="Comment">; and they share the virtual processor.</span> +<span class="Comment">;</span> <span class="Comment">; There's also a 'fork' primitive to let functions create new threads of</span> -<span class="Comment">; execution.</span> +<span class="Comment">; execution (we call them routines).</span> +<span class="Comment">;</span> <span class="Comment">; Eventually we want to allow callers to influence how much of their CPU they</span> <span class="Comment">; give to their 'children', or to rescind a child's running privileges.</span> @@ -1345,8 +1623,8 @@ a { color:#4444ff; } <span class="Delimiter">(</span><span class="Normal">let</span> ninsts <span class="Delimiter">(</span>run <span class="Delimiter">'</span>f1 <span class="Delimiter">'</span>f2<span class="Delimiter">)</span> <span class="Delimiter">(</span>when <span class="Delimiter">(</span>~iso <span class="Constant">2</span> ninsts<span class="Delimiter">)</span> <span class="Delimiter">(</span>prn <span class="Constant">"F - scheduler didn't run the right number of instructions: "</span> ninsts<span class="Delimiter">)))</span> -<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso memory* <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">4</span><span class="Delimiter">))</span> - <span class="Delimiter">(</span>prn <span class="Constant">"F - scheduler runs multiple functions: "</span> memory*<span class="Delimiter">))</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Global">memory*</span> <span class="Delimiter">(</span>obj <span class="Constant">1</span> <span class="Constant">3</span> <span class="Constant">2</span> <span class="Constant">4</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - scheduler runs multiple functions: "</span> <span class="Global">memory*</span><span class="Delimiter">))</span> <span class="Delimiter">(</span>check-trace-contents <span class="Constant">"scheduler orders functions correctly"</span> <span class="Delimiter">'((</span><span class="Constant">"schedule"</span> <span class="Constant">"f1"</span><span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="Constant">"schedule"</span> <span class="Constant">"f2"</span><span class="Delimiter">)</span> @@ -1358,13 +1636,54 @@ a { color:#4444ff; } <span class="Delimiter">(</span><span class="Constant">"run"</span> <span class="Constant">"f2 0"</span><span class="Delimiter">)</span> <span class="Delimiter">))</span> -<span class="Comment">; The scheduler needs to keep track of the call stack for each thread.</span> +<span class="Comment">; The scheduler needs to keep track of the call stack for each routine.</span> <span class="Comment">; Eventually we'll want to save this information in mu's address space itself,</span> <span class="Comment">; along with the types array, the magic buffers for args and oargs, and so on.</span> <span class="Comment">;</span> <span class="Comment">; Eventually we want the right stack-management primitives to build delimited</span> <span class="Comment">; continuations in mu.</span> +<span class="Comment">; Routines can throw errors.</span> +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"array-bounds-check"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span>add-fns + <span class="Mu"><span class="Delimiter">'((</span>main</span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">23</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">24</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">4</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> index <span class="Delimiter">(</span><span class="Constant">1</span> integer-array<span class="Delimiter">)</span> <span class="Delimiter">(</span><span class="MuConstant">2</span> literal<span class="Delimiter">)))))</span></span> +<span class="CommentedCode">;? (set dump-trace*)</span> +<span class="Delimiter">(</span>run <span class="Delimiter">'</span>main<span class="Delimiter">)</span> +<span class="CommentedCode">;? (prn memory*)</span> +<span class="Delimiter">(</span><span class="Normal">let</span> last-routine <span class="Delimiter">(</span>deq <span class="Global">completed-routines*</span><span class="Delimiter">)</span> + <span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>no rep.last-routine!error<span class="Delimiter">)</span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - 'index' throws an error if out of bounds"</span><span class="Delimiter">)))</span> + +<span class="Comment">; Lightweight tools can also operate on quoted lists of statements surrounded</span> +<span class="Comment">; by square brackets. In the example below, we mimic Go's 'defer' keyword</span> +<span class="Comment">; using 'convert-quotes'. It lets us write code anywhere in a function, but</span> +<span class="Comment">; have it run just before the function exits. Great for keeping code to</span> +<span class="Comment">; reclaim memory or other resources close to the code to allocate it. (C++</span> +<span class="Comment">; programmers know this as RAII.) We'll use 'defer' when we build a memory</span> +<span class="Comment">; deallocation routine like C's 'free'.</span> +<span class="Comment">;</span> +<span class="Comment">; More powerful reorderings are also possible like in Literate Programming or</span> +<span class="Comment">; Aspect-Oriented Programming; one advantage of prohibiting arbitrarily nested</span> +<span class="Comment">; code is that we can naturally name 'join points' wherever we want.</span> + +<span class="Delimiter">(</span>reset<span class="Delimiter">)</span> +<span class="Delimiter">(</span>new-trace <span class="Constant">"convert-quotes-defer"</span><span class="Delimiter">)</span> +<span class="Delimiter">(</span><span class="Normal">if</span> <span class="Delimiter">(</span>~iso <span class="Delimiter">(</span>convert-quotes + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">(</span>defer <span class="Delimiter">[</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">6</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">])</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))))</span></span> + <span class="Mu"><span class="Delimiter">'(((</span><span class="Constant">1</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">4</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">2</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">5</span> literal<span class="Delimiter">))</span></span> + <span class="Mu"><span class="Delimiter">((</span><span class="Constant">3</span> integer<span class="Delimiter">)</span> <span class="Op"><-</span> copy <span class="Delimiter">(</span><span class="MuConstant">6</span> literal<span class="Delimiter">))))</span></span> + <span class="Delimiter">(</span>prn <span class="Constant">"F - convert-quotes can handle 'defer'"</span><span class="Delimiter">))</span> + <span class="Delimiter">(</span>reset<span class="Delimiter">)</span> <span class="Comment">; end file with this to persist the trace for the final test</span> </pre> </body> |