clean up
parent
896d6eac31
commit
0d743f94ff
|
@ -20,3 +20,4 @@ SYMBOL: implement-structs
|
|||
|
||||
: get-lib-alias ( lib -- alias )
|
||||
lib-aliases get-global at ;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
! Copyright (C) 2009 Anton Gorenko.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien alien.c-types alien.enums alien.parser arrays assocs classes.parser
|
||||
classes.struct combinators combinators.short-circuit compiler.units effects definitions fry generalizations
|
||||
gir.common gir.types kernel locals math math.parser namespaces
|
||||
parser prettyprint quotations sequences vocabs.parser words
|
||||
words.constant ;
|
||||
USING: accessors alien alien.c-types alien.enums alien.parser arrays
|
||||
assocs classes.parser classes.struct combinators
|
||||
combinators.short-circuit definitions effects fry gir.common gir.types
|
||||
kernel locals math.parser namespaces parser quotations sequences
|
||||
sequences.generalizations vocabs.parser words words.constant ;
|
||||
IN: gir.ffi
|
||||
|
||||
: string>c-type ( str -- c-type )
|
||||
|
@ -47,7 +47,7 @@ IN: gir.ffi
|
|||
: signal-ffi-invoker ( signal -- quot )
|
||||
[ return>> signal-param-c-type string>c-type ]
|
||||
[ parameters>> [ signal-param-c-type string>c-type ] map ] bi
|
||||
"cdecl" [ [ ] 3curry dip alien-callback ] 3curry ;
|
||||
cdecl [ [ ] 3curry dip alien-callback ] 3curry ;
|
||||
|
||||
: signal-ffi-effect ( signal -- effect )
|
||||
[ parameters>> [ name>> ] map ]
|
||||
|
@ -91,7 +91,11 @@ IN: gir.ffi
|
|||
|
||||
: fields>struct-slots ( fields -- slots )
|
||||
[
|
||||
[ name>> ] [ c-type>> string>c-type ]
|
||||
[ name>> ]
|
||||
[
|
||||
[ c-type>> string>c-type ] [ array-info>> ] bi
|
||||
[ fixed-size>> [ 2array ] when* ] when*
|
||||
]
|
||||
[ drop { } ] tri <struct-slot-spec>
|
||||
] map ;
|
||||
|
||||
|
@ -109,7 +113,6 @@ IN: gir.ffi
|
|||
[ c-type>> implement-structs get-global member? ]
|
||||
} 1&&
|
||||
[
|
||||
dup .
|
||||
[ c-type>> create-class-in dup ]
|
||||
[ fields>> fields>struct-slots ] bi define-struct-class
|
||||
] [
|
||||
|
@ -196,7 +199,8 @@ IN: gir.ffi
|
|||
} cleave ;
|
||||
|
||||
: define-ffi-const ( const -- word )
|
||||
[ name>> create-in dup ] [ const-value ] bi define-constant ;
|
||||
[ c-identifier>> create-in dup ] [ const-value ] bi
|
||||
define-constant ;
|
||||
|
||||
: define-ffi-consts ( consts -- )
|
||||
[ define-ffi-const ] define-each ;
|
||||
|
@ -210,7 +214,6 @@ IN: gir.ffi
|
|||
: prepare-vocab ( repository -- )
|
||||
includes>> lib-aliases get '[ _ at ] map sift
|
||||
[ ffi-vocab "." glue ] map
|
||||
! { "alien.c-types" } append
|
||||
[ dup using-vocab? [ drop ] [ use-vocab ] if ] each ;
|
||||
|
||||
: define-ffi-namespace ( namespace -- )
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2009 Anton Gorenko.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs combinators gir.common gir.ffi gir.loader
|
||||
kernel lexer locals namespaces prettyprint sequences vocabs.parser xml ;
|
||||
kernel lexer locals namespaces sequences vocabs.parser xml ;
|
||||
IN: gir
|
||||
|
||||
: with-child-vocab ( name quot -- )
|
||||
|
@ -12,7 +12,6 @@ IN: gir
|
|||
:: define-gir-vocab ( vocab-name file-name -- )
|
||||
file-name file>xml xml>repository
|
||||
|
||||
implement-structs get-global .
|
||||
vocab-name [ set-current-vocab ] [ current-lib set ] bi
|
||||
{
|
||||
[
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
! Copyright (C) 2009 Anton Gorenko.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors ascii combinators fry gir.common gir.repository
|
||||
gir.types kernel math math.parser sequences splitting xml.data
|
||||
gir.types kernel math.parser sequences splitting xml.data
|
||||
xml.traversal ;
|
||||
FROM: namespaces => set get ;
|
||||
IN: gir.loader
|
||||
|
||||
SYMBOL: namespace-prefix
|
||||
SYMBOL: namespace-PREFIX
|
||||
|
||||
: word-started? ( word letter -- ? )
|
||||
[ last letter? ] [ LETTER? ] bi* and ;
|
||||
|
||||
: camel>PREFIX ( name -- name' )
|
||||
dup 1 head
|
||||
[ 2dup word-started? [ [ CHAR: _ suffix ] dip ] when suffix ]
|
||||
reduce rest >upper ;
|
||||
|
||||
: set-prefix ( prefix -- )
|
||||
[ namespace-prefix set ]
|
||||
[ camel>PREFIX namespace-PREFIX set ] bi ;
|
||||
|
||||
: camel>factor ( name -- name' )
|
||||
dup 1 head
|
||||
[ 2dup word-started? [ [ CHAR: - suffix ] dip ] when suffix ]
|
||||
|
@ -231,6 +243,10 @@ IN: gir.loader
|
|||
: xml>const ( xml -- const )
|
||||
[ const new ] dip {
|
||||
[ "name" attr >>name ]
|
||||
[
|
||||
"name" attr namespace-PREFIX get swap "_" glue
|
||||
>>c-identifier
|
||||
]
|
||||
[ "value" attr >>value ]
|
||||
[ first-child-tag "type" attr >>c-type ]
|
||||
[ first-child-tag xml>type nip >>type ]
|
||||
|
@ -239,6 +255,7 @@ IN: gir.loader
|
|||
: xml>namespace ( xml -- namespace )
|
||||
[ namespace new ] dip {
|
||||
[ "name" attr camel>factor dup current-lib set >>name ]
|
||||
[ "prefix" attr [ set-prefix ] keep >>prefix ]
|
||||
[ "alias" tags-named [ xml>alias ] map >>aliases ]
|
||||
[ "record" tags-named [ xml>record ] map >>records ]
|
||||
[ "union" tags-named [ xml>union ] map >>unions ]
|
||||
|
|
|
@ -8,14 +8,15 @@ TUPLE: node name ;
|
|||
TUPLE: repository includes namespace ;
|
||||
|
||||
TUPLE: namespace < node
|
||||
aliases consts classes interfaces records unions callbacks
|
||||
prefix aliases consts classes interfaces records unions callbacks
|
||||
enums bitfields functions ;
|
||||
|
||||
TUPLE: alias < node target ;
|
||||
|
||||
TUPLE: typed < node type c-type ;
|
||||
|
||||
TUPLE: const < typed value ffi ;
|
||||
TUPLE: const < typed
|
||||
value c-identifier ffi ;
|
||||
|
||||
TUPLE: type-node < node
|
||||
type c-type type-name get-type ffi ;
|
||||
|
|
|
@ -133,3 +133,4 @@ PREDICATE: interface-type < type get-type-info interface-info? ;
|
|||
[ namespace>> ] [ simple-type? ]
|
||||
[ utf8-type? ] [ none-type? ]
|
||||
} 1|| [ current-lib get >>namespace ] unless ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue