]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/prettyprint/prettyprint.factor
use a "pointer" wrapper tuple to indicate pointer types instead of the current slipsh...
[factor.git] / basis / alien / prettyprint / prettyprint.factor
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 ;
7 IN: alien.prettyprint
8
9 M: alien pprint*
10     {
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 ]
14     } cond ;
15
16 M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
17
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 ;
21
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* ;
28
29 M: pointer pprint* \ pointer: pprint-word to>> pprint-c-type ;
30
31 M: typedef-word definer drop \ TYPEDEF: f ;
32
33 M: typedef-word synopsis*
34     {
35         [ seeing-word ]
36         [ definer. ]
37         [ "c-type" word-prop pprint-c-type ]
38         [ pprint-word ]
39     } cleave ;
40
41 : pprint-function-arg ( type name -- )
42     [ pprint-c-type ] [ text ] bi* ;
43
44 : pprint-function-args ( types names -- )
45     zip [ ] [
46         unclip-last
47         [ [ first2 "," append pprint-function-arg ] each ] dip
48         first2 pprint-function-arg
49     ] if-empty ;
50
51 : pprint-library ( library -- )
52     [ \ LIBRARY: [ text ] pprint-prefix ] when* ;
53
54 M: alien-function-word definer
55     drop \ FUNCTION: \ ; ;
56 M: alien-function-word definition drop f ;
57 M: alien-function-word synopsis*
58     {
59         [ seeing-word ]
60         [ def>> second pprint-library ]
61         [ definer. ]
62         [ def>> first pprint-c-type ]
63         [ pprint-word ]
64         [
65             <block "(" text
66             [ def>> fourth ] [ stack-effect in>> ] bi
67             pprint-function-args
68             ")" text block>
69         ]
70     } cleave ;
71
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*
76     {
77         [ seeing-word ]
78         [ "callback-library" word-prop pprint-library ]
79         [ definer. ]
80         [ def>> first pprint-c-type ]
81         [ pprint-word ]
82         [
83             <block "(" text 
84             [ def>> second ] [ "callback-effect" word-prop in>> ] bi
85             pprint-function-args
86             ")" text block>
87         ]
88     } cleave ;