]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/parser/parser.factor
use a "pointer" wrapper tuple to indicate pointer types instead of the current slipsh...
[factor.git] / basis / alien / parser / parser.factor
index 67f1d4e5fd36bf7107bc4a854fe7a202112d13c8..09ee88c173c4130034afe76111d452b73df3b5fd 100644 (file)
@@ -8,18 +8,27 @@ namespaces summary math vocabs.parser ;
 IN: alien.parser
 
 : parse-c-type-name ( name -- word )
-    dup search [ nip ] [ no-word ] if* ;
+    dup search [ ] [ no-word ] ?if ;
 
-: parse-c-type ( string -- type )
+: parse-array-type ( name -- dims c-type )
+    "[" split unclip
+    [ [ "]" ?tail drop parse-word ] map ] dip ;
+
+: (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 ] }
-        [ parse-c-type-name no-c-type ]
+        { [ dup "void" =         ] [ drop void ] }
+        { [ CHAR: ] over member? ] [ parse-array-type parse-c-type-name prefix ] }
+        { [ dup search           ] [ parse-c-type-name ] }
+        { [ "*" ?tail            ] [ (parse-c-type) <pointer> ] }
+        [ dup search [ ] [ no-word ] ?if ]
     } cond ;
 
+: valid-c-type? ( c-type -- ? )
+    { [ array? ] [ c-type-word? ] [ pointer? ] [ void? ] } 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 ]
@@ -88,7 +97,7 @@ IN: alien.parser
     type-name current-vocab create :> type-word 
     type-word [ reset-generic ] [ reset-c-type ] bi
     void* type-word typedef
-    parameters return parse-arglist :> callback-effect :> types
+    parameters return parse-arglist :> ( types callback-effect )
     type-word callback-effect "callback-effect" set-word-prop
     type-word lib "callback-library" set-word-prop
     type-word return types lib library-abi callback-quot (( quot -- alien )) ;