1 ! Copyright (C) 2009 Jeremy Hughes.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.inline alien.inline.types alien.marshall
4 combinators effects generalizations kernel locals make namespaces
5 quotations sequences words alien.marshall.structs lexer parser
6 vocabs.parser multiline ;
7 IN: alien.marshall.syntax
9 :: marshalled-function ( name types effect -- word quot effect )
10 name types effect factor-function
12 [ out>> types [ pointer-to-non-const-primitive? ] filter append ]
16 types [ marshaller ] map , \ spread , ,
17 types length , \ nkeep ,
18 types [ out-arg-unmarshaller ] map
19 effect out>> dup empty?
20 [ drop ] [ first unmarshaller prefix ] if
25 : define-c-marshalled ( name types effect body -- )
27 [ marshalled-function define-declared ]
28 [ prototype-string ] 3bi
29 ] dip append-function-body c-strings get push ;
31 : define-c-marshalled' ( name effect body -- )
34 [ marshalled-function define-declared ]
35 [ out>> prototype-string' ] 3bi
36 ] dip append-function-body c-strings get push ;
39 function-types-effect parse-here define-c-marshalled ;
42 function-types-effect marshalled-function define-declared ;
45 scan current-vocab parse-definition
46 define-marshalled-struct ;
49 scan current-vocab parse-definition
50 [ define-marshalled-struct ] [ nip define-c-struct ] 3bi ;