tweak parse-c-type so data-map can parse non-c-types

db4
Joe Groff 2009-10-16 16:10:09 -05:00
parent 2ae8edeb9d
commit 21b289e836
4 changed files with 27 additions and 10 deletions

View File

@ -10,16 +10,22 @@ IN: alien.parser
: parse-c-type-name ( name -- word )
dup search [ ] [ no-word ] ?if ;
: parse-c-type ( string -- type )
: (parse-c-type) ( string -- type )
{
{ [ dup "void" = ] [ drop void ] }
{ [ CHAR: ] over member? ] [ parse-array-type parse-c-type-name prefix ] }
{ [ dup search c-type-word? ] [ parse-c-type-name ] }
{ [ "**" ?tail ] [ drop void* ] }
{ [ "*" ?tail ] [ parse-c-type-name resolve-pointer-type ] }
[ dup search [ no-c-type ] [ no-word ] ?if ]
{ [ dup "void" = ] [ drop void ] }
{ [ CHAR: ] over member? ] [ parse-array-type parse-c-type-name prefix ] }
{ [ dup search ] [ parse-c-type-name ] }
{ [ "**" ?tail ] [ drop void* ] }
{ [ "*" ?tail ] [ parse-c-type-name resolve-pointer-type ] }
[ dup search [ ] [ no-word ] ?if ]
} cond ;
: valid-c-type? ( c-type -- ? )
{ [ array? ] [ c-type-name? ] } 1|| ;
: parse-c-type ( string -- type )
(parse-c-type) dup valid-c-type? [ no-c-type ] unless ;
: scan-c-type ( -- c-type )
scan dup "{" =
[ drop \ } parse-until >array ]

View File

@ -13,6 +13,17 @@ IN: alien.data.map.tests
byte-array>float-array
] unit-test
[
float-4-array{
float-4{ 0.0 0.0 0.0 0.0 }
float-4{ 1.0 1.0 1.0 1.0 }
float-4{ 2.0 2.0 2.0 2.0 }
}
] [
3 iota [ float-4-with ] data-map( object -- float-4 )
byte-array>float-4-array
] unit-test
[
float-4-array{
float-4{ 0.0 1.0 2.0 3.0 }

View File

@ -117,8 +117,8 @@ MACRO: data-map! ( ins outs -- )
: parse-data-map-effect ( accum -- accum )
")" parse-effect
[ in>> [ parse-c-type ] map parsed ]
[ out>> [ parse-c-type ] map parsed ] bi ;
[ in>> [ (parse-c-type) ] map parsed ]
[ out>> [ (parse-c-type) ] map parsed ] bi ;
PRIVATE>

View File

@ -13,7 +13,7 @@ TUPLE: grid-mesh dim buffer row-length ;
: vertex-array-row ( range z0 z1 -- vertices )
'[ _ _ [ 0.0 swap 1.0 float-4-boa ] bi-curry@ bi ]
data-map( void -- float-4[2] ) ; inline
data-map( object -- float-4[2] ) ; inline
: vertex-array ( dim -- vertices )
first2 [ [ 0.0 1.0 1.0 ] dip /f <range> ] bi@