about summary refs log tree commit diff stats
path: root/073deep_copy.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-06-29 13:57:40 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-06-29 13:57:40 -0700
commit21da851e5e75632d3d955c608451b6fced990184 (patch)
treef4dcaeabd69872dc8f1b950c29c23c1b139dc241 /073deep_copy.cc
parent872dd0018bdf023612db8aef6e3fef7c8ee0746b (diff)
downloadmu-21da851e5e75632d3d955c608451b6fced990184.tar.gz
3077
Diffstat (limited to '073deep_copy.cc')
-rw-r--r--073deep_copy.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/073deep_copy.cc b/073deep_copy.cc
index 685780f3..3fb17602 100644
--- a/073deep_copy.cc
+++ b/073deep_copy.cc
@@ -53,6 +53,31 @@ def main [
 +mem: decrementing refcount of 202: 1 -> 0
 +abandon: saving 202 in free-list of size 2
 
+:(scenario deep_copy_array)
+% Memory_allocated_until = 200;
+def main [
+  # avoid all memory allocations except the implicit ones inside deep-copy, so
+  # that the result is deterministic
+  100:number <- copy 1  # pretend refcount
+  101:number <- copy 3  # pretend array length
+  1:address:array:number <- copy 100/unsafe  # pretend allocation
+  put-index *1:address:array:number, 0, 34
+  put-index *1:address:array:number, 1, 35
+  put-index *1:address:array:number, 2, 36
+  stash [old:], *1:address:array:number
+  2:address:array:number <- deep-copy 1:address:array:number
+  stash 2:address:array:number
+  stash [new:], *2:address:array:number
+  10:boolean <- equal 1:address:array:number, 2:address:array:number
+  11:boolean <- equal *1:address:array:number, *2:address:array:number
+]
++app: old: 3 34 35 36
++app: new: 3 34 35 36
+# the result of deep-copy is a new address
++mem: storing 0 in location 10
+# however, the contents are identical
++mem: storing 1 in location 11
+
 :(before "End Primitive Recipe Declarations")
 DEEP_COPY,
 :(before "End Primitive Recipe Numbers")
@@ -85,7 +110,6 @@ vector<double> deep_copy(reagent/*copy*/ in, reagent& tmp) {
   map<int, int> addresses_copied;
   if (is_mu_address(in))
     result.push_back(deep_copy_address(in, addresses_copied, tmp));
-  // TODO: handle arrays
   else
     deep_copy(in, addresses_copied, result);
   return result;