]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/prettyprint/prettyprint.factor
include LIBRARY: in FUNCTION: synopsis
[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 ( word -- )
42     [ def>> fourth ] [ stack-effect in>> ] bi 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         [ <block "(" text pprint-function-args ")" text block> ]
59     } cleave ;
60