1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel combinators alien alien.strings alien.c-types
4 alien.parser alien.syntax arrays assocs effects math.parser
5 prettyprint.backend prettyprint.custom prettyprint.sections
6 definitions see see.private sequences strings words ;
11 { [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
12 { [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
13 [ \ ALIEN: [ alien-address >hex text ] pprint-prefix ]
16 M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
18 M: c-type-word definer drop \ C-TYPE: f ;
19 M: c-type-word definition drop f ;
20 M: c-type-word declarations. drop ;
22 GENERIC: pprint-c-type ( c-type -- )
23 M: word pprint-c-type pprint-word ;
24 M: pointer pprint-c-type to>> pprint-c-type "*" text ;
25 M: wrapper pprint-c-type wrapped>> pprint-word ;
26 M: string pprint-c-type text ;
27 M: array pprint-c-type pprint* ;
29 M: pointer pprint* \ pointer: pprint-word to>> pprint-c-type ;
31 M: typedef-word definer drop \ TYPEDEF: f ;
33 M: typedef-word synopsis*
37 [ "c-type" word-prop pprint-c-type ]
41 : pprint-function-arg ( type name -- )
42 [ pprint-c-type ] [ text ] bi* ;
44 : pprint-function-args ( types names -- )
47 [ [ first2 "," append pprint-function-arg ] each ] dip
48 first2 pprint-function-arg
51 : pprint-library ( library -- )
52 [ \ LIBRARY: [ text ] pprint-prefix ] when* ;
54 M: alien-function-word definer
55 drop \ FUNCTION: \ ; ;
56 M: alien-function-word definition drop f ;
57 M: alien-function-word synopsis*
60 [ def>> second pprint-library ]
62 [ def>> first pprint-c-type ]
66 [ def>> fourth ] [ stack-effect in>> ] bi
72 M: alien-callback-type-word definer
73 drop \ CALLBACK: \ ; ;
74 M: alien-callback-type-word definition drop f ;
75 M: alien-callback-type-word synopsis*
78 [ "callback-library" word-prop pprint-library ]
80 [ def>> first pprint-c-type ]
84 [ def>> second ] [ "callback-effect" word-prop in>> ] bi