]> gitweb.factorcode.org Git - factor.git/commitdiff
allow FUNCTION: to parse pointers in the name field
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 23 Jul 2009 23:05:09 +0000 (18:05 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 23 Jul 2009 23:05:09 +0000 (18:05 -0500)
basis/alien/parser/parser.factor

index 8e050b395035a56b329fe9d32f930f6d2595625e..8e2fe8257868f48b23f855f384b472c2c4a4f461 100644 (file)
@@ -1,27 +1,30 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types arrays assocs effects grouping kernel
 parser sequences splitting words fry locals lexer namespaces
-summary ;
+summary math ;
 IN: alien.parser
 
-ERROR: invalid-c-name name ;
-
-M: invalid-c-name summary
-    drop "The C pointer asterisk must be part of the type string." ;
-
-: check-c-name ( string -- string )
-    dup [ CHAR: * = ] any? [ invalid-c-name ] when ;
+: normalize-c-arg ( type name -- type' name' )
+    [ length ]
+    [
+        [ CHAR: * = ] trim-head
+        [ length - CHAR: * <array> append ] keep
+    ] bi ;
 
 : parse-arglist ( parameters return -- types effect )
-    [ 2 group unzip [ "," ?tail drop check-c-name ] map ]
+    [
+        2 group [ first2 normalize-c-arg 2array ] map
+        unzip [ "," ?tail drop check-c-name ] map
+    ]
     [ [ { } ] [ 1array ] if-void ]
     bi* <effect> ;
 
 : function-quot ( return library function types -- quot )
     '[ _ _ _ _ alien-invoke ] ;
 
-:: make-function ( return library function parameters -- word quot effect )
+:: make-function ( return! library function! parameters -- word quot effect )
+    return function normalize-c-arg function! return!
     function check-c-name create-in dup reset-generic
     return library function
     parameters return parse-arglist [ function-quot ] dip ;