factor/basis/windows/com/syntax/syntax.factor

111 lines
3.1 KiB
Factor
Raw Normal View History

USING: alien alien.c-types alien.accessors alien.parser
effects kernel windows.ole32 parser lexer splitting grouping
sequences namespaces assocs quotations generalizations
accessors words macros alien.syntax fry arrays layouts math
classes.struct windows.kernel32 ;
2008-04-28 17:30:11 -04:00
IN: windows.com.syntax
<PRIVATE
MACRO: com-invoke ( n return parameters -- )
2008-12-03 07:52:16 -05:00
[ 2nip length ] 3keep
2008-04-28 17:30:11 -04:00
'[
2009-08-29 20:33:04 -04:00
_ npick *void* _ cell * alien-cell _ _
2008-04-28 17:30:11 -04:00
"stdcall" alien-indirect
] ;
TUPLE: com-interface-definition word parent iid functions ;
2008-04-28 17:30:11 -04:00
C: <com-interface-definition> com-interface-definition
TUPLE: com-function-definition name return parameters ;
C: <com-function-definition> com-function-definition
SYMBOL: +com-interface-definitions+
+com-interface-definitions+ get-global
[ H{ } +com-interface-definitions+ set-global ]
unless
ERROR: no-com-interface interface ;
2008-04-28 17:30:11 -04:00
: find-com-interface-definition ( name -- definition )
[
2008-04-28 17:30:11 -04:00
dup +com-interface-definitions+ get-global at*
[ nip ] [ drop no-com-interface ] if
] [ f ] if* ;
2008-04-28 17:30:11 -04:00
: save-com-interface-definition ( definition -- )
dup word>> +com-interface-definitions+ get-global set-at ;
2008-04-28 17:30:11 -04:00
: (parse-com-function) ( tokens -- definition )
[ second ]
[ first ]
[
3 tail [ CHAR: , swap remove ] map
2 group [ first2 normalize-c-arg 2array ] map
{ void* "this" } prefix
] tri
2008-04-28 17:30:11 -04:00
<com-function-definition> ;
: parse-com-functions ( -- functions )
2008-05-14 00:36:55 -04:00
";" parse-tokens { ")" } split harvest
2008-04-28 17:30:11 -04:00
[ (parse-com-function) ] map ;
: (iid-word) ( definition -- word )
word>> name>> "-iid" append create-in ;
2008-04-28 17:30:11 -04:00
: (function-word) ( function interface -- word )
swap [ word>> name>> "::" ] [ name>> ] bi*
3append create-in ;
2008-04-28 17:30:11 -04:00
: family-tree ( definition -- definitions )
dup parent>> [ family-tree ] [ { } ] if*
swap suffix ;
: family-tree-functions ( definition -- functions )
dup parent>> [ family-tree-functions ] [ { } ] if*
swap functions>> append ;
: (invocation-quot) ( function return parameters -- quot )
[ first ] map [ com-invoke ] 3curry ;
: (stack-effect-from-return-and-parameters) ( return parameters -- stack-effect )
swap
[ [ second ] map ]
[ dup void? [ drop { } ] [ 1array ] if ] bi*
<effect> ;
2008-04-28 17:30:11 -04:00
: (define-word-for-function) ( function interface n -- )
-rot [ (function-word) swap ] 2keep drop
2008-08-23 00:20:49 -04:00
[ return>> ] [ parameters>> ] bi
[ (invocation-quot) ] 2keep
(stack-effect-from-return-and-parameters)
define-declared ;
2008-04-28 17:30:11 -04:00
: define-words-for-com-interface ( definition -- )
[ [ (iid-word) ] [ iid>> 1quotation ] bi (( -- iid )) define-declared ]
[ word>> void* swap typedef ]
2008-04-28 17:30:11 -04:00
[
dup family-tree-functions
[ (define-word-for-function) ] with each-index
]
tri ;
PRIVATE>
SYNTAX: COM-INTERFACE:
CREATE-C-TYPE
scan-object find-com-interface-definition
2008-04-28 17:30:11 -04:00
scan string>guid
parse-com-functions
<com-interface-definition>
dup save-com-interface-definition
define-words-for-com-interface ;
2008-04-28 17:30:11 -04:00
SYNTAX: GUID: scan string>guid parsed ;
2009-08-29 20:18:39 -04:00
USING: vocabs vocabs.loader ;
"prettyprint" vocab [
"windows.com.prettyprint" require
] when