factor/basis/alien/complex/functor/functor.factor

33 lines
677 B
Factor
Raw Normal View History

! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2014-11-29 23:10:37 -05:00
USING: accessors alien alien.c-types classes.struct functors
kernel math math.functions quotations ;
IN: alien.complex.functor
<FUNCTOR: define-complex-type ( N T -- )
2010-02-21 13:28:42 -05:00
N-type IS ${N}
T-class DEFINES-CLASS ${T}
2009-02-06 20:05:56 -05:00
<T> DEFINES <${T}>
*T DEFINES *${T}
WHERE
2010-02-21 13:28:42 -05:00
STRUCT: T-class { real N-type } { imaginary N-type } ;
2009-02-06 20:05:56 -05:00
: <T> ( z -- alien )
2009-08-30 00:18:31 -04:00
>rect T-class <struct-boa> >c-ptr ;
2009-02-06 20:05:56 -05:00
: *T ( alien -- z )
T-class memory>struct [ real>> ] [ imaginary>> ] bi rect> ; inline
2011-10-24 20:00:09 -04:00
T-class lookup-c-type
2009-02-09 16:01:41 -05:00
<T> 1quotation >>unboxer-quot
*T 1quotation >>boxer-quot
complex >>boxed-class
drop
;FUNCTOR>