]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/complex/functor/functor.factor
Specialized array overhaul
[factor.git] / basis / alien / complex / functor / functor.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.structs alien.c-types classes.struct math
4 math.functions sequences arrays kernel functors vocabs.parser
5 namespaces quotations ;
6 IN: alien.complex.functor
7
8 FUNCTOR: define-complex-type ( N T -- )
9
10 T-class DEFINES-CLASS ${T}
11
12 <T> DEFINES <${T}>
13 *T DEFINES *${T}
14
15 WHERE
16
17 STRUCT: T-class { real N } { imaginary N } ;
18
19 : <T> ( z -- alien )
20     >rect T-class <struct-boa> >c-ptr ;
21
22 : *T ( alien -- z )
23     T-class memory>struct [ real>> ] [ imaginary>> ] bi rect> ; inline
24
25 T-class c-type
26 <T> 1quotation >>unboxer-quot
27 *T 1quotation >>boxer-quot
28 number >>boxed-class
29 drop
30
31 ;FUNCTOR