]> gitweb.factorcode.org Git - factor.git/commitdiff
tweak parse-c-type so data-map can parse non-c-types
authorJoe Groff <arcata@gmail.com>
Fri, 16 Oct 2009 21:10:09 +0000 (16:10 -0500)
committerJoe Groff <arcata@gmail.com>
Fri, 16 Oct 2009 21:10:09 +0000 (16:10 -0500)
basis/alien/parser/parser.factor
extra/alien/data/map/map-tests.factor
extra/alien/data/map/map.factor
extra/grid-meshes/grid-meshes.factor

index e4ff5789d2385545a74ddbf8146aca128b59ed3a..abda8539e9460431d1e1492d2a255d29ab3d0e21 100644 (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 ]
index 25b07c381be1fdb646619312088ed3de549838b6..7a492ab0c56e8e0a89dd25895d0ef7bd003794b4 100644 (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 }
index 8039015a85bb4f7d0a0d189a9b5d89872e115f4f..72f5cb5517ecf55cb46e3a5c6bae83655fc4888f 100644 (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>
 
index 9a9fd91a64a8b7727eea70c2f6eb4295d593ea5e..b63b3d791c51e6d105daae2634ece5c98a61aac8 100644 (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@