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 ;
23 GENERIC: pointer-string ( pointer -- string/f )
24 M: object pointer-string drop f ;
25 M: word pointer-string name>> ;
26 M: pointer pointer-string to>> pointer-string [ CHAR: * suffix ] [ f ] if* ;
29 GENERIC: pprint-c-type ( c-type -- )
30 M: word pprint-c-type pprint-word ;
31 M: pointer pprint-c-type
35 M: wrapper pprint-c-type wrapped>> pprint-word ;
36 M: string pprint-c-type text ;
37 M: array pprint-c-type pprint* ;
39 M: pointer pprint* \ pointer: pprint-word to>> pprint-c-type ;
41 M: typedef-word definer drop \ TYPEDEF: f ;
43 M: typedef-word synopsis*
47 [ "c-type" word-prop pprint-c-type ]
51 : pprint-function-arg ( type name -- )
52 [ pprint-c-type ] [ text ] bi* ;
54 : pprint-function-args ( types names -- )
57 [ [ first2 "," append pprint-function-arg ] each ] dip
58 first2 pprint-function-arg
61 : pprint-library ( library -- )
62 [ \ LIBRARY: [ text ] pprint-prefix ] when* ;
64 M: alien-function-word definer
65 drop \ FUNCTION: \ ; ;
66 M: alien-function-word definition drop f ;
67 M: alien-function-word synopsis*
70 [ def>> second pprint-library ]
72 [ def>> first pprint-c-type ]
76 [ def>> fourth ] [ stack-effect in>> ] bi
82 M: alien-callback-type-word definer
83 drop \ CALLBACK: \ ; ;
84 M: alien-callback-type-word definition drop f ;
85 M: alien-callback-type-word synopsis*
88 [ "callback-library" word-prop pprint-library ]
90 [ def>> first pprint-c-type ]
94 [ def>> second ] [ "callback-effect" word-prop in>> ] bi