39915d8c09d5 — Leonard Ritter 11 days ago
* atom: `cell` and `blob` use FatArray by default
1 files changed, 25 insertions(+), 26 deletions(-)

M lib/scopes/compiler/atom.sc
M lib/scopes/compiler/atom.sc +25 -26
@@ 155,6 155,13 @@ type FatArray < Struct
             super-type.__typecall cls
                 keys = cls.ArrayType ...
 
+    @@ memo
+    inline __rimply (T cls)
+        static-if (T == cls.ArrayType)
+            inline (self)
+                super-type.__typecall cls
+                    keys = (move self)
+
     fn invalidate (self offset count)
         cls := typeof self
         x0 := offset // cls.Stride

          
@@ 237,6 244,9 @@ type FatArray < Struct
     inline append (self value)
         'append self.keys (autocopy value)
 
+    fn append-from-arrayptr (self ptr sz)
+        'append-from-arrayptr self.keys ptr sz
+
     inline updated? (self)
         (countof self.past) == (countof self.keys)
 

          
@@ 261,6 271,10 @@ type FatArray < Struct
             self.pastcount = keyscount
             ;
 
+    fn data (self offset)
+        viewing self
+        'data self.keys 0:usize
+
     inline indexof (self value)
         """"return the absolute last index of `value`
         copy ('getdefault self.map value NoIndex)

          
@@ 393,9 407,8 @@ type Slice < Struct
 
     inline wrap (cls arr)
         count := copy (countof arr)
-        data := Rc.wrap arr
         super-type.__typecall cls
-            data = data
+            data = arr
             offset = 0
             count = count
 

          
@@ 440,7 453,7 @@ type Slice < Struct
 
     inline... join (self, other : this-type)
         self := 'align self
-        'append-from-arrayptr self.data ('data other.data other.offset) other.count
+        'append-from-arrayptr self.data ('data other) other.count
         cls := typeof self
         super-type.__typecall cls
             data = copy self.data

          
@@ 678,7 691,8 @@ type+ SliceView
 
 ###############################
 
-Cell := Slice (Array Atom)
+Cell := Slice (FatArray (Array Atom) 1)
+#Cell := Slice (Array Atom)
 CellView := Cell.SliceViewType
 
 type+ Cell

          
@@ 722,7 736,8 @@ type+ CellView
 
 ###############################
 
-Blob := Slice String
+Blob := Slice (FatArray String 8)
+#Blob := Slice String
 BlobView := Blob.SliceViewType
 
 fn... blob-quotestr (x : String, start : usize, end : usize)

          
@@ 1090,6 1105,8 @@ inline listing (atom)
 
 ###############################
 
+run-stage;
+
 static-if main-module?
     using import testing .Printer
 

          
@@ 1127,27 1144,7 @@ static-if main-module?
         k += 1
     test (k == 4)
     do
-        cell := (SliceT)
-        cell := 'append cell "1"
-        cell := 'append cell "2"
-        cell := 'append cell "3"
-        cell := 'append cell "4"
-        cell := 'append cell "5"
-        cell := 'append cell "1"
-        cell := 'append cell "2"
-        cell := 'append cell "3"
-        cell := 'append cell "4"
-        cell := 'append cell "5"
-        cell := 'append cell "1"
-        cell := 'append cell "2"
-        cell := 'append cell "3"
-        cell := 'append cell "4"
-        cell := 'append cell "5"
-        cell := 'append cell "1"
-        cell := 'append cell "2"
-        cell := 'append cell "3"
-        cell := 'append cell "4"
-        cell := 'append cell "5"
+        cell := b"12345123451234512345"
 
         s5a := slice (copy cell) 0 5
         s5b := slice (copy cell) 5 10

          
@@ 1170,6 1167,8 @@ static-if main-module?
         print
             hash s10a
             hash s10b
+        test
+            (hash (copy cell)) == (hash (s10a .. s10b))
         #test
             ==
                 hash (slice (copy cell) 1 3)