]> gitweb.factorcode.org Git - factor.git/commitdiff
alien.structs: struct-type now has a class slot; fix specialized complex-float/double...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 9 Aug 2009 21:10:11 +0000 (16:10 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 9 Aug 2009 21:10:11 +0000 (16:10 -0500)
basis/alien/c-types/c-types.factor
basis/alien/complex/functor/functor.factor
basis/alien/structs/structs.factor
basis/math/vectors/specialization/specialization-tests.factor

index 3be2074056eb367b960cf46388f69dbb280913ac..7807113999a4f27de2f733d1d4a027921b91f74d 100755 (executable)
@@ -13,17 +13,19 @@ DEFER: *char
 
 : little-endian? ( -- ? ) 1 <int> *char 1 = ; foldable
 
-TUPLE: c-type
+TUPLE: abstract-c-type
 { class class initial: object }
-boxer
 { boxer-quot callable }
-unboxer
 { unboxer-quot callable }
 { getter callable }
 { setter callable }
-{ rep initial: int-rep }
 size
-align
+align ;
+
+TUPLE: c-type < abstract-c-type
+boxer
+unboxer
+{ rep initial: int-rep }
 stack-align? ;
 
 : <c-type> ( -- type )
@@ -70,7 +72,7 @@ M: string c-type ( name -- type )
 
 GENERIC: c-type-class ( name -- class )
 
-M: c-type c-type-class class>> ;
+M: abstract-c-type c-type-class class>> ;
 
 M: string c-type-class c-type c-type-class ;
 
@@ -82,7 +84,7 @@ M: string c-type-boxer c-type c-type-boxer ;
 
 GENERIC: c-type-boxer-quot ( name -- quot )
 
-M: c-type c-type-boxer-quot boxer-quot>> ;
+M: abstract-c-type c-type-boxer-quot boxer-quot>> ;
 
 M: string c-type-boxer-quot c-type c-type-boxer-quot ;
 
@@ -94,7 +96,7 @@ M: string c-type-unboxer c-type c-type-unboxer ;
 
 GENERIC: c-type-unboxer-quot ( name -- quot )
 
-M: c-type c-type-unboxer-quot unboxer-quot>> ;
+M: abstract-c-type c-type-unboxer-quot unboxer-quot>> ;
 
 M: string c-type-unboxer-quot c-type c-type-unboxer-quot ;
 
@@ -118,7 +120,7 @@ M: string c-type-setter c-type c-type-setter ;
 
 GENERIC: c-type-align ( name -- n )
 
-M: c-type c-type-align align>> ;
+M: abstract-c-type c-type-align align>> ;
 
 M: string c-type-align c-type c-type-align ;
 
@@ -167,7 +169,7 @@ GENERIC: heap-size ( type -- size ) foldable
 
 M: string heap-size c-type heap-size ;
 
-M: c-type heap-size size>> ;
+M: abstract-c-type heap-size size>> ;
 
 GENERIC: stack-size ( type -- size ) foldable
 
index fc9e594be57824f4cb3dbda092498b2f58ca7634..59bf3451b87cd70b23a6a06318114780ba763f21 100644 (file)
@@ -30,6 +30,7 @@ define-struct
 T c-type
 <T> 1quotation >>unboxer-quot
 *T 1quotation >>boxer-quot
+number >>class
 drop
 
 ;FUNCTOR
index b618e7974bc76cd9647f5fcd0f3f4a2c39f12616..4154ad1dd8f3aef9e1f3d1f7b967d2d1499b6f9e 100755 (executable)
@@ -6,30 +6,12 @@ alien.c-types alien.structs.fields cpu.architecture math.order
 quotations byte-arrays ;
 IN: alien.structs
 
-TUPLE: struct-type
-size
-align
-fields
-{ boxer-quot callable }
-{ unboxer-quot callable }
-{ getter callable }
-{ setter callable }
-return-in-registers? ;
+TUPLE: struct-type < abstract-c-type fields return-in-registers? ;
 
 M: struct-type c-type ;
 
-M: struct-type heap-size size>> ;
-
-M: struct-type c-type-class drop byte-array ;
-
-M: struct-type c-type-align align>> ;
-
 M: struct-type c-type-stack-align? drop f ;
 
-M: struct-type c-type-boxer-quot boxer-quot>> ;
-
-M: struct-type c-type-unboxer-quot unboxer-quot>> ;
-
 : if-value-struct ( ctype true false -- )
     [ dup value-struct? ] 2dip '[ drop "void*" @ ] if ; inline
 
@@ -56,6 +38,7 @@ M: struct-type stack-size
 : (define-struct) ( name size align fields -- )
     [ [ align ] keep ] dip
     struct-type new
+        byte-array >>class
         swap >>fields
         swap >>align
         swap >>size
index 36f4fadf00a47903554e3f9bd98a7921485081fc..5b6f1eac7174a15e70b023b7532808a1de8d8d82 100644 (file)
@@ -1,6 +1,7 @@
 IN: math.vectors.specialization.tests
 USING: compiler.tree.debugger math.vectors tools.test kernel
 kernel.private math specialized-arrays.double
+specialized-arrays.complex-float
 specialized-arrays.float ;
 
 [ V{ t } ] [
@@ -9,4 +10,12 @@ specialized-arrays.float ;
 
 [ V{ float } ] [
     [ { float-array float } declare v*n norm ] final-classes
+] unit-test
+
+[ V{ number } ] [
+    [ { complex-float-array complex-float-array } declare v. ] final-classes
+] unit-test
+
+[ V{ real } ] [
+    [ { complex-float-array complex } declare v*n norm ] final-classes
 ] unit-test
\ No newline at end of file