]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/prettyprint/prettyprint.factor
Merge branch 'master' of git://factorcode.org/git/factor into constraints
[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: wrapper pprint-c-type wrapped>> pprint-word ;
25 M: string pprint-c-type text ;
26 M: array pprint-c-type pprint* ;
27
28 M: typedef-word definer drop \ TYPEDEF: f ;
29
30 M: typedef-word synopsis*
31     {
32         [ seeing-word ]
33         [ definer. ]
34         [ "c-type" word-prop pprint-c-type ]
35         [ pprint-word ]
36     } cleave ;
37
38 : pprint-function-arg ( type name -- )
39     [ pprint-c-type ] [ text ] bi* ;
40
41 : pprint-function-args ( types names -- )
42     zip [ ] [
43         unclip-last
44         [ [ first2 "," append pprint-function-arg ] each ] dip
45         first2 pprint-function-arg
46     ] if-empty ;
47
48 M: alien-function-word definer
49     drop \ FUNCTION: \ ; ;
50 M: alien-function-word definition drop f ;
51 M: alien-function-word synopsis*
52     {
53         [ seeing-word ]
54         [ def>> second [ \ LIBRARY: [ text ] pprint-prefix ] when* ]
55         [ definer. ]
56         [ def>> first pprint-c-type ]
57         [ pprint-word ]
58         [
59             <block "(" text
60             [ def>> fourth ] [ stack-effect in>> ] bi
61             pprint-function-args
62             ")" text block>
63         ]
64     } cleave ;
65
66 M: alien-callback-type-word definer
67     "callback-abi" word-prop "stdcall" =
68     \ STDCALL-CALLBACK: \ CALLBACK: ? 
69     f ;
70 M: alien-callback-type-word definition drop f ;
71 M: alien-callback-type-word synopsis*
72     {
73         [ seeing-word ]
74         [ definer. ]
75         [ def>> first pprint-c-type ]
76         [ pprint-word ]
77         [
78             <block "(" text 
79             [ def>> second ] [ "callback-effect" word-prop in>> ] bi
80             pprint-function-args
81             ")" text block>
82         ]
83     } cleave ;