]> gitweb.factorcode.org Git - factor.git/commitdiff
windows.com: update COM-INTERFACE: to parse incrementally
authorJoe Groff <arcata@gmail.com>
Mon, 1 Mar 2010 03:30:15 +0000 (19:30 -0800)
committerJoe Groff <arcata@gmail.com>
Mon, 1 Mar 2010 03:30:15 +0000 (19:30 -0800)
basis/windows/com/syntax/syntax.factor
basis/windows/com/wrapper/wrapper.factor

index 5230d9497e04f07fd51e4240e15693d843d891d8..49c9272d9bb7d742c1f8be0006e815b6c07769ca 100644 (file)
@@ -2,8 +2,8 @@ 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 ;
-FROM: alien.parser.private => return-type-name ;
+classes.struct windows.kernel32 locals ;
+FROM: alien.parser.private => parse-pointers return-type-name ;
 IN: windows.com.syntax
 
 <PRIVATE
@@ -18,7 +18,7 @@ MACRO: com-invoke ( n return parameters -- )
 TUPLE: com-interface-definition word parent iid functions ;
 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
 
 SYMBOL: +com-interface-definitions+
@@ -37,19 +37,20 @@ ERROR: no-com-interface interface ;
 : save-com-interface-definition ( definition -- )
     dup word>> +com-interface-definitions+ get-global set-at ;
 
-: (parse-com-function) ( tokens -- definition )
-    [ second ]
-    [ first parse-c-type ]
-    [
-        3 tail [ CHAR: , swap remove ] map
-        2 group [ first2 normalize-c-arg 2array ] map
-        { void* "this" } prefix
-    ] tri
+: (parse-com-function) ( return name -- definition )
+    ")" scan-c-args
+    [ pointer: void prefix ] [ "this" prefix ] bi*
     <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-tokens { ")" } split harvest
-    [ (parse-com-function) ] map ;
+    V{ } clone [ (parse-com-functions) ] keep >array ;
 
 : (iid-word) ( definition -- word )
     word>> name>> "-iid" append create-in ;
@@ -66,20 +67,10 @@ ERROR: no-com-interface interface ;
     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 { } ] [ 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-word-for-function) ( function interface n -- )
+    function interface (function-word)
+    n function [ return>> ] [ parameter-types>> ] bi '[ _ _ _ com-invoke ]
+    function [ parameter-names>> ] [ return>> ] bi function-effect
     define-declared ;
 
 : define-words-for-com-interface ( definition -- )
index 623a9c8db3189e88a8d27b7f215256407a5c6451..25861659dc6d80f2661e736c1c30eeac45445367 100644 (file)
@@ -110,11 +110,7 @@ unless
     keep (next-vtbl-counter) '[
         swap [
             [ name>> _ _ (callback-word) ]
-            [ return>> ] [
-                parameters>>
-                [ [ first ] map ]
-                [ length ] bi
-            ] tri
+            [ return>> ] [ parameter-types>> dup length ] tri
         ] [
             first2 (finish-thunk)
         ] bi*