159a683aebd3 — Leonard Ritter 3 months ago
* more work on typeschema
1 files changed, 42 insertions(+), 15 deletions(-)

M testing/test_typeschema2.sc
M testing/test_typeschema2.sc +42 -15
@@ 82,11 82,10 @@ struct UStore # content addressable stor
     # root address
     root : UPointer = (undef UPointer)
 
-    inline... @ (self, blob : UBlob, T : type)
-        @ ((& (self.memory @ blob.offset)) as @T)
-
-    fn... get (self, addr : UPointer)
-        'get self.map addr
+    inline... @ (self, addr : UPointer, T : type)
+        blob := ('get self.map addr)
+        ptr := (& (self.memory @ blob.offset))
+        @ (ptr as @T)
 
     fn... insert
     case (self, data : voidstar, size : usize)

          
@@ 108,6 107,10 @@ struct UStore # content addressable stor
                     size = size
                     offset = offset
             'set self.map addr blob
+            do
+                ptr := (& (self.memory @ blob.offset))
+                let revaddr = (UPointer.to ptr blob.size)
+                print "insert" addr revaddr
             _ addr blob
     case (self, str : string)
         this-function self (str as rawstring) (countof str)

          
@@ 130,16 133,22 @@ let ref-type-name = (intern-string "ref2
 let integer-type-name = (intern-string "integer")
 let real-type-name = (intern-string "real")
 
-type UPointerType <: ('packed tuple UPointer i32)
+inline verify-sizeof (size)
+    inline (T)
+        static-assert ((sizeof T) == size)
+            .. "(sizeof " (tostring T) ") != " (tostring size)
+        T
 
-type NumberType <: ('packed tuple UPointer i32)
-
-static-assert ((sizeof NumberType) == 36)
+#@@ verify-sizeof 36
+struct NumberType plain
+    name : UPointer
+    bitcount : i32
 
 fn... number-type (name : UPointer, bitcount : i32,)
-    let value =
-        NumberType name bitcount
-    _ ('insert module value) ()
+    _
+        'insert module
+            NumberType name bitcount
+        ;
 
 inline integer-type (bitcount)
     number-type integer-type-name bitcount

          
@@ 149,16 158,34 @@ inline real-type (bitcount)
 
 inline bitcountof (T)
     try
-        let ptr = ('@ module ('get module T) NumberType)
-        deref (ptr @ 1)
+        let ptr = ('@ module T NumberType)
+        deref ptr.bitcount
     else 0
 
 global i32-type = (integer-type 32)
 global f32-type = (real-type 32)
 
+#@@ verify-sizeof 64
+struct UPointerType plain
+    name : UPointer
+    element : UPointer
 
+fn... pointer-type (element : UPointer,)
+    _
+        'insert module
+            UPointerType ref-type-name element
+        ;
 
 print
+    integer-type 32
+    bitcountof
+        integer-type 32
+print
+    pointer-type
+        integer-type 32
+
+print
+    integer-type 32
     bitcountof
         integer-type 32
 print

          
@@ 306,7 333,7 @@ print
     local stack : (Array type)
     encode-schemastr stack T
 
-do
+#do
     let s = "Rosetta code"
     local k = (tupleof 1 2 3)
     let addr =