# Some tokenization primitives. == code # instruction effective address register displacement immediate # . op subop mod rm32 base index scale r32 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes # extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary) # on reaching end of file, return an empty interval next-token: # in: (addr stream byte), delimiter: byte, out: (addr slice) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 51/push-ecx 56/push-esi 57/push-edi # esi = in 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # edi = out 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0x10/disp8 . # copy *(ebp+16) to edi # skip-chars-matching(in, delimiter) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) 56/push-esi # . . call e8/call skip-chars-matching/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # out->start = &in->data[in->read] 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 . # copy esi+ecx+12 to eax 89/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # copy eax to *edi # skip-chars-not-matching(in, delimiter) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) 56/push-esi # . . call e8/call skip-chars-not-matching/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # out->end = &in->data[in->read] 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/eax 0xc/disp8 . # copy esi+ecx+12 to eax 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 . # copy eax to *(edi+4) # . restore registers 5f/pop-to-edi 5e/pop-to-esi 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-token: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # var slice/ecx: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # write(_test-stream, " ab") # . . push args 68/push " ab"/imm32 68/push _test-stream/imm32 # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # next-token(_test-stream, 0x20/space, slice) # . . push args 51/push-ecx 68/push 0x20/imm32 68/push _test-stream/imm32 # . . call e8/call next-token/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(slice->start - _test-stream->data, 2, msg) # . check-ints-equal(slice->start - _test-stream, 14, msg) # . . push args 68/push "F - test-next-token: start"/imm32 68/push 0xe/imm32 # . . push slice->start - _test-stream 8b/copy 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . . # copy *ecx to eax 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32 # subtract from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(slice->end - _test-stream->data, 4, msg) # . check-ints-equal(slice->end - _test-stream, 16, msg) # . . push args 68/push "F - test-next-token: end"/imm32 68/push 0x10/imm32 # . . push slice->end - _test-stream 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 4/disp8 . # copy *(ecx+4) to eax 81 5/subop/subtract 3/mod/direct 0/rm32/eax . . . . . _test-stream/imm32 # subtract from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-token-Eof: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # var slice/ecx: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # write nothing to _test-stream # next-token(_test-stream, 0x20/space, slice) # . . push args 51/push-ecx 68/push 0x20/imm32 68/push _test-stream/imm32 # . . call e8/call next-token/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(slice->end, slice->start, msg) # . . push args 68/push "F - test-next-token-Eof"/imm32 ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 . # push *(ecx+4) ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary) # on reaching end of file, return an empty interval next-token-from-slice: # start: (addr byte), end: (addr byte), delimiter: byte, out: (addr slice) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 51/push-ecx 52/push-edx 57/push-edi # ecx = end 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0xc/disp8 . # copy *(ebp+12) to ecx # edx = delimiter 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0x10/disp8 . # copy *(ebp+16) to edx # edi = out 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0x14/disp8 . # copy *(ebp+20) to edi # eax = skip-chars-matching-in-slice(start, end, delimiter) # . . push args 52/push-edx 51/push-ecx ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call skip-chars-matching-in-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # out->start = eax 89/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # copy eax to *edi # eax = skip-chars-not-matching-in-slice(eax, end, delimiter) # . . push args 52/push-edx 51/push-ecx 50/push-eax # . . call e8/call skip-chars-not-matching-in-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # out->end = eax 89/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 4/disp8 . # copy eax to *(edi+4) # . restore registers 5f/pop-to-edi 5a/pop-to-edx 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-token-from-slice: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # (eax..ecx) = " ab" b8/copy-to-eax " ab"/imm32 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . . # copy *eax to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 . # copy eax+ecx+4 to ecx 05/add-to-eax 4/imm32 # var out/edi: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . . # copy esp to edi # next-token-from-slice(eax, ecx, 0x20/space, out) # . . push args 57/push-edi 68/push 0x20/imm32 51/push-ecx 50/push-eax # . . call e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # out->start should be at the 'a' # . check-ints-equal(out->start - in->start, 2, msg) # . . push args 68/push "F - test-next-token-from-slice: start"/imm32 68/push 2/imm32 # . . push out->start - in->start 8b/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . . # copy *edi to ecx 2b/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract eax from ecx 51/push-ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # out->end should be after the 'b' # check-ints-equal(out->end - in->start, 4, msg) # . . push args 68/push "F - test-next-token-from-slice: end"/imm32 68/push 4/imm32 # . . push out->end - in->start 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 1/r32/ecx 4/disp8 . # copy *(edi+4) to ecx 2b/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract eax from ecx 51/push-ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-token-from-slice-Eof: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # var out/edi: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . . # copy esp to edi # next-token-from-slice(0, 0, 0x20/space, out) # . . push args 57/push-edi 68/push 0x20/imm32 68/push 0/imm32 68/push 0/imm32 # . . call e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # out should be empty # . check-ints-equal(out->end - out->start, 0, msg) # . . push args 68/push "F - test-next-token-from-slice-Eof"/imm32 68/push 0/imm32 # . . push out->start - in->start 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 1/r32/ecx 4/disp8 . # copy *(edi+4) to ecx 2b/subtract 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . . # subtract *edi from ecx 51/push-ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-next-token-from-slice-nothing: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # (eax..ecx) = " " b8/copy-to-eax " "/imm32 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . . # copy *eax to ecx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 . # copy eax+ecx+4 to ecx 05/add-to-eax 4/imm32 # var out/edi: slice 68/push 0/imm32/end 68/push 0/imm32/start 89/copy 3/mod/direct 7/rm32/edi . . . 4/r32/esp . . # copy esp to edi # next-token-from-slice(in, 0x20/space, out) # . . push args 57/push-edi 68/push 0x20/imm32 51/push-ecx 50/push-eax # . . call e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . .
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 074deep_copy.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.Special { color: #c00000; }
.muRecipe { color: #ff8700; }
.cSpecial { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.LineNr { color: #444444; }
.traceContains { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.muData { color: #ffff00; }
.Identifier { color: #c0a020; }
-->
</style>

<script type='text/javascript'>
<!--

/* function to open any folds containing a jumped-to line before jumping to it */
function JumpToLine()
{
  var lineNum;
  lineNum = window.location.hash;
  lineNum = lineNum.substr(1); /* strip off '#' */

  if (lineNum.indexOf('L') == -1) {
    lineNum = 'L'+lineNum;
  }
  lineElem = document.getElementById(lineNum);
  /* Always jump to new location even if the line was hidden inside a fold, or
   * we corrected the raw number to a line ID.
   */
  if (lineElem) {
    lineElem.scrollIntoView(true);
  }
  return true;
}
if ('onhashchange' in window) {
  window.onhashchange = JumpToLine;
}

-->
</script>
</head>
<body onload='JumpToLine();'>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr">  1 </span><span class="Comment">// To recursively copy containers and any addresses they contain, use</span>
<span id="L2" class="LineNr">  2 </span><span class="Comment">// 'deep-copy'.</span>
<span id="L3" class="LineNr">  3 </span><span class="Comment">//</span>
<span id="L4" class="LineNr">  4 </span><span class="Comment">// Invariant: After a deep-copy its ingredient and result will point to no</span>
<span id="L5" class="LineNr">  5 </span><span class="Comment">// common addresses.</span>
<span id="L6" class="LineNr">  6 </span><span class="Comment">// Implications: Refcounts of all data pointed to by the original ingredient</span>
<span id="L7" class="LineNr">  7 </span><span class="Comment">// will remain unchanged. Refcounts of all data pointed to by the (newly</span>
<span id="L8" class="LineNr">  8 </span><span class="Comment">// created) result will be 1, in the absence of cycles.</span>
<span id="L9" class="LineNr">  9 </span><span class="Comment">//</span>
<span id="L10" class="LineNr"> 10 </span><span class="Comment">// We do handle cycles in the ingredient, however. All cycles are translated</span>
<span id="L11" class="LineNr"> 11 </span><span class="Comment">// to new cycles in the product.</span>
<span id="L12" class="LineNr"> 12 </span>
<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(scenario deep_copy_number)</span>
<span id="L14" class="LineNr"> 14 </span><span class="muRecipe">def</span> main [
<span id="L15" class="LineNr"> 15 </span>  local-scope
<span id="L16" class="LineNr"> 16 </span>  <span class="Normal">x</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
<span id="L17" class="LineNr"> 17 </span>  <span class="Normal">y</span>:num<span class="Special"> &lt;- </span>deep-copy x
<span id="L18" class="LineNr"> 18 </span>  <span class="Constant">10</span>:<span class="Normal">bool</span>/<span class="Special">raw &lt;- </span>equal x<span class="Delimiter">,</span> y
<span id="L19" class="LineNr"> 19 </span>]
<span id="L20" class="LineNr"> 20 </span><span class="Comment"># non-address primitives are identical</span>
<span id="L21" class="LineNr"> 21 </span><span class="traceContains">+mem: storing 1 in location 10</span>
<span id="L22" class="LineNr"> 22 </span>
<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(scenario deep_copy_container_without_address)</span>
<span id="L24" class="LineNr"> 24 </span><span class="muData">container</span> foo [
<span id="L25" class="LineNr"> 25 </span>  <span class="Normal">x</span>:num
<span id="L26" class="LineNr"> 26 </span>  <span class="Normal">y</span>:num
<span id="L27" class="LineNr"> 27 </span>]
<span id="L28" class="LineNr"> 28 </span><span class="muRecipe">def</span> main [
<span id="L29" class="LineNr"> 29 </span>  local-scope
<span id="L30" class="LineNr"> 30 </span>  <span class="Normal">a</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
<span id="L31" class="LineNr"> 31 </span>  <span class="Normal">b</span>:foo<span class="Special"> &lt;- </span>deep-copy a
<span id="L32" class="LineNr"> 32 </span>  <span class="Constant">10</span>:<span class="Normal">bool</span>/<span class="Special">raw &lt;- </span>equal a<span class="Delimiter">,</span> b
<span id="L33" class="LineNr"> 33 </span>]
<span id="L34" class="LineNr"> 34 </span><span class="Comment"># containers are identical as long as they don't contain addresses</span>
<span id="L35" class="LineNr"> 35 </span><span class="traceContains">+mem: storing 1 in location 10</span>
<span id="L36" class="LineNr"> 36 </span>
<span id="L37" class="LineNr"> 37 </span><span class="Delimiter">:(scenario deep_copy_address)</span>
<span id="L38" class="LineNr"> 38 </span><span class="Special">% Memory_allocated_until = 200;</span>
<span id="L39" class="LineNr"> 39 </span><span class="muRecipe">def</span> main [
<span id="L40" class="LineNr"> 40 </span>  <span class="Comment"># avoid all memory allocations except the implicit ones inside deep-copy, so</span>
<span id="L41" class="LineNr"> 41 </span>  <span class="Comment"># that the result is deterministic</span>
<span id="L42" class="LineNr"> 42 </span>  <span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">100</span>/unsafe  <span class="Comment"># pretend allocation</span>
<span id="L43" class="LineNr"> 43 </span>  *<span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
<span id="L44" class="LineNr"> 44 </span>  <span class="Constant">2</span>:&amp;:num<span class="Special"> &lt;- </span>deep-copy <span class="Constant">1</span>:&amp;:num
<span id="L45" class="LineNr"> 45 </span>  <span class="Constant">10</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">1</span>:&amp;:num<span class="Delimiter">,</span> <span class="Constant">2</span>:&amp;:num
<span id="L46" class="LineNr"> 46 </span>  <span class="Constant">11</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal *<span class="Constant">1</span>:&amp;:num<span class="Delimiter">,</span> *<span class="Constant">2</span>:&amp;:num
<span id="L47" class="LineNr"> 47 </span>  <span class="Constant">2</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
<span id="L48" class="LineNr"> 48 </span>]
<span id="L49" class="LineNr"> 49 </span><span class="Comment"># the result of deep-copy is a new address</span>
<span id="L50" class="LineNr"> 50 </span><span class="traceContains">+mem: storing 0 in location 10</span>
<span id="L51" class="LineNr"> 51 </span><span class="Comment"># however, the contents are identical</span>
<span id="L52" class="LineNr"> 52 </span><span class="traceContains">+mem: storing 1 in location 11</span>
<span id="L53" class="LineNr"> 53 </span><span class="Comment"># the result of deep-copy gets a refcount of 1</span>
<span id="L54" class="LineNr"> 54 </span><span class="Comment"># (its address 202 = 200 base + 2 for temporary space inside deep-copy)</span>
<span id="L55" class="LineNr"> 55 </span><span class="traceContains">+run: {2: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span id="L56" class="LineNr"> 56 </span><span class="traceContains">+mem: decrementing refcount of 202: 1 -&gt; 0</span>
<span id="L57" class="LineNr"> 57 </span><span class="traceContains">+abandon: saving 202 in free-list of size 2</span>
<span id="L58" class="LineNr"> 58 </span>
<span id="L59" class="LineNr"> 59 </span><span class="Delimiter">:(scenario deep_copy_address_to_container)</span>
<span id="L60" class="LineNr"> 60 </span><span class="Special">% Memory_allocated_until = 200;</span>
<span id="L61" class="LineNr"> 61 </span><span class="muRecipe">def</span> main [
<span id="L62" class="LineNr"> 62 </span>  <span class="Comment"># avoid all memory allocations except the implicit ones inside deep-copy, so</span>
<span id="L63" class="LineNr"> 63 </span>  <span class="Comment"># that the result is deterministic</span>
<span id="L64" class="LineNr"> 64 </span>  <span class="Constant">1</span>:&amp;:point<span class="Special"> &lt;- </span>copy <span class="Constant">100</span>/unsafe  <span class="Comment"># pretend allocation</span>
<span id="L65" class="LineNr"> 65 </span>  *<span class="Constant">1</span>:&amp;:point<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
<span id="L66" class="LineNr"> 66 </span>  <span class="Constant">2</span>:&amp;:point<span class="Special"> &lt;- </span>deep-copy <span class="Constant">1</span>:&amp;:point
<span id="L67" class="LineNr"> 67 </span>  <span class="Constant">10</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">1</span>:&amp;:point<span class="Delimiter">,</span> <span class="Constant">2</span>:&amp;:point
<span id="L68" class="LineNr"> 68 </span>  <span class="Constant">11</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal *<span class="Constant">1</span>:&amp;:point<span class="Delimiter">,</span> *<span class="Constant">2</span>:&amp;:point
<span id="L69" class="LineNr"> 69 </span>]
<span id="L70" class="LineNr"> 70 </span><span class="Comment"># the result of deep-copy is a new address</span>
<span id="L71" class="LineNr"> 71 </span><span class="traceContains">+mem: storing 0 in location 10</span>
<span id="L72" class="LineNr"> 72 </span><span class="Comment"># however, the contents are identical</span>
<span id="L73" class="LineNr"> 73 </span><span class="traceContains">+mem: storing 1 in location 11</span>
<span id="L74" class="LineNr"> 74 </span>
<span id="L75" class="LineNr"> 75 </span><span class="Delimiter">:(scenario deep_copy_address_to_address)</span>
<span id="L76" class="LineNr"> 76 </span><span class="Special">% Memory_allocated_until = 200;</span>
<span id="L77" class="LineNr"> 77 </span><span class="muRecipe">def</span> main [
<span id="L78" class="LineNr"> 78 </span>  <span class="Comment"># avoid all memory allocations except the implicit ones inside deep-copy, so</span>
<span id="L79" class="LineNr"> 79 </span>  <span class="Comment"># that the result is deterministic</span>
<span id="L80" class="LineNr"> 80 </span>  <span class="Constant">1</span>:&amp;:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">100</span>/unsafe  <span class="Comment"># pretend allocation</span>
<span id="L81" class="LineNr"> 81 </span>  *<span class="Constant">1</span>:&amp;:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">150</span>/unsafe
<span id="L82" class="LineNr"> 82 </span>  **<span class="Constant">1</span>:&amp;:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
<span id="L83" class="LineNr"> 83 </span>  <span class="Constant">2</span>:&amp;:&amp;:num<span class="Special"> &lt;- </span>deep-copy <span class="Constant">1</span>:&amp;:&amp;:num
<span id="L84" class="LineNr"> 84 </span>  <span class="Constant">10</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">1</span>:&amp;:&amp;:num<span class="Delimiter">,</span> <span class="Constant">2</span>:&amp;:&amp;:num
<span id="L85" class="LineNr"> 85 </span>  <span class="Constant">11</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal *<span class="Constant">1</span>:&amp;:&amp;:num<span class="Delimiter">,</span> *<span class="Constant">2</span>:&amp;:&amp;:num
<span id="L86" class="LineNr"> 86 </span>  <span class="Constant">12</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal **<span class="Constant">1</span>:&amp;:&amp;:num<span class="Delimiter">,</span> **<span class="Constant">2</span>:&amp;:&amp;:num
<span id="L87" class="LineNr"> 87 </span>]
<span id="L88" class="LineNr"> 88 </span><span class="Comment"># the result of deep-copy is a new address</span>
<span id="L89" class="LineNr"> 89 </span><span class="traceContains">+mem: storing 0 in location 10</span>
<span id="L90" class="LineNr"> 90 </span><span class="Comment"># any addresses in it or pointed to it are also new</span>
<span id="L91" class="LineNr"> 91 </span><span class="traceContains">+mem: storing 0 in location 11</span>
<span id="L92" class="LineNr"> 92 </span><span class="Comment"># however, the non-address contents are identical</span>
<span id="L93" class="LineNr"> 93 </span><span class="traceContains">+mem: storing 1 in location 12</span>
<span id="L94" class="LineNr"> 94 </span>
<span id="L95" class="LineNr"> 95 </span><span class="Delimiter">:(scenario deep_copy_array)</span>
<span id="L96" class="LineNr"> 96 </span><span class="Special">% Memory_allocated_until = 200;</span>
<span id="L97" class="LineNr"> 97 </span><span class="muRecipe">def</span> main [
<span id="L98" class="LineNr"> 98 </span>  <span class="Comment"># avoid all memory allocations except the implicit ones inside deep-copy, so</span>
<span id="L99" class="LineNr"> 99 </span>  <span class="Comment"># that the result is deterministic</span>
<span id="L100" class="LineNr">100 </span>  <span class="Constant">100</span>:num<span class="Special"> &lt;- </span>copy <span