1 ! Copyright (C) 2008, 2010 Slava Pestov, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.enums alien.strings
4 alien.syntax arrays assocs combinators combinators.short-circuit
5 definitions effects kernel math.parser prettyprint.backend
6 prettyprint.custom prettyprint.sections 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: record-pointer ( pointer -- )
25 M: object record-pointer drop ;
26 M: word record-pointer record-vocab ;
27 M: pointer record-pointer to>> record-pointer ;
29 GENERIC: record-c-type ( c-type -- )
30 M: word record-c-type record-vocab ;
31 M: pointer record-c-type record-pointer ;
32 M: wrapper record-c-type wrapped>> record-c-type ;
33 M: array record-c-type first record-c-type ;
36 : pprint-c-type ( c-type -- )
37 [ record-c-type ] [ c-type-string ] [ ] tri present-text ;
40 <flow \ pointer: pprint-word to>> pprint* block> ;
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 PREDICATE: alien-function-alias-word < word
78 [ last \ alien-invoke eq? ]
81 M: alien-function-alias-word definer
82 drop \ FUNCTION-ALIAS: f ;
83 M: alien-function-alias-word definition drop f ;
84 M: alien-function-alias-word synopsis*
87 [ def>> second pprint-library ]
90 [ [ def>> third text ] pprint-function ]
92 M: alien-function-alias-word declarations. drop ;
94 PREDICATE: alien-function-word < alien-function-alias-word
95 [ def>> third ] [ name>> ] bi = ;
97 M: alien-function-word definer
99 M: alien-function-word synopsis*
102 [ def>> second pprint-library ]
104 [ [ pprint-word ] pprint-function ]
107 PREDICATE: alien-callback-type-word < typedef-word
108 "callback-effect" word-prop >boolean ;
110 M: alien-callback-type-word definer
112 M: alien-callback-type-word definition drop f ;
113 M: alien-callback-type-word synopsis*
116 [ "callback-library" word-prop pprint-library ]
118 [ def>> first first pprint-c-type ]
122 [ def>> first second ] [ "callback-effect" word-prop in>> ] bi
128 M: enum-c-type-word definer
130 M: enum-c-type-word synopsis*
135 [ lookup-c-type base-type>> dup int eq? [ drop ] [ "<" text pprint-word ] if ]
137 M: enum-c-type-word definition
138 lookup-c-type members>> ;