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

22 lines
540 B
Factor
Raw Normal View History

! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2017-12-03 11:52:03 -05:00
USING: functors2 ;
IN: alien.complex.functor
2017-12-03 11:52:03 -05:00
FUNCTOR: define-complex-type ( N: name T: name -- ) [[
2017-12-03 11:52:03 -05:00
STRUCT: ${T}-class { real ${N}-type } { imaginary ${N}-type } ;
2010-02-21 13:28:42 -05:00
2017-12-03 11:52:03 -05:00
: <${T}> ( z -- alien )
>rect ${T}-class <struct-boa> >c-ptr ;
2017-12-03 11:52:03 -05:00
: *${T} ( alien -- z )
T-class memory>struct [ real>> ] [ imaginary>> ] bi rect> ; inline
2017-12-03 11:52:03 -05:00
${T}-class lookup-c-type
<${T}> 1quotation >>unboxer-quot
*${T} 1quotation >>boxer-quot
complex >>boxed-class
drop
2017-12-03 11:52:03 -05:00
]]