]> gitweb.factorcode.org Git - factor.git/commitdiff
rename gir to gobject-introspection
authorAnton Gorenko <ex.rzrjck@gmail.com>
Sat, 17 Jul 2010 11:17:03 +0000 (17:17 +0600)
committerAnton Gorenko <ex.rzrjck@gmail.com>
Sat, 17 Jul 2010 11:17:03 +0000 (17:17 +0600)
29 files changed:
basis/atk/ffi/ffi.factor
basis/gdk/ffi/ffi.factor
basis/gdk/gl/ffi/ffi.factor
basis/gdk/pixbuf/ffi/ffi.factor
basis/gio/ffi/ffi.factor
basis/gir/authors.txt [deleted file]
basis/gir/common/common.factor [deleted file]
basis/gir/ffi/ffi.factor [deleted file]
basis/gir/gir.factor [deleted file]
basis/gir/loader/loader.factor [deleted file]
basis/gir/repository/repository.factor [deleted file]
basis/gir/summary.txt [deleted file]
basis/gir/types/types.factor [deleted file]
basis/glib/ffi/ffi.factor
basis/gmodule/ffi/ffi.factor
basis/gobject-introspection/authors.txt [new file with mode: 0644]
basis/gobject-introspection/common/common.factor [new file with mode: 0644]
basis/gobject-introspection/ffi/ffi.factor [new file with mode: 0644]
basis/gobject-introspection/gobject-introspection.factor [new file with mode: 0755]
basis/gobject-introspection/loader/loader.factor [new file with mode: 0644]
basis/gobject-introspection/repository/repository.factor [new file with mode: 0644]
basis/gobject-introspection/summary.txt [new file with mode: 0644]
basis/gobject-introspection/types/types.factor [new file with mode: 0644]
basis/gobject/ffi/ffi.factor
basis/gst/ffi/ffi.factor
basis/gtk/ffi/ffi.factor
basis/gtk/gl/ffi/ffi.factor
basis/pango/cairo/ffi/ffi.factor
basis/pango/ffi/ffi.factor

index fa3dd6910f2e7d989d3a8bde0a94da01b93d078d..67c8362c73305add541d2264d1b22d902e4a8eef 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.libraries alien.syntax combinators kernel
 system
-gir glib.ffi gobject.ffi ;
+gobject-introspection glib.ffi gobject.ffi ;
 IN: atk.ffi
 
 <<
index d67f61f585dba138754968973ee322a0ca83a241..11dbbc6fdb6efda957829ff1413e7c255f0d23a7 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.destructors alien.syntax
 alien.libraries cairo.ffi combinators kernel system
-gir gdk.pixbuf.ffi gio.ffi glib.ffi gmodule.ffi gobject.ffi
-pango.ffi ;
+gobject-introspection gdk.pixbuf.ffi gio.ffi glib.ffi gmodule.ffi
+gobject.ffi pango.ffi ;
 IN: gdk.ffi
 
 <<
index 5c57fe00135a855907c133efbd7ad4ddb8130b3c..74fa46a3b75d06bd17fa6c98871f8325ee5c593e 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.libraries combinators kernel
 system vocabs.parser words
-gir gdk.ffi gdk.pixbuf.ffi gio.ffi glib.ffi gmodule.ffi
-gobject.ffi pango.ffi ;
+gobject-introspection gdk.ffi gdk.pixbuf.ffi gio.ffi glib.ffi
+gmodule.ffi gobject.ffi pango.ffi ;
 IN: gdk.gl.ffi
 
 <<
index 12e56753e15dd8035b40e85139f4b8e70364aa84..a87ca77c3b108bb7da57ec3c31d21e087bfa9695 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.libraries combinators kernel system
-gir gio.ffi glib.ffi gmodule.ffi gobject.ffi ;
+gobject-introspection gio.ffi glib.ffi gmodule.ffi gobject.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gdk.pixbuf.ffi
 
index 16056f1fb5357e04aafae1d00aece33b5d7d5404..e4d9b73fd09cbfe84c30c089b1a9a802bac09d0c 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.libraries combinators kernel system
-gir glib.ffi gobject.ffi ;
+gobject-introspection glib.ffi gobject.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gio.ffi
 
diff --git a/basis/gir/authors.txt b/basis/gir/authors.txt
deleted file mode 100644 (file)
index ce9bcc8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Anton Gorenko
\ No newline at end of file
diff --git a/basis/gir/common/common.factor b/basis/gir/common/common.factor
deleted file mode 100644 (file)
index d498460..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-! Copyright (C) 2010 Anton Gorenko.
-! See http://factorcode.org/license.txt for BSD license.
-USING: assocs kernel namespaces ;
-IN: gir.common
-
-CONSTANT: ffi-vocab "ffi"
-
-SYMBOL: current-lib
-
-SYMBOL: type-infos
-type-infos [ H{ } ] initialize
-
-SYMBOL: aliases
-aliases [ H{ } ] initialize
-
-SYMBOL: implement-structs
-
diff --git a/basis/gir/ffi/ffi.factor b/basis/gir/ffi/ffi.factor
deleted file mode 100644 (file)
index 4ee7f35..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-! Copyright (C) 2009 Anton Gorenko.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.parser arrays
-classes.parser classes.struct combinators combinators.short-circuit
-definitions effects fry gir.common gir.types kernel math.parser
-namespaces parser quotations sequences sequences.generalizations words
-words.constant ;
-IN: gir.ffi
-
-: string>c-type ( str -- c-type )
-    parse-c-type ;
-    
-: define-each ( nodes quot -- )
-    '[ dup @ >>ffi drop ] each ; inline
-
-: function-ffi-invoker ( func -- quot )
-    {
-        [ return>> c-type>> string>c-type ]
-        [ drop current-lib get-global ]
-        [ identifier>> ]
-        [ parameters>> [ c-type>> string>c-type ] map ]
-        [ varargs?>> [ void* suffix ] when ]
-    } cleave function-quot ;
-
-: function-ffi-effect ( func -- effect )
-    [ parameters>> [ name>> ] map ]
-    [ varargs?>> [ "varargs" suffix ] when ]
-    [ return>> type>> none-type? { } { "result" } ? ] tri
-    <effect> ;
-
-: define-ffi-function ( func -- word )
-    [ identifier>> create-in dup ]
-    [ function-ffi-invoker ] [ function-ffi-effect ] tri
-    define-declared ;
-
-: define-ffi-functions ( functions -- )
-    [ define-ffi-function ] define-each ;
-
-: callback-ffi-invoker ( callback -- quot )
-    [ return>> c-type>> string>c-type ]
-    [ parameters>> [ c-type>> string>c-type ] map ] bi
-    cdecl callback-quot ;
-
-: callback-ffi-effect ( callback -- effect )
-    [ parameters>> [ name>> ] map ]
-    [ return>> type>> none-type? { } { "result" } ? ] bi
-    <effect> ;
-
-: define-ffi-callback ( callback -- word )
-    [ c-type>> create-in [ void* swap typedef ] keep dup ] keep
-    [ callback-ffi-effect "callback-effect" set-word-prop ]
-    [ drop current-lib get-global "callback-library" set-word-prop ] 
-    [ callback-ffi-invoker (( quot -- alien )) define-inline ] 2tri ;
-
-: fix-signal-param-c-type ( param -- )
-    dup [ c-type>> ] [ type>> ] bi
-    {
-        [ none-type? ]
-        [ simple-type? ]
-        [ enum-type? ]
-        [ bitfield-type? ]
-    } 1|| [ dup "*" tail? [ CHAR: * suffix ] unless ] unless
-    >>c-type drop ;
-
-: define-ffi-signal ( signal -- word )
-    [ return>> fix-signal-param-c-type ]
-    [ parameters>> [ fix-signal-param-c-type ] each ]
-    [ define-ffi-callback ] tri ;
-    
-: define-ffi-signals ( signals -- )
-    [ define-ffi-signal ] define-each ;
-
-: const-value ( const -- value )
-    [ value>> ] [ type>> name>> ] bi {
-        { "int" [ string>number ] }
-        { "double" [ string>number ] }
-        { "utf8" [ ] }
-    } case ;
-
-: define-ffi-enum ( enum -- word )
-    [
-       members>> [
-           [ c-identifier>> create-in ]
-           [ value>> ] bi define-constant
-       ] each 
-    ] [ c-type>> (CREATE-C-TYPE) [ int swap typedef ] keep ] bi ;
-
-: define-ffi-enums ( enums -- )
-    [ define-ffi-enum ] define-each ;
-    
-: define-ffi-bitfields ( bitfields -- )
-    [ define-ffi-enum ] define-each ;
-
-: fields>struct-slots ( fields -- slots )
-    [
-        [ name>> ]
-        [
-            [ c-type>> string>c-type ] [ array-info>> ] bi
-            [ fixed-size>> [ 2array ] when* ] when*
-        ]
-        [ drop { } ] tri <struct-slot-spec>
-    ] map ;
-
-: define-ffi-record-defer ( record -- word )
-    c-type>> create-in void* swap [ typedef ] keep ;
-
-: define-ffi-records-defer ( records -- )
-    [ define-ffi-record-defer ] define-each ;
-
-: define-ffi-record ( record -- word )
-    dup ffi>> forget
-    dup {
-        [ fields>> empty? not ]
-        [ c-type>> implement-structs get-global member? ]
-    } 1&&
-    [
-        [ c-type>> create-class-in dup ]
-        [ fields>> fields>struct-slots ] bi define-struct-class        
-    ] [
-        [ disguised?>> void* void ? ]
-        [ c-type>> create-in ] bi [ typedef ] keep
-    ] if ;
-
-: define-ffi-records ( records -- )
-    [ define-ffi-record ] define-each ;
-
-: define-ffi-record-content ( record -- )
-    {
-        [ constructors>> define-ffi-functions ]
-        [ functions>> define-ffi-functions ]
-        [ methods>> define-ffi-functions ]
-    } cleave ;
-
-: define-ffi-records-content ( records -- )
-    [ define-ffi-record-content ] each ;
-
-: define-ffi-union ( union -- word )
-    c-type>> create-in [ void* swap typedef ] keep ;
-
-: define-ffi-unions ( unions -- )
-    [ define-ffi-union ] define-each ;
-
-: define-ffi-callbacks ( callbacks -- )
-    [ define-ffi-callback ] define-each ;
-
-: define-ffi-interface ( interface -- word )
-    c-type>> create-in [ void swap typedef ] keep ;
-
-: define-ffi-interfaces ( interfaces -- )
-    [ define-ffi-interface ] define-each ;
-
-: define-ffi-interface-content ( interface -- )
-    {
-        [ methods>> define-ffi-functions ]
-    } cleave ;
-
-: define-ffi-interfaces-content ( interfaces -- )
-    [ define-ffi-interface-content ] each ;
-
-: get-type-invoker ( name -- quot )
-    [ "GType" current-lib get-global ] dip
-    { } \ alien-invoke 5 narray >quotation ;
-    
-: define-ffi-class ( class -- word )
-    c-type>> create-in [ void swap typedef ] keep ;
-
-: define-ffi-classes ( class -- )
-    [ define-ffi-class ] define-each ;
-
-: define-ffi-class-content ( class -- )
-    {
-        [ constructors>> define-ffi-functions ]
-        [ functions>> define-ffi-functions ]
-        [ methods>> define-ffi-functions ]
-        [ signals>> define-ffi-signals ]
-    } cleave ;
-
-: define-ffi-classes-content ( class -- )
-    [ define-ffi-class-content ] each ;
-
-: define-get-type ( node -- word )
-    get-type>> dup { "intern" f } member? [ drop f ]
-    [
-        [ create-in dup ] [ get-type-invoker ] bi
-        { } { "type" } <effect> define-declared
-    ] if ;
-
-: define-get-types ( namespace -- )
-    {
-        [ enums>> [ define-get-type drop ] each ]
-        [ bitfields>> [ define-get-type drop ] each ]
-        [ records>> [ define-get-type drop ] each ]
-        [ unions>> [ define-get-type drop ] each ]
-        [ interfaces>> [ define-get-type drop ] each ]
-        [ classes>> [ define-get-type drop ] each ]
-    } cleave ;
-
-: define-ffi-const ( const -- word )
-    [ c-identifier>> create-in dup ] [ const-value ] bi
-    define-constant ;
-
-: define-ffi-consts ( consts -- )
-    [ define-ffi-const ] define-each ;
-
-: define-ffi-alias ( alias -- )
-    drop ;
-
-: define-ffi-aliases ( aliases -- )
-    [ define-ffi-alias ] each ;
-
-: define-ffi-namespace ( namespace -- )
-    {
-        [ aliases>> define-ffi-aliases ]
-        [ consts>> define-ffi-consts ]
-        [ enums>> define-ffi-enums ]
-        [ bitfields>> define-ffi-bitfields ]
-        
-        [ records>> define-ffi-records-defer ]
-
-        [ unions>> define-ffi-unions ]
-        [ interfaces>> define-ffi-interfaces ]
-        [ classes>> define-ffi-classes ]
-        [ callbacks>> define-ffi-callbacks ]
-        [ records>> define-ffi-records ]
-                
-        [ records>> define-ffi-records-content ]
-        [ classes>> define-ffi-classes-content ]
-        [ interfaces>> define-ffi-interfaces-content ]
-        [ functions>> define-ffi-functions ]
-    } cleave ;
-
-: define-ffi-repository ( repository -- )
-    namespace>> define-ffi-namespace ;
-     
diff --git a/basis/gir/gir.factor b/basis/gir/gir.factor
deleted file mode 100755 (executable)
index 3c39d8d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-! 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 math namespaces sequences vocabs.parser xml ;
-IN: gir
-
-: with-child-vocab ( name quot -- )
-    swap current-vocab name>>
-    [ swap "." glue set-current-vocab call ] keep
-    set-current-vocab ; inline
-
-:: define-gir-vocab ( file-name -- )
-    file-name file>xml xml>repository
-
-    current-vocab name>> dup ffi-vocab tail?
-    [ ffi-vocab length 1 + head* current-lib set-global ]
-    [ drop ] if ! throw the error
-    {
-        [ define-ffi-repository ]
-    } cleave
-    f implement-structs set-global ;
-
-SYNTAX: GIR: scan define-gir-vocab ;
-
-SYNTAX: IMPLEMENT-STRUCTS:
-    ";" parse-tokens implement-structs set-global ;
diff --git a/basis/gir/loader/loader.factor b/basis/gir/loader/loader.factor
deleted file mode 100644 (file)
index 0e9ed62..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-! 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.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 ]
-    reduce rest >lower ;
-
-: underscored>factor ( name -- name' )
-    [ [ CHAR: _ = not ] keep CHAR: - ? ] map >lower ;
-
-: full-type-name>type ( name -- type )
-    [ type new ] dip
-    camel>factor "." split1 dup [ swap ] unless
-    [ >>namespace ] [ >>name ] bi* absolute-type ;
-
-: node>type ( xml -- type )
-    "name" attr full-type-name>type ;
-
-: xml>array-info ( xml -- array-info )
-    [ array-info new ] dip {
-        [ "zero-terminated" attr [ "1" = ] [ t ] if* >>zero-terminated? ]
-        [ "length" attr [ string>number ] [ f ] if* >>length ]
-        [ "fixed-size" attr [ string>number ] [ f ] if* >>fixed-size ]
-    } cleave ;
-
-: xml>type ( xml -- array-info type )
-    dup name>> main>> {
-        { "array"
-            [
-                [ xml>array-info ]
-                [ first-child-tag node>type ] bi
-            ]
-        }
-        { "type" [ node>type f swap ] }
-        { "varargs" [ drop f f ] }
-        { "callback" [ drop f "any" f type boa ] }
-    } case ;
-    
-: load-parameter ( param xml -- param )
-    [ "transfer-ownership" attr >>transfer-ownership ]
-    [ first-child-tag "type" attr >>c-type ]
-    [
-        first-child-tag xml>type
-        [ [ >>array-info ] [ >>type ] bi* ] [ 2drop f ] if*
-    ] tri ;
-
-: load-type ( type xml -- type )
-    {
-        [ "name" attr camel>factor >>name ]
-        [ node>type >>type ]
-        [ "type" attr >>c-type ]
-        [ "type-name" attr >>type-name ]
-        [ "get-type" attr >>get-type ]
-    } cleave ;
-
-: xml>parameter ( xml -- parameter )
-    [ parameter new ] dip {
-        [ "name" attr >>name ]
-        [ "direction" attr dup "in" ? >>direction ]
-        [ "allow-none" attr "1" = >>allow-none? ]
-        [ load-parameter ]
-    } cleave ;
-
-: xml>return ( xml -- return )
-    [ return new ] dip {
-        [ drop "result" >>name ]
-        [ load-parameter ]
-    } cleave ;
-
-: throws-parameter ( -- parameter )
-    parameter new
-        "error" >>name
-        "in" >>direction
-        "none" >>transfer-ownership
-        "GError**" >>c-type
-        "GLib.Error" full-type-name>type >>type ;
-
-: extract-parameters ( xml -- parameters )
-    "parameters" tag-named "parameter" tags-named
-    [ xml>parameter ] map ;
-
-: load-parameters ( callable xml -- callable )
-    [
-        [
-            extract-parameters
-            dup { f } tail? [ but-last [ t >>varargs? ] dip ] when
-        ]
-        [ "throws" attr "1" = [ throws-parameter suffix ] when ] bi
-        >>parameters
-    ]
-    [ "return-value" tag-named xml>return >>return ] bi ;
-
-: xml>function ( xml -- function )
-    [ function new ] dip {
-        [ "name" attr underscored>factor >>name ]
-        [ "identifier" attr >>identifier ]
-        [ load-parameters ]
-    } cleave ;
-
-: (type>param) ( type -- param )
-    [ parameter new ] dip
-    [ c-type>> CHAR: * suffix >>c-type ] [ type>> >>type ] bi
-    "none" >>transfer-ownership
-    "in" >>direction ;
-    
-: type>self-param ( type -- self )
-    (type>param) "self" >>name ;
-
-: type>sender-param ( type -- sender )
-    (type>param) "sender" >>name ;
-
-: signal-data-param ( -- param )
-    parameter new
-    "user_data" >>name
-    "gpointer" >>c-type
-    type new "any" >>name >>type
-    "none" >>transfer-ownership
-    "in" >>direction ;
-
-: xml>property ( xml -- property )
-     [ property new ] dip {
-        [ "name" attr >>name ]
-        [ "writable" attr "1" = >>writable? ]
-        [ "readable" attr "0" = not >>readable? ]
-        [ "construct" attr "1" = >>construct? ]
-        [ "construct-only" attr "1" = >>construct-only? ]
-        [ first-child-tag xml>type nip >>type ]
-    } cleave ;
-
-: xml>callback ( xml -- callback )
-    [ callback new ] dip {
-        [ load-type ]
-        [ load-parameters ]
-    } cleave ;
-
-: xml>signal ( xml -- signal )
-    [ signal new ] dip {
-        [ "name" attr camel>factor >>name ]
-        [ node>type >>type ]
-        [ "type" attr >>c-type ]
-        [
-            load-parameters
-            [ signal-data-param suffix ] change-parameters
-        ]
-    } cleave ;
-
-: load-functions ( xml tag-name -- functions )
-    tags-named [ xml>function ] map ;
-
-: xml>class ( xml -- class )
-    [ class new ] dip {
-        [ load-type ]
-        [ "abstract" attr "1" = >>abstract? ]
-        [
-            "parent" attr [ full-type-name>type ] [ f ] if*
-            >>parent
-        ]
-        [ "type-struct" attr >>type-struct ]
-        [ "constructor" load-functions >>constructors ]
-        [ "function" load-functions >>functions ]
-        [
-            "method" load-functions over type>self-param
-            '[ [ _ prefix ] change-parameters ] map
-            >>methods
-        ]       
-        [
-            "signal" tags-named [ xml>signal ] map
-            over type>sender-param
-            '[ [ _ prefix ] change-parameters ] map
-            over c-type>> CHAR: : suffix
-            '[ dup name>> _ prepend >>c-type ] map
-            >>signals
-        ]
-    } cleave ;
-
-: xml>interface ( xml -- interface )
-    [ interface new ] dip {
-        [ load-type ]
-        [
-            "method" load-functions over type>self-param
-            '[ [ _ prefix ] change-parameters ] map
-            >>methods
-        ] 
-    } cleave ;
-
-: xml>member ( xml -- member )
-    [ enum-member new ] dip {
-        [ "name" attr underscored>factor >>name ]
-        [ "identifier" attr >>c-identifier ]
-        [ "value" attr string>number >>value ]
-    } cleave ;
-
-: xml>enum ( xml -- enum )
-    [ enum new ] dip {
-        [ load-type ]
-        [ "member" tags-named [ xml>member ] map >>members ]
-    } cleave ;
-
-: xml>field ( xml -- field )
-    [ field new ] dip {
-        [ "name" attr >>name ]
-        [ "writable" attr "1" = >>writable? ]
-        ! Для некоторых field  есть callback в качестве типа, решить, как лучше сделать
-        [
-            first-child-tag dup name>> main>> "callback" =
-            [ drop "gpointer" ] [ "type" attr ] if
-            >>c-type
-        ]
-        [
-            first-child-tag xml>type
-            [ [ >>array-info ] [ >>type ] bi* ] [ 2drop f ] if*
-        ]
-    } cleave ;
-
-: xml>record ( xml -- record )
-    [ record new ] dip {
-        [ load-type ]
-        [ "disguised" attr "1" = >>disguised? ]
-        [ "field" tags-named [ xml>field ] map >>fields ]
-        [ "constructor" load-functions >>constructors ]
-        [ "function" load-functions >>functions ]
-        [
-            "method" load-functions over type>self-param
-            '[ [ _ prefix ] change-parameters ] map
-            >>methods
-        ]
-    } cleave ;
-
-: xml>union ( xml -- union )
-    [ union new ] dip load-type ;
-
-: xml>alias ( xml -- alias )
-    [ alias new ] dip {
-        [ node>type >>name ]
-        [ "target" attr full-type-name>type >>target ]
-    } cleave ;
-
-: 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 ]
-    } cleave ;
-
-: xml>namespace ( xml -- namespace )
-    [ namespace new ] dip {
-        [ "name" attr camel>factor >>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 ]
-        [ "callback" tags-named [ xml>callback ] map >>callbacks ]
-        [ "interface" tags-named [ xml>interface ] map >>interfaces ]
-        [ "class" tags-named [ xml>class ] map >>classes ]
-        [ "constant" tags-named [ xml>const ] map >>consts ]
-        [ "enumeration" tags-named [ xml>enum ] map >>enums ]
-        [ "bitfield" tags-named [ xml>enum ] map >>bitfields ]
-        [ "function" load-functions >>functions ]
-    } cleave ;
-
-: xml>repository ( xml -- repository )
-    [ repository new ] dip {
-        [
-            "" "include" f <name> tags-named
-            [ "name" attr camel>factor ] map >>includes
-        ]
-        [ "namespace" tag-named xml>namespace >>namespace ]
-    } cleave ;
-
diff --git a/basis/gir/repository/repository.factor b/basis/gir/repository/repository.factor
deleted file mode 100644 (file)
index 1ff5b2c..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-! Copyright (C) 2009 Anton Gorenko.
-! See http://factorcode.org/license.txt for BSD license.
-USING: ;
-IN: gir.repository
-
-TUPLE: node name ;
-
-TUPLE: repository includes namespace ;
-
-TUPLE: namespace < node
-    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 c-identifier ffi ;
-
-TUPLE: type-node < node
-    type c-type type-name get-type ffi ;
-
-TUPLE: field < typed
-    writable? length? array-info ;
-
-TUPLE: record < type-node
-    fields constructors methods functions disguised? ;
-
-TUPLE: union < type-node ;
-
-TUPLE: class < record
-    abstract? parent type-struct signals ;
-
-TUPLE: interface < type-node
-    methods ;
-
-TUPLE: property < type-node
-    readable? writable? construct? construct-only? ;
-
-TUPLE: callable < type-node
-    return parameters varargs? ;
-
-TUPLE: function < callable identifier ;
-
-TUPLE: callback < type-node return parameters varargs? ;
-
-TUPLE: signal < callback ;
-
-TUPLE: parameter < typed
-    direction allow-none? length? transfer-ownership array-info
-    local ;
-
-TUPLE: return < typed
-    transfer-ownership array-info local ;
-
-TUPLE: type name namespace ;
-
-TUPLE: array-info zero-terminated? fixed-size length ;
-
-TUPLE: enum-member < node value c-identifier ;
-
-TUPLE: enum < type-node members ;
-
diff --git a/basis/gir/summary.txt b/basis/gir/summary.txt
deleted file mode 100644 (file)
index 7be5ede..0000000
+++ /dev/null
@@ -1 +0,0 @@
-GObjectIntrospection support
diff --git a/basis/gir/types/types.factor b/basis/gir/types/types.factor
deleted file mode 100644 (file)
index 219eb3a..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-! Copyright (C) 2009 Anton Gorenko.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types assocs combinators.short-circuit
-gir.common gir.repository kernel namespaces specialized-arrays ;
-IN: gir.types
-
-TUPLE: gwrapper { underlying alien } ;
-TUPLE: grecord < gwrapper ;
-TUPLE: gobject < gwrapper ;
-
-SPECIALIZED-ARRAYS:
-    void* bool int uint char uchar short ushort long ulong
-    longlong ulonglong float double ;
-
-CONSTANT: simple-types H{
-    { "any" {
-        void* *void* >void*-array <direct-void*-array>
-    } }
-    { "boolean" {
-        bool *bool >bool-array <direct-bool-array>
-    } }
-    { "int" {
-        int *int >int-array <direct-int-array>
-    } }
-    { "uint" {
-        uint *uint >uint-array <direct-uint-array>
-    } }
-    { "int8" {
-        char *char >char-array <direct-char-array>
-    } }
-    { "uint8" {
-        uchar *uchar >uchar-array <direct-uchar-array>
-    } }
-    { "int16" {
-        short *short >short-array <direct-short-array>
-    } }
-    { "uint16" {
-        ushort *ushort >ushort-array <direct-ushort-array>
-    } }
-    { "int32" {
-        int *int >int-array <direct-int-array>
-    } }
-    { "uint32" {
-        uint *uint >uint-array <direct-uint-array>
-    } }
-    { "int64" {
-        longlong *longlong
-        >longlong-array <direct-longlong-array>
-    } }
-    { "uint64" {
-        ulonglong *ulonglong
-        >ulonglong-array <direct-ulonglong-array>
-    } }
-    { "long" {
-        long *long >long-array <direct-long-array>
-    } }
-    { "ulong" {
-        ulong *ulong >ulong-array <direct-ulong-array>
-    } }
-    { "float" {
-        float *float >float-array <direct-float-array>
-    } }
-    { "double" {
-        double *double >double-array <direct-double-array>
-    } }
-     { "size_t" {
-        ulong *ulong >ulong-array <direct-ulong-array>
-    } }
-    { "ssize_t" {
-        long *long >long-array <direct-long-array>
-    } }
-    { "time_t" {
-        long *long >long-array <direct-long-array>
-    } }
-     { "gtype" {
-        ulong *ulong >ulong-array <direct-ulong-array>
-    } }    
-}
-
-TUPLE: type-info c-type-word type-word ;
-
-TUPLE: enum-info < type-info ;
-
-TUPLE: bitfield-info < type-info ;
-
-TUPLE: record-info < type-info ;
-
-TUPLE: union-info < type-info ;
-
-TUPLE: callback-info < type-info ;
-
-TUPLE: class-info < type-info ;
-
-TUPLE: interface-info < type-info ;
-
-: aliased-type ( alias -- type )
-    aliases get ?at [ aliased-type ] when ;
-
-: get-type-info ( type -- info )
-    aliased-type type-infos get at ;
-
-PREDICATE: none-type < type
-    [ namespace>> not ] [ name>> "none" = ] bi and ;
-
-PREDICATE: simple-type < type
-    aliased-type
-    [ namespace>> not ] [ name>> simple-types key? ] bi and ;
-
-PREDICATE: utf8-type < type
-    aliased-type
-    [ namespace>> not ] [ name>> "utf8" = ] bi and ;
-
-PREDICATE: any-type < type
-    aliased-type
-    [ namespace>> not ] [ name>> "any" = ] bi and ;
-   
-PREDICATE: enum-type < type get-type-info enum-info? ;
-
-PREDICATE: bitfield-type < type get-type-info bitfield-info? ;
-
-PREDICATE: record-type < type get-type-info record-info? ;
-
-PREDICATE: union-type < type get-type-info union-info? ;
-
-PREDICATE: callback-type < type get-type-info callback-info? ;
-
-PREDICATE: class-type < type get-type-info class-info? ;
-
-PREDICATE: interface-type < type get-type-info interface-info? ;
-
-: absolute-type ( type -- type' )
-    dup {
-        [ namespace>> ] [ simple-type? ]
-        [ utf8-type? ] [ none-type? ]
-    } 1|| [ current-lib get-global >>namespace ] unless ;
-
index 99183a88dc7ada495357e3a68eadc4ad5766be70..d7b265004e934a5a2348bd950e1a66df60aa922a 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.destructors
-alien.libraries alien.syntax combinators compiler.units gir
-kernel system vocabs.parser words ;
+alien.libraries alien.syntax combinators compiler.units
+gobject-introspection kernel system vocabs.parser words ;
 IN: glib.ffi
 
 <<
index 449ef69249fb18ca5e91335146440eae127f2746..5e3334de68eadbad6f39ab795e33800a5474f116 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.libraries combinators kernel system
-gir glib.ffi ;
+gobject-introspection glib.ffi ;
 IN: gmodule.ffi
 
 <<
diff --git a/basis/gobject-introspection/authors.txt b/basis/gobject-introspection/authors.txt
new file mode 100644 (file)
index 0000000..ce9bcc8
--- /dev/null
@@ -0,0 +1 @@
+Anton Gorenko
\ No newline at end of file
diff --git a/basis/gobject-introspection/common/common.factor b/basis/gobject-introspection/common/common.factor
new file mode 100644 (file)
index 0000000..8bf2c7e
--- /dev/null
@@ -0,0 +1,17 @@
+! Copyright (C) 2010 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs kernel namespaces ;
+IN: gobject-introspection.common
+
+CONSTANT: ffi-vocab "ffi"
+
+SYMBOL: current-lib
+
+SYMBOL: type-infos
+type-infos [ H{ } ] initialize
+
+SYMBOL: aliases
+aliases [ H{ } ] initialize
+
+SYMBOL: implement-structs
+
diff --git a/basis/gobject-introspection/ffi/ffi.factor b/basis/gobject-introspection/ffi/ffi.factor
new file mode 100644 (file)
index 0000000..9af0186
--- /dev/null
@@ -0,0 +1,235 @@
+! Copyright (C) 2009 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien alien.c-types alien.parser arrays
+classes.parser classes.struct combinators
+combinators.short-circuit definitions effects fry
+gobject-introspection.common gobject-introspection.types kernel
+math.parser namespaces parser quotations sequences
+sequences.generalizations words words.constant ;
+IN: gobject-introspection.ffi
+
+: string>c-type ( str -- c-type )
+    parse-c-type ;
+    
+: define-each ( nodes quot -- )
+    '[ dup @ >>ffi drop ] each ; inline
+
+: function-ffi-invoker ( func -- quot )
+    {
+        [ return>> c-type>> string>c-type ]
+        [ drop current-lib get-global ]
+        [ identifier>> ]
+        [ parameters>> [ c-type>> string>c-type ] map ]
+        [ varargs?>> [ void* suffix ] when ]
+    } cleave function-quot ;
+
+: function-ffi-effect ( func -- effect )
+    [ parameters>> [ name>> ] map ]
+    [ varargs?>> [ "varargs" suffix ] when ]
+    [ return>> type>> none-type? { } { "result" } ? ] tri
+    <effect> ;
+
+: define-ffi-function ( func -- word )
+    [ identifier>> create-in dup ]
+    [ function-ffi-invoker ] [ function-ffi-effect ] tri
+    define-declared ;
+
+: define-ffi-functions ( functions -- )
+    [ define-ffi-function ] define-each ;
+
+: callback-ffi-invoker ( callback -- quot )
+    [ return>> c-type>> string>c-type ]
+    [ parameters>> [ c-type>> string>c-type ] map ] bi
+    cdecl callback-quot ;
+
+: callback-ffi-effect ( callback -- effect )
+    [ parameters>> [ name>> ] map ]
+    [ return>> type>> none-type? { } { "result" } ? ] bi
+    <effect> ;
+
+: define-ffi-callback ( callback -- word )
+    [ c-type>> create-in [ void* swap typedef ] keep dup ] keep
+    [ callback-ffi-effect "callback-effect" set-word-prop ]
+    [ drop current-lib get-global "callback-library" set-word-prop ] 
+    [ callback-ffi-invoker (( quot -- alien )) define-inline ] 2tri ;
+
+: fix-signal-param-c-type ( param -- )
+    dup [ c-type>> ] [ type>> ] bi
+    {
+        [ none-type? ]
+        [ simple-type? ]
+        [ enum-type? ]
+        [ bitfield-type? ]
+    } 1|| [ dup "*" tail? [ CHAR: * suffix ] unless ] unless
+    >>c-type drop ;
+
+: define-ffi-signal ( signal -- word )
+    [ return>> fix-signal-param-c-type ]
+    [ parameters>> [ fix-signal-param-c-type ] each ]
+    [ define-ffi-callback ] tri ;
+    
+: define-ffi-signals ( signals -- )
+    [ define-ffi-signal ] define-each ;
+
+: const-value ( const -- value )
+    [ value>> ] [ type>> name>> ] bi {
+        { "int" [ string>number ] }
+        { "double" [ string>number ] }
+        { "utf8" [ ] }
+    } case ;
+
+: define-ffi-enum ( enum -- word )
+    [
+       members>> [
+           [ c-identifier>> create-in ]
+           [ value>> ] bi define-constant
+       ] each 
+    ] [ c-type>> (CREATE-C-TYPE) [ int swap typedef ] keep ] bi ;
+
+: define-ffi-enums ( enums -- )
+    [ define-ffi-enum ] define-each ;
+    
+: define-ffi-bitfields ( bitfields -- )
+    [ define-ffi-enum ] define-each ;
+
+: fields>struct-slots ( fields -- slots )
+    [
+        [ name>> ]
+        [
+            [ c-type>> string>c-type ] [ array-info>> ] bi
+            [ fixed-size>> [ 2array ] when* ] when*
+        ]
+        [ drop { } ] tri <struct-slot-spec>
+    ] map ;
+
+: define-ffi-record-defer ( record -- word )
+    c-type>> create-in void* swap [ typedef ] keep ;
+
+: define-ffi-records-defer ( records -- )
+    [ define-ffi-record-defer ] define-each ;
+
+: define-ffi-record ( record -- word )
+    dup ffi>> forget
+    dup {
+        [ fields>> empty? not ]
+        [ c-type>> implement-structs get-global member? ]
+    } 1&&
+    [
+        [ c-type>> create-class-in dup ]
+        [ fields>> fields>struct-slots ] bi define-struct-class        
+    ] [
+        [ disguised?>> void* void ? ]
+        [ c-type>> create-in ] bi [ typedef ] keep
+    ] if ;
+
+: define-ffi-records ( records -- )
+    [ define-ffi-record ] define-each ;
+
+: define-ffi-record-content ( record -- )
+    {
+        [ constructors>> define-ffi-functions ]
+        [ functions>> define-ffi-functions ]
+        [ methods>> define-ffi-functions ]
+    } cleave ;
+
+: define-ffi-records-content ( records -- )
+    [ define-ffi-record-content ] each ;
+
+: define-ffi-union ( union -- word )
+    c-type>> create-in [ void* swap typedef ] keep ;
+
+: define-ffi-unions ( unions -- )
+    [ define-ffi-union ] define-each ;
+
+: define-ffi-callbacks ( callbacks -- )
+    [ define-ffi-callback ] define-each ;
+
+: define-ffi-interface ( interface -- word )
+    c-type>> create-in [ void swap typedef ] keep ;
+
+: define-ffi-interfaces ( interfaces -- )
+    [ define-ffi-interface ] define-each ;
+
+: define-ffi-interface-content ( interface -- )
+    {
+        [ methods>> define-ffi-functions ]
+    } cleave ;
+
+: define-ffi-interfaces-content ( interfaces -- )
+    [ define-ffi-interface-content ] each ;
+
+: get-type-invoker ( name -- quot )
+    [ "GType" current-lib get-global ] dip
+    { } \ alien-invoke 5 narray >quotation ;
+    
+: define-ffi-class ( class -- word )
+    c-type>> create-in [ void swap typedef ] keep ;
+
+: define-ffi-classes ( class -- )
+    [ define-ffi-class ] define-each ;
+
+: define-ffi-class-content ( class -- )
+    {
+        [ constructors>> define-ffi-functions ]
+        [ functions>> define-ffi-functions ]
+        [ methods>> define-ffi-functions ]
+        [ signals>> define-ffi-signals ]
+    } cleave ;
+
+: define-ffi-classes-content ( class -- )
+    [ define-ffi-class-content ] each ;
+
+: define-get-type ( node -- word )
+    get-type>> dup { "intern" f } member? [ drop f ]
+    [
+        [ create-in dup ] [ get-type-invoker ] bi
+        { } { "type" } <effect> define-declared
+    ] if ;
+
+: define-get-types ( namespace -- )
+    {
+        [ enums>> [ define-get-type drop ] each ]
+        [ bitfields>> [ define-get-type drop ] each ]
+        [ records>> [ define-get-type drop ] each ]
+        [ unions>> [ define-get-type drop ] each ]
+        [ interfaces>> [ define-get-type drop ] each ]
+        [ classes>> [ define-get-type drop ] each ]
+    } cleave ;
+
+: define-ffi-const ( const -- word )
+    [ c-identifier>> create-in dup ] [ const-value ] bi
+    define-constant ;
+
+: define-ffi-consts ( consts -- )
+    [ define-ffi-const ] define-each ;
+
+: define-ffi-alias ( alias -- )
+    drop ;
+
+: define-ffi-aliases ( aliases -- )
+    [ define-ffi-alias ] each ;
+
+: define-ffi-namespace ( namespace -- )
+    {
+        [ aliases>> define-ffi-aliases ]
+        [ consts>> define-ffi-consts ]
+        [ enums>> define-ffi-enums ]
+        [ bitfields>> define-ffi-bitfields ]
+        
+        [ records>> define-ffi-records-defer ]
+
+        [ unions>> define-ffi-unions ]
+        [ interfaces>> define-ffi-interfaces ]
+        [ classes>> define-ffi-classes ]
+        [ callbacks>> define-ffi-callbacks ]
+        [ records>> define-ffi-records ]
+                
+        [ records>> define-ffi-records-content ]
+        [ classes>> define-ffi-classes-content ]
+        [ interfaces>> define-ffi-interfaces-content ]
+        [ functions>> define-ffi-functions ]
+    } cleave ;
+
+: define-ffi-repository ( repository -- )
+    namespace>> define-ffi-namespace ;
+     
diff --git a/basis/gobject-introspection/gobject-introspection.factor b/basis/gobject-introspection/gobject-introspection.factor
new file mode 100755 (executable)
index 0000000..f0a5a98
--- /dev/null
@@ -0,0 +1,27 @@
+! Copyright (C) 2009 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs combinators gobject-introspection.common
+gobject-introspection.ffi gobject-introspection.loader
+kernel lexer locals math namespaces sequences vocabs.parser xml ;
+IN: gobject-introspection
+
+: with-child-vocab ( name quot -- )
+    swap current-vocab name>>
+    [ swap "." glue set-current-vocab call ] keep
+    set-current-vocab ; inline
+
+:: define-gir-vocab ( file-name -- )
+    file-name file>xml xml>repository
+
+    current-vocab name>> dup ffi-vocab tail?
+    [ ffi-vocab length 1 + head* current-lib set-global ]
+    [ drop ] if ! throw the error
+    {
+        [ define-ffi-repository ]
+    } cleave
+    f implement-structs set-global ;
+
+SYNTAX: GIR: scan define-gir-vocab ;
+
+SYNTAX: IMPLEMENT-STRUCTS:
+    ";" parse-tokens implement-structs set-global ;
diff --git a/basis/gobject-introspection/loader/loader.factor b/basis/gobject-introspection/loader/loader.factor
new file mode 100644 (file)
index 0000000..7f0b161
--- /dev/null
@@ -0,0 +1,295 @@
+! Copyright (C) 2009 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors ascii combinators fry
+gobject-introspection.common gobject-introspection.repository
+gobject-introspection.types kernel math.parser sequences
+splitting xml.data xml.traversal ;
+FROM: namespaces => set get ;
+IN: gobject-introspection.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 ]
+    reduce rest >lower ;
+
+: underscored>factor ( name -- name' )
+    [ [ CHAR: _ = not ] keep CHAR: - ? ] map >lower ;
+
+: full-type-name>type ( name -- type )
+    [ type new ] dip
+    camel>factor "." split1 dup [ swap ] unless
+    [ >>namespace ] [ >>name ] bi* absolute-type ;
+
+: node>type ( xml -- type )
+    "name" attr full-type-name>type ;
+
+: xml>array-info ( xml -- array-info )
+    [ array-info new ] dip {
+        [ "zero-terminated" attr [ "1" = ] [ t ] if* >>zero-terminated? ]
+        [ "length" attr [ string>number ] [ f ] if* >>length ]
+        [ "fixed-size" attr [ string>number ] [ f ] if* >>fixed-size ]
+    } cleave ;
+
+: xml>type ( xml -- array-info type )
+    dup name>> main>> {
+        { "array"
+            [
+                [ xml>array-info ]
+                [ first-child-tag node>type ] bi
+            ]
+        }
+        { "type" [ node>type f swap ] }
+        { "varargs" [ drop f f ] }
+        { "callback" [ drop f "any" f type boa ] }
+    } case ;
+    
+: load-parameter ( param xml -- param )
+    [ "transfer-ownership" attr >>transfer-ownership ]
+    [ first-child-tag "type" attr >>c-type ]
+    [
+        first-child-tag xml>type
+        [ [ >>array-info ] [ >>type ] bi* ] [ 2drop f ] if*
+    ] tri ;
+
+: load-type ( type xml -- type )
+    {
+        [ "name" attr camel>factor >>name ]
+        [ node>type >>type ]
+        [ "type" attr >>c-type ]
+        [ "type-name" attr >>type-name ]
+        [ "get-type" attr >>get-type ]
+    } cleave ;
+
+: xml>parameter ( xml -- parameter )
+    [ parameter new ] dip {
+        [ "name" attr >>name ]
+        [ "direction" attr dup "in" ? >>direction ]
+        [ "allow-none" attr "1" = >>allow-none? ]
+        [ load-parameter ]
+    } cleave ;
+
+: xml>return ( xml -- return )
+    [ return new ] dip {
+        [ drop "result" >>name ]
+        [ load-parameter ]
+    } cleave ;
+
+: throws-parameter ( -- parameter )
+    parameter new
+        "error" >>name
+        "in" >>direction
+        "none" >>transfer-ownership
+        "GError**" >>c-type
+        "GLib.Error" full-type-name>type >>type ;
+
+: extract-parameters ( xml -- parameters )
+    "parameters" tag-named "parameter" tags-named
+    [ xml>parameter ] map ;
+
+: load-parameters ( callable xml -- callable )
+    [
+        [
+            extract-parameters
+            dup { f } tail? [ but-last [ t >>varargs? ] dip ] when
+        ]
+        [ "throws" attr "1" = [ throws-parameter suffix ] when ] bi
+        >>parameters
+    ]
+    [ "return-value" tag-named xml>return >>return ] bi ;
+
+: xml>function ( xml -- function )
+    [ function new ] dip {
+        [ "name" attr underscored>factor >>name ]
+        [ "identifier" attr >>identifier ]
+        [ load-parameters ]
+    } cleave ;
+
+: (type>param) ( type -- param )
+    [ parameter new ] dip
+    [ c-type>> CHAR: * suffix >>c-type ] [ type>> >>type ] bi
+    "none" >>transfer-ownership
+    "in" >>direction ;
+    
+: type>self-param ( type -- self )
+    (type>param) "self" >>name ;
+
+: type>sender-param ( type -- sender )
+    (type>param) "sender" >>name ;
+
+: signal-data-param ( -- param )
+    parameter new
+    "user_data" >>name
+    "gpointer" >>c-type
+    type new "any" >>name >>type
+    "none" >>transfer-ownership
+    "in" >>direction ;
+
+: xml>property ( xml -- property )
+     [ property new ] dip {
+        [ "name" attr >>name ]
+        [ "writable" attr "1" = >>writable? ]
+        [ "readable" attr "0" = not >>readable? ]
+        [ "construct" attr "1" = >>construct? ]
+        [ "construct-only" attr "1" = >>construct-only? ]
+        [ first-child-tag xml>type nip >>type ]
+    } cleave ;
+
+: xml>callback ( xml -- callback )
+    [ callback new ] dip {
+        [ load-type ]
+        [ load-parameters ]
+    } cleave ;
+
+: xml>signal ( xml -- signal )
+    [ signal new ] dip {
+        [ "name" attr camel>factor >>name ]
+        [ node>type >>type ]
+        [ "type" attr >>c-type ]
+        [
+            load-parameters
+            [ signal-data-param suffix ] change-parameters
+        ]
+    } cleave ;
+
+: load-functions ( xml tag-name -- functions )
+    tags-named [ xml>function ] map ;
+
+: xml>class ( xml -- class )
+    [ class new ] dip {
+        [ load-type ]
+        [ "abstract" attr "1" = >>abstract? ]
+        [
+            "parent" attr [ full-type-name>type ] [ f ] if*
+            >>parent
+        ]
+        [ "type-struct" attr >>type-struct ]
+        [ "constructor" load-functions >>constructors ]
+        [ "function" load-functions >>functions ]
+        [
+            "method" load-functions over type>self-param
+            '[ [ _ prefix ] change-parameters ] map
+            >>methods
+        ]       
+        [
+            "signal" tags-named [ xml>signal ] map
+            over type>sender-param
+            '[ [ _ prefix ] change-parameters ] map
+            over c-type>> CHAR: : suffix
+            '[ dup name>> _ prepend >>c-type ] map
+            >>signals
+        ]
+    } cleave ;
+
+: xml>interface ( xml -- interface )
+    [ interface new ] dip {
+        [ load-type ]
+        [
+            "method" load-functions over type>self-param
+            '[ [ _ prefix ] change-parameters ] map
+            >>methods
+        ] 
+    } cleave ;
+
+: xml>member ( xml -- member )
+    [ enum-member new ] dip {
+        [ "name" attr underscored>factor >>name ]
+        [ "identifier" attr >>c-identifier ]
+        [ "value" attr string>number >>value ]
+    } cleave ;
+
+: xml>enum ( xml -- enum )
+    [ enum new ] dip {
+        [ load-type ]
+        [ "member" tags-named [ xml>member ] map >>members ]
+    } cleave ;
+
+: xml>field ( xml -- field )
+    [ field new ] dip {
+        [ "name" attr >>name ]
+        [ "writable" attr "1" = >>writable? ]
+        [
+            first-child-tag dup name>> main>> "callback" =
+            [ drop "gpointer" ] [ "type" attr ] if
+            >>c-type
+        ]
+        [
+            first-child-tag xml>type
+            [ [ >>array-info ] [ >>type ] bi* ] [ 2drop f ] if*
+        ]
+    } cleave ;
+
+: xml>record ( xml -- record )
+    [ record new ] dip {
+        [ load-type ]
+        [ "disguised" attr "1" = >>disguised? ]
+        [ "field" tags-named [ xml>field ] map >>fields ]
+        [ "constructor" load-functions >>constructors ]
+        [ "function" load-functions >>functions ]
+        [
+            "method" load-functions over type>self-param
+            '[ [ _ prefix ] change-parameters ] map
+            >>methods
+        ]
+    } cleave ;
+
+: xml>union ( xml -- union )
+    [ union new ] dip load-type ;
+
+: xml>alias ( xml -- alias )
+    [ alias new ] dip {
+        [ node>type >>name ]
+        [ "target" attr full-type-name>type >>target ]
+    } cleave ;
+
+: 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 ]
+    } cleave ;
+
+: xml>namespace ( xml -- namespace )
+    [ namespace new ] dip {
+        [ "name" attr camel>factor >>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 ]
+        [ "callback" tags-named [ xml>callback ] map >>callbacks ]
+        [ "interface" tags-named [ xml>interface ] map >>interfaces ]
+        [ "class" tags-named [ xml>class ] map >>classes ]
+        [ "constant" tags-named [ xml>const ] map >>consts ]
+        [ "enumeration" tags-named [ xml>enum ] map >>enums ]
+        [ "bitfield" tags-named [ xml>enum ] map >>bitfields ]
+        [ "function" load-functions >>functions ]
+    } cleave ;
+
+: xml>repository ( xml -- repository )
+    [ repository new ] dip {
+        [
+            "" "include" f <name> tags-named
+            [ "name" attr camel>factor ] map >>includes
+        ]
+        [ "namespace" tag-named xml>namespace >>namespace ]
+    } cleave ;
+
diff --git a/basis/gobject-introspection/repository/repository.factor b/basis/gobject-introspection/repository/repository.factor
new file mode 100644 (file)
index 0000000..e6b2de7
--- /dev/null
@@ -0,0 +1,64 @@
+! Copyright (C) 2009 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: ;
+IN: gobject-introspection.repository
+
+TUPLE: node name ;
+
+TUPLE: repository includes namespace ;
+
+TUPLE: namespace < node
+    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 c-identifier ffi ;
+
+TUPLE: type-node < node
+    type c-type type-name get-type ffi ;
+
+TUPLE: field < typed
+    writable? length? array-info ;
+
+TUPLE: record < type-node
+    fields constructors methods functions disguised? ;
+
+TUPLE: union < type-node ;
+
+TUPLE: class < record
+    abstract? parent type-struct signals ;
+
+TUPLE: interface < type-node
+    methods ;
+
+TUPLE: property < type-node
+    readable? writable? construct? construct-only? ;
+
+TUPLE: callable < type-node
+    return parameters varargs? ;
+
+TUPLE: function < callable identifier ;
+
+TUPLE: callback < type-node return parameters varargs? ;
+
+TUPLE: signal < callback ;
+
+TUPLE: parameter < typed
+    direction allow-none? length? transfer-ownership array-info
+    local ;
+
+TUPLE: return < typed
+    transfer-ownership array-info local ;
+
+TUPLE: type name namespace ;
+
+TUPLE: array-info zero-terminated? fixed-size length ;
+
+TUPLE: enum-member < node value c-identifier ;
+
+TUPLE: enum < type-node members ;
+
diff --git a/basis/gobject-introspection/summary.txt b/basis/gobject-introspection/summary.txt
new file mode 100644 (file)
index 0000000..7be5ede
--- /dev/null
@@ -0,0 +1 @@
+GObjectIntrospection support
diff --git a/basis/gobject-introspection/types/types.factor b/basis/gobject-introspection/types/types.factor
new file mode 100644 (file)
index 0000000..f6d2257
--- /dev/null
@@ -0,0 +1,138 @@
+! Copyright (C) 2009 Anton Gorenko.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien alien.c-types assocs
+combinators.short-circuit gobject-introspection.common
+gobject-introspection.repository kernel namespaces
+specialized-arrays ;
+IN: gobject-introspection.types
+
+TUPLE: gwrapper { underlying alien } ;
+TUPLE: grecord < gwrapper ;
+TUPLE: gobject < gwrapper ;
+
+SPECIALIZED-ARRAYS:
+    void* bool int uint char uchar short ushort long ulong
+    longlong ulonglong float double ;
+
+CONSTANT: simple-types H{
+    { "any" {
+        void* *void* >void*-array <direct-void*-array>
+    } }
+    { "boolean" {
+        bool *bool >bool-array <direct-bool-array>
+    } }
+    { "int" {
+        int *int >int-array <direct-int-array>
+    } }
+    { "uint" {
+        uint *uint >uint-array <direct-uint-array>
+    } }
+    { "int8" {
+        char *char >char-array <direct-char-array>
+    } }
+    { "uint8" {
+        uchar *uchar >uchar-array <direct-uchar-array>
+    } }
+    { "int16" {
+        short *short >short-array <direct-short-array>
+    } }
+    { "uint16" {
+        ushort *ushort >ushort-array <direct-ushort-array>
+    } }
+    { "int32" {
+        int *int >int-array <direct-int-array>
+    } }
+    { "uint32" {
+        uint *uint >uint-array <direct-uint-array>
+    } }
+    { "int64" {
+        longlong *longlong
+        >longlong-array <direct-longlong-array>
+    } }
+    { "uint64" {
+        ulonglong *ulonglong
+        >ulonglong-array <direct-ulonglong-array>
+    } }
+    { "long" {
+        long *long >long-array <direct-long-array>
+    } }
+    { "ulong" {
+        ulong *ulong >ulong-array <direct-ulong-array>
+    } }
+    { "float" {
+        float *float >float-array <direct-float-array>
+    } }
+    { "double" {
+        double *double >double-array <direct-double-array>
+    } }
+     { "size_t" {
+        ulong *ulong >ulong-array <direct-ulong-array>
+    } }
+    { "ssize_t" {
+        long *long >long-array <direct-long-array>
+    } }
+    { "time_t" {
+        long *long >long-array <direct-long-array>
+    } }
+     { "gtype" {
+        ulong *ulong >ulong-array <direct-ulong-array>
+    } }    
+}
+
+TUPLE: type-info c-type-word type-word ;
+
+TUPLE: enum-info < type-info ;
+
+TUPLE: bitfield-info < type-info ;
+
+TUPLE: record-info < type-info ;
+
+TUPLE: union-info < type-info ;
+
+TUPLE: callback-info < type-info ;
+
+TUPLE: class-info < type-info ;
+
+TUPLE: interface-info < type-info ;
+
+: aliased-type ( alias -- type )
+    aliases get ?at [ aliased-type ] when ;
+
+: get-type-info ( type -- info )
+    aliased-type type-infos get at ;
+
+PREDICATE: none-type < type
+    [ namespace>> not ] [ name>> "none" = ] bi and ;
+
+PREDICATE: simple-type < type
+    aliased-type
+    [ namespace>> not ] [ name>> simple-types key? ] bi and ;
+
+PREDICATE: utf8-type < type
+    aliased-type
+    [ namespace>> not ] [ name>> "utf8" = ] bi and ;
+
+PREDICATE: any-type < type
+    aliased-type
+    [ namespace>> not ] [ name>> "any" = ] bi and ;
+   
+PREDICATE: enum-type < type get-type-info enum-info? ;
+
+PREDICATE: bitfield-type < type get-type-info bitfield-info? ;
+
+PREDICATE: record-type < type get-type-info record-info? ;
+
+PREDICATE: union-type < type get-type-info union-info? ;
+
+PREDICATE: callback-type < type get-type-info callback-info? ;
+
+PREDICATE: class-type < type get-type-info class-info? ;
+
+PREDICATE: interface-type < type get-type-info interface-info? ;
+
+: absolute-type ( type -- type' )
+    dup {
+        [ namespace>> ] [ simple-type? ]
+        [ utf8-type? ] [ none-type? ]
+    } 1|| [ current-lib get-global >>namespace ] unless ;
+
index c82ec75412885f42524509d89f8e14e9d4cc6978..2904ceb833bdfca7634306a4286192c470c7ad1b 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax alien.destructors alien.libraries
 combinators kernel literals math system
-gir glib.ffi ;
+gobject-introspection glib.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gobject.ffi
 
index fa110b3a5d50e6bc95f465d67cb850b6ea36e670..0bb365a755019ebd7d4b68207618837040a19d69 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax alien.libraries combinators kernel
 system
-gir glib.ffi gmodule.ffi gobject.ffi ;
+gobject-introspection glib.ffi gmodule.ffi gobject.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gst.ffi
 
@@ -18,7 +18,7 @@ TYPEDEF: gpointer GstClockID
 TYPEDEF: guint64 GstClockTime
 TYPEDEF: gint64 GstClockTimeDiff
 
-! Временное исправление отсутвующих типов libxml2
+! types from libxml2
 TYPEDEF: void* xmlNodePtr
 TYPEDEF: void* xmlDocPtr
 TYPEDEF: void* xmlNsPtr
index 98ea4a408b8659471e7d056ae9f0fb706231b658..e6490256706529a3ce311bf45fcaca51a989c620 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax alien.destructors alien.libraries
 cairo.ffi combinators kernel system
-gir atk.ffi gdk.ffi gdk.pixbuf.ffi gio.ffi glib.ffi gmodule.ffi
-gobject.ffi pango.ffi ;
+gobject-introspection atk.ffi gdk.ffi gdk.pixbuf.ffi gio.ffi
+glib.ffi gmodule.ffi gobject.ffi pango.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gtk.ffi
 
index 9997ce81ad72375d980112d6590488ff97c6b906..775537063b4627d23147bfc9c174133e8ebcd837 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2010 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.libraries combinators kernel system
-gir gdk.ffi gdk.pixbuf.ffi gdk.gl.ffi gio.ffi glib.ffi
-gmodule.ffi gobject.ffi gtk.ffi ;
+gobject-introspection gdk.ffi gdk.pixbuf.ffi gdk.gl.ffi gio.ffi
+glib.ffi gmodule.ffi gobject.ffi gtk.ffi ;
 EXCLUDE: alien.c-types => pointer ;
 IN: gtk.gl.ffi
 
index 2361fe5de4e1f0b51832c655033bfbbfa55e185d..c37a08b6d6f82397777f9e9bf48b87cc12832a77 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.libraries alien.syntax cairo.ffi
 combinators kernel system
-gir pango.ffi ;
+gobject-introspection pango.ffi ;
 IN: pango.cairo.ffi
 
 << 
index d174ac44881d10e765bdb909a918da96e42304af..e6c794e8bf846cd83e30a869050b578090bb80c1 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.destructors alien.libraries
 alien.syntax combinators kernel system
-gir glib.ffi ;
+gobject-introspection glib.ffi ;
 IN: pango.ffi
 
 << 
@@ -13,7 +13,7 @@ IN: pango.ffi
 } cond 
 >>
 
-TYPEDEF: void PangoLayoutRun ! не совсем верно
+TYPEDEF: void PangoLayoutRun
 TYPEDEF: guint32 PangoGlyph
 
 IMPLEMENT-STRUCTS: PangoRectangle ;