]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/prettyprint/prettyprint.factor
fix FUNCTION: prettyprint when function has no arguments
[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: typedef-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     \ TYPEDEF: pprint-word
32     dup "c-type" word-prop pprint-c-type
33     pprint-word ;
34
35 : pprint-function-arg ( type name -- )
36     [ pprint-c-type ] [ text ] bi* ;
37
38 : pprint-function-args ( word -- )
39     [ def>> fourth ] [ stack-effect in>> ] bi zip [ ] [
40         unclip-last
41         [ [ first2 "," append pprint-function-arg ] each ] dip
42         first2 pprint-function-arg
43     ] if-empty ;
44
45 M: alien-function-word definer
46     drop \ FUNCTION: \ ; ;
47 M: alien-function-word definition drop f ;
48 M: alien-function-word synopsis*
49     \ FUNCTION: pprint-word
50     [ def>> first pprint-c-type ]
51     [ pprint-word ]
52     [ <block "(" text pprint-function-args ")" text block> ] tri ;