1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel combinators alien alien.enums
4 alien.strings alien.c-types alien.parser alien.syntax arrays
5 assocs effects math.parser prettyprint.backend prettyprint.custom
6 prettyprint.sections definitions see see.private sequences
12 { [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
13 { [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
14 [ \ ALIEN: [ alien-address >hex text ] pprint-prefix ]
17 M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
19 M: c-type-word definer drop \ C-TYPE: f ;
20 M: c-type-word definition drop f ;
21 M: c-type-word declarations. drop ;
24 GENERIC: pointer-string ( pointer -- string/f )
25 M: object pointer-string drop f ;
26 M: word pointer-string name>> ;
27 M: pointer pointer-string to>> pointer-string [ CHAR: * suffix ] [ f ] if* ;
30 GENERIC: pprint-c-type ( c-type -- )
31 M: word pprint-c-type pprint-word ;
32 M: pointer pprint-c-type
36 M: wrapper pprint-c-type wrapped>> pprint-word ;
37 M: string pprint-c-type text ;
38 M: array pprint-c-type pprint* ;
40 M: pointer pprint* \ pointer: pprint-word to>> pprint-c-type ;
42 M: typedef-word definer drop \ TYPEDEF: f ;
44 M: typedef-word synopsis*
48 [ "c-type" word-prop pprint-c-type ]
52 : pprint-function-arg ( type name -- )
53 [ pprint-c-type ] [ text ] bi* ;
55 : pprint-function-args ( types names -- )
58 [ [ first2 "," append pprint-function-arg ] each ] dip
59 first2 pprint-function-arg
62 : pprint-library ( library -- )
63 [ \ LIBRARY: [ text ] pprint-prefix ] when* ;
65 : pprint-function ( word quot -- )
66 [ def>> first pprint-c-type ]
70 [ def>> fourth ] [ stack-effect in>> ] bi
75 M: alien-function-alias-word definer
76 drop \ FUNCTION-ALIAS: \ ; ;
77 M: alien-function-alias-word definition drop f ;
78 M: alien-function-alias-word synopsis*
81 [ def>> second pprint-library ]
84 [ [ def>> third text ] pprint-function ]
87 M: alien-function-word definer
88 drop \ FUNCTION: \ ; ;
89 M: alien-function-word synopsis*
92 [ def>> second pprint-library ]
94 [ [ pprint-word ] pprint-function ]
97 M: alien-callback-type-word definer
98 drop \ CALLBACK: \ ; ;
99 M: alien-callback-type-word definition drop f ;
100 M: alien-callback-type-word synopsis*
103 [ "callback-library" word-prop pprint-library ]
105 [ def>> first pprint-c-type ]
109 [ def>> second ] [ "callback-effect" word-prop in>> ] bi
115 M: enum-c-type-word definer
117 M: enum-c-type-word synopsis*
122 [ c-type base-type>> dup int eq? [ drop ] [ "<" text pprint-word ] if ]
124 M: enum-c-type-word definition