78959be22604 — Leonard Ritter a month ago
* added copy to UAtom
1 files changed, 24 insertions(+), 12 deletions(-)

M testing/test_uvm3.sc
M testing/test_uvm3.sc +24 -12
@@ 273,6 273,10 @@ type UHashed < Struct
                 id = (cls.HashFunction data)
                 data = data
 
+    #fn __drop (self)
+        report "dropped"
+        ;
+
     fn __repr (self)
         viewing self
         .. "(" (tostring (typeof self)) " " (repr self.data) ")"

          
@@ 307,18 311,18 @@ type+ UAtom
     inline __typecall (cls value)
         imply value cls
 
+    fn wrap (ptr kind)
+        let origptr = ptr
+        let val = (ptrtoint ptr usize)
+        # no bits must be set
+        assert ((val & 0xf:usize) == 0:usize)
+        let ptr = (inttoptr (val | (kind as integer as usize)) voidstar)
+        let self = (dupe (bitcast ptr this-type))
+        lose origptr
+        self
+
     @@ memo
     inline __rimply (T cls)
-        fn wrap (ptr kind)
-            let origptr = ptr
-            let val = (ptrtoint ptr usize)
-            # no bits must be set
-            assert ((val & 0xf:usize) == 0:usize)
-            let ptr = (inttoptr (val | (kind as integer as usize)) voidstar)
-            let self = (dupe (bitcast ptr this-type))
-            lose origptr
-            self
-
         static-if (T == bool)
             inline (self)
                 wrap null

          
@@ 436,6 440,14 @@ type+ UAtom
             default "?"
             ")"
 
+    fn __copy (self)
+        viewing self
+        let ptr = (topointer self)
+        if (ptr != null)
+            wrap (copy (bitcast ptr (Rc voidstar))) ('kind self)
+        else
+            deref (dupe self)
+
     fn __drop (self)
         viewing self
         returning void

          
@@ 462,9 474,9 @@ do
 
     local digest = ('uhash val)
 
-    print ((UAtom true) != (UAtom true))
+    print ((UAtom 2) != (UAtom 2))
 
-    print val
+    let val2 = (copy val)
 
     dispatch val
     case Number (n)