2008-12-08 15:58:00 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-09-15 23:39:25 -04:00
|
|
|
USING: accessors kernel combinators alien alien.strings alien.c-types
|
|
|
|
alien.parser alien.syntax arrays assocs effects math.parser
|
|
|
|
prettyprint.backend prettyprint.custom prettyprint.sections
|
|
|
|
definitions see see.private sequences strings words ;
|
2008-12-08 15:58:00 -05:00
|
|
|
IN: alien.prettyprint
|
|
|
|
|
|
|
|
M: alien pprint*
|
|
|
|
{
|
|
|
|
{ [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
|
|
|
|
{ [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
|
2009-09-12 22:17:53 -04:00
|
|
|
[ \ ALIEN: [ alien-address >hex text ] pprint-prefix ]
|
2008-12-08 15:58:00 -05:00
|
|
|
} cond ;
|
|
|
|
|
|
|
|
M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
|
2009-09-15 16:18:54 -04:00
|
|
|
|
|
|
|
M: c-type-word definer drop \ C-TYPE: f ;
|
|
|
|
M: c-type-word definition drop f ;
|
2009-09-21 00:12:31 -04:00
|
|
|
M: c-type-word declarations. drop ;
|
2009-09-15 16:18:54 -04:00
|
|
|
|
2009-09-15 17:08:42 -04:00
|
|
|
GENERIC: pprint-c-type ( c-type -- )
|
|
|
|
M: word pprint-c-type pprint-word ;
|
2009-09-15 23:39:25 -04:00
|
|
|
M: wrapper pprint-c-type wrapped>> pprint-word ;
|
2009-09-15 17:08:42 -04:00
|
|
|
M: string pprint-c-type text ;
|
|
|
|
M: array pprint-c-type pprint* ;
|
|
|
|
|
2009-09-15 23:10:41 -04:00
|
|
|
M: typedef-word definer drop \ TYPEDEF: f ;
|
|
|
|
|
|
|
|
M: typedef-word synopsis*
|
2009-09-21 00:12:31 -04:00
|
|
|
{
|
|
|
|
[ seeing-word ]
|
|
|
|
[ definer. ]
|
|
|
|
[ "c-type" word-prop pprint-c-type ]
|
|
|
|
[ pprint-word ]
|
|
|
|
} cleave ;
|
2009-09-15 23:39:25 -04:00
|
|
|
|
|
|
|
: pprint-function-arg ( type name -- )
|
|
|
|
[ pprint-c-type ] [ text ] bi* ;
|
|
|
|
|
2009-09-21 15:14:12 -04:00
|
|
|
: pprint-function-args ( types names -- )
|
|
|
|
zip [ ] [
|
2009-09-16 11:24:03 -04:00
|
|
|
unclip-last
|
|
|
|
[ [ first2 "," append pprint-function-arg ] each ] dip
|
|
|
|
first2 pprint-function-arg
|
|
|
|
] if-empty ;
|
2009-09-15 23:39:25 -04:00
|
|
|
|
|
|
|
M: alien-function-word definer
|
|
|
|
drop \ FUNCTION: \ ; ;
|
|
|
|
M: alien-function-word definition drop f ;
|
|
|
|
M: alien-function-word synopsis*
|
2009-09-21 00:12:31 -04:00
|
|
|
{
|
|
|
|
[ seeing-word ]
|
2009-09-21 00:59:43 -04:00
|
|
|
[ def>> second [ \ LIBRARY: [ text ] pprint-prefix ] when* ]
|
2009-09-21 00:12:31 -04:00
|
|
|
[ definer. ]
|
|
|
|
[ def>> first pprint-c-type ]
|
|
|
|
[ pprint-word ]
|
2009-09-21 15:14:12 -04:00
|
|
|
[
|
|
|
|
<block "(" text
|
|
|
|
[ def>> fourth ] [ stack-effect in>> ] bi
|
|
|
|
pprint-function-args
|
|
|
|
")" text block>
|
|
|
|
]
|
2009-09-21 00:12:31 -04:00
|
|
|
} cleave ;
|
2009-09-21 00:59:43 -04:00
|
|
|
|
2009-09-21 15:14:12 -04:00
|
|
|
M: alien-callback-type-word definer
|
|
|
|
"callback-abi" word-prop "stdcall" =
|
|
|
|
\ STDCALL-CALLBACK: \ CALLBACK: ?
|
|
|
|
f ;
|
|
|
|
M: alien-callback-type-word definition drop f ;
|
|
|
|
M: alien-callback-type-word synopsis*
|
|
|
|
{
|
|
|
|
[ seeing-word ]
|
|
|
|
[ definer. ]
|
|
|
|
[ def>> first pprint-c-type ]
|
|
|
|
[ pprint-word ]
|
|
|
|
[
|
|
|
|
<block "(" text
|
|
|
|
[ def>> second ] [ "callback-effect" word-prop in>> ] bi
|
|
|
|
pprint-function-args
|
|
|
|
")" text block>
|
|
|
|
]
|
|
|
|
} cleave ;
|