windows.com: update COM-INTERFACE: to parse incrementally
parent
cd17a934ac
commit
bde65fe2d0
|
@ -2,8 +2,8 @@ USING: alien alien.c-types alien.accessors alien.parser
|
||||||
effects kernel windows.ole32 parser lexer splitting grouping
|
effects kernel windows.ole32 parser lexer splitting grouping
|
||||||
sequences namespaces assocs quotations generalizations
|
sequences namespaces assocs quotations generalizations
|
||||||
accessors words macros alien.syntax fry arrays layouts math
|
accessors words macros alien.syntax fry arrays layouts math
|
||||||
classes.struct windows.kernel32 ;
|
classes.struct windows.kernel32 locals ;
|
||||||
FROM: alien.parser.private => return-type-name ;
|
FROM: alien.parser.private => parse-pointers return-type-name ;
|
||||||
IN: windows.com.syntax
|
IN: windows.com.syntax
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -18,7 +18,7 @@ MACRO: com-invoke ( n return parameters -- )
|
||||||
TUPLE: com-interface-definition word parent iid functions ;
|
TUPLE: com-interface-definition word parent iid functions ;
|
||||||
C: <com-interface-definition> com-interface-definition
|
C: <com-interface-definition> com-interface-definition
|
||||||
|
|
||||||
TUPLE: com-function-definition name return parameters ;
|
TUPLE: com-function-definition return name parameter-types parameter-names ;
|
||||||
C: <com-function-definition> com-function-definition
|
C: <com-function-definition> com-function-definition
|
||||||
|
|
||||||
SYMBOL: +com-interface-definitions+
|
SYMBOL: +com-interface-definitions+
|
||||||
|
@ -37,19 +37,20 @@ ERROR: no-com-interface interface ;
|
||||||
: save-com-interface-definition ( definition -- )
|
: save-com-interface-definition ( definition -- )
|
||||||
dup word>> +com-interface-definitions+ get-global set-at ;
|
dup word>> +com-interface-definitions+ get-global set-at ;
|
||||||
|
|
||||||
: (parse-com-function) ( tokens -- definition )
|
: (parse-com-function) ( return name -- definition )
|
||||||
[ second ]
|
")" scan-c-args
|
||||||
[ first parse-c-type ]
|
[ pointer: void prefix ] [ "this" prefix ] bi*
|
||||||
[
|
|
||||||
3 tail [ CHAR: , swap remove ] map
|
|
||||||
2 group [ first2 normalize-c-arg 2array ] map
|
|
||||||
{ void* "this" } prefix
|
|
||||||
] tri
|
|
||||||
<com-function-definition> ;
|
<com-function-definition> ;
|
||||||
|
|
||||||
|
:: (parse-com-functions) ( functions -- )
|
||||||
|
scan dup ";" = [ drop ] [
|
||||||
|
parse-c-type scan parse-pointers
|
||||||
|
(parse-com-function) functions push
|
||||||
|
functions (parse-com-functions)
|
||||||
|
] if ;
|
||||||
|
|
||||||
: parse-com-functions ( -- functions )
|
: parse-com-functions ( -- functions )
|
||||||
";" parse-tokens { ")" } split harvest
|
V{ } clone [ (parse-com-functions) ] keep >array ;
|
||||||
[ (parse-com-function) ] map ;
|
|
||||||
|
|
||||||
: (iid-word) ( definition -- word )
|
: (iid-word) ( definition -- word )
|
||||||
word>> name>> "-iid" append create-in ;
|
word>> name>> "-iid" append create-in ;
|
||||||
|
@ -66,20 +67,10 @@ ERROR: no-com-interface interface ;
|
||||||
dup parent>> [ family-tree-functions ] [ { } ] if*
|
dup parent>> [ family-tree-functions ] [ { } ] if*
|
||||||
swap functions>> append ;
|
swap functions>> append ;
|
||||||
|
|
||||||
: (invocation-quot) ( function return parameters -- quot )
|
:: (define-word-for-function) ( function interface n -- )
|
||||||
[ first ] map [ com-invoke ] 3curry ;
|
function interface (function-word)
|
||||||
|
n function [ return>> ] [ parameter-types>> ] bi '[ _ _ _ com-invoke ]
|
||||||
: (stack-effect-from-return-and-parameters) ( return parameters -- stack-effect )
|
function [ parameter-names>> ] [ return>> ] bi function-effect
|
||||||
swap
|
|
||||||
[ [ second ] map ]
|
|
||||||
[ dup void? [ drop { } ] [ return-type-name 1array ] if ] bi*
|
|
||||||
<effect> ;
|
|
||||||
|
|
||||||
: (define-word-for-function) ( function interface n -- )
|
|
||||||
-rot [ (function-word) swap ] 2keep drop
|
|
||||||
[ return>> ] [ parameters>> ] bi
|
|
||||||
[ (invocation-quot) ] 2keep
|
|
||||||
(stack-effect-from-return-and-parameters)
|
|
||||||
define-declared ;
|
define-declared ;
|
||||||
|
|
||||||
: define-words-for-com-interface ( definition -- )
|
: define-words-for-com-interface ( definition -- )
|
||||||
|
|
|
@ -110,11 +110,7 @@ unless
|
||||||
keep (next-vtbl-counter) '[
|
keep (next-vtbl-counter) '[
|
||||||
swap [
|
swap [
|
||||||
[ name>> _ _ (callback-word) ]
|
[ name>> _ _ (callback-word) ]
|
||||||
[ return>> ] [
|
[ return>> ] [ parameter-types>> dup length ] tri
|
||||||
parameters>>
|
|
||||||
[ [ first ] map ]
|
|
||||||
[ length ] bi
|
|
||||||
] tri
|
|
||||||
] [
|
] [
|
||||||
first2 (finish-thunk)
|
first2 (finish-thunk)
|
||||||
] bi*
|
] bi*
|
||||||
|
|
Loading…
Reference in New Issue