cords: updated functors syntax. ugly.

modern-harvey2
Doug Coleman 2017-12-28 16:52:05 -08:00
parent 7ccaf78071
commit 233c3dcebd
3 changed files with 58 additions and 81 deletions

View File

@ -2,86 +2,67 @@ USING: accessors alien.c-types arrays byte-arrays
cpu.architecture effects functors generalizations kernel lexer cpu.architecture effects functors generalizations kernel lexer
math math.vectors.simd math.vectors.simd.intrinsics parser math math.vectors.simd math.vectors.simd.intrinsics parser
prettyprint.custom quotations sequences sequences.cords words prettyprint.custom quotations sequences sequences.cords words
classes ; classes functors2 literals ;
IN: math.vectors.simd.cords IN: math.vectors.simd.cords
<< <<
<PRIVATE SAME-FUNCTOR: simd-128-cord ( type/2: existing-word type: name -- ) [[
<FUNCTOR: (define-simd-128-cord) ( A/2 A -- ) DEFER: ${type}
<<
SPECIALIZED-CORD: ${type/2} ${type}
>>
A-rep IS ${A/2}-rep <<
>A/2 IS >${A/2} <c-type>
A/2-boa IS ${A/2}-boa byte-array >>class
A/2-with IS ${A/2}-with ${type} >>boxed-class
A/2-cast IS ${A/2}-cast [
[ ${type/2}-rep alien-vector ${type/2} boa ]
[ 16 + ${type/2}-rep alien-vector ${type/2} boa ] 2bi cord-append
] >>getter
[
[ [ head>> underlying>> ] 2dip ${type/2}-rep set-alien-vector ]
[ [ tail>> underlying>> ] 2dip 16 + ${type/2}-rep set-alien-vector ] 3bi
] >>setter
32 >>size
16 >>align
${type/2}-rep >>rep
\ ${type} typedef
>>
>A DEFINES >${A} : >${type} ( seq -- ${type} )
A-boa DEFINES ${A}-boa [ $[ ${type/2}-rep rep-length ] head-slice >${type/2} ]
A-with DEFINES ${A}-with [ $[ ${type/2}-rep rep-length ] tail-slice >${type/2} ] bi cord-append ;
A-cast DEFINES ${A}-cast
A{ DEFINES ${A}{
N [ A-rep rep-length ] DEFER: ${type}-boa
BOA-EFFECT [ N 2 * "n" <array> { "v" } <effect> ] \ ${type}-boa
{ $[ ${type/2}-rep rep-length ] ndip ${type/2}-boa cord-append } { ${type/2}-boa } >quotation prefix >quotation
$[ $[ ${type/2}-rep rep-length ] 2 * "n" <array> { "v" } <effect> ] define-inline
WHERE : ${type}-with ( n -- v )
[ ${type/2}-with ] [ ${type/2}-with ] bi cord-append ; inline
: >A ( seq -- A ) : ${type}-cast ( v -- v' )
[ N head-slice >A/2 ] [ ${type/2}-cast ] cord-map ; inline
[ N tail-slice >A/2 ] bi cord-append ;
\ A-boa M: ${type} new-sequence
{ N ndip A/2-boa cord-append } { A/2-boa } >quotation prefix >quotation 2drop
BOA-EFFECT define-inline $[ ${type/2}-rep rep-length ] ${type/2} new new-sequence
$[ ${type/2}-rep rep-length ] ${type/2} new new-sequence
\ ${type} boa ;
: A-with ( n -- v ) M: ${type} like
[ A/2-with ] [ A/2-with ] bi cord-append ; inline over \ ${type} instance? [ drop ] [ call-next-method ] if ;
: A-cast ( v -- v' ) M: ${type} >pprint-sequence ;
[ A/2-cast ] cord-map ; inline M: ${type} pprint* pprint-object ;
M: A new-sequence <<
2drop SYNTAX: ${type}{ \ } [ >${type} ] parse-literal ;
N A/2 new new-sequence >>
N A/2 new new-sequence M: ${type} pprint-delims drop \ ${type}{ \ } ;
\ A boa ; ]]
M: A like
over \ A instance? [ drop ] [ call-next-method ] if ;
M: A >pprint-sequence ;
M: A pprint* pprint-object ;
M: A pprint-delims drop \ A{ \ } ;
SYNTAX: A{ \ } [ >A ] parse-literal ;
<c-type>
byte-array >>class
A >>boxed-class
[
[ A-rep alien-vector A/2 boa ]
[ 16 + A-rep alien-vector A/2 boa ] 2bi cord-append
] >>getter
[
[ [ head>> underlying>> ] 2dip A-rep set-alien-vector ]
[ [ tail>> underlying>> ] 2dip 16 + A-rep set-alien-vector ] 3bi
] >>setter
32 >>size
16 >>align
A-rep >>rep
\ A typedef
;FUNCTOR>
: define-simd-128-cord ( A/2 T -- )
[ define-specialized-cord ]
[ create-word-in (define-simd-128-cord) ] 2bi ;
SYNTAX: \SIMD-128-CORD:
scan-word scan-token define-simd-128-cord ;
PRIVATE>
>> >>
SIMD-128-CORD: char-16 char-32 SIMD-128-CORD: char-16 char-32

View File

@ -328,7 +328,6 @@ DEFER: ${type}-boa
<< <<
\ ${type}-boa \ ${type}-boa
! [ $[ ${type}-rep rep-component-type c:c-type-class "coercer" word-prop [ ] or ] $[ ${type}-rep rep-length ] napply ] ${type}-rep rep-length {
[ $[ ${type}-coercer ] $[ ${type}-rep rep-length ] napply ] ${type}-rep rep-length { [ $[ ${type}-coercer ] $[ ${type}-rep rep-length ] napply ] ${type}-rep rep-length {
{ 2 [ [ ${type}-rep (simd-gather-2) ${type} boa ] ] } { 2 [ [ ${type}-rep (simd-gather-2) ${type} boa ] ] }
{ 4 [ [ ${type}-rep (simd-gather-4) ${type} boa ] ] } { 4 [ [ ${type}-rep (simd-gather-4) ${type} boa ] ] }

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs sequences sorting binary-search fry math USING: accessors assocs sequences sorting binary-search fry math
math.order arrays classes combinators kernel functors locals math.order arrays classes combinators kernel functors locals
math.functions math.vectors ; math.functions math.vectors functors2 ;
IN: sequences.cords IN: sequences.cords
MIXIN: cord MIXIN: cord
@ -27,21 +27,18 @@ GENERIC: cord-append ( seq1 seq2 -- cord )
M: object cord-append M: object cord-append
generic-cord boa ; inline generic-cord boa ; inline
<FUNCTOR: define-specialized-cord ( T C -- ) SAME-FUNCTOR: specialized-cord ( type: name class: name -- ) [[
USING: kernel ;
T-cord DEFINES-CLASS ${C} TUPLE: ${class}
{ head ${type} read-only } { tail ${type} read-only } ; final
INSTANCE: ${class} cord
WHERE M: ${type} cord-append
2dup [ ${type} instance? ] both?
[ ${class} boa ] [ generic-cord boa ] if ; inline
TUPLE: T-cord ]]
{ head T read-only } { tail T read-only } ; final
INSTANCE: T-cord cord
M: T cord-append
2dup [ T instance? ] both?
[ T-cord boa ] [ generic-cord boa ] if ; inline
;FUNCTOR>
: cord-map ( cord quot -- cord' ) : cord-map ( cord quot -- cord' )
[ [ head>> ] dip call ] [ [ head>> ] dip call ]