-! Copyright (C) 2009 Anton Gorenko.
+! Copyright (C) 2010 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 strings.parser vocabs.parser xml ;
+USING: accessors combinators environment
+gobject-introspection.common gobject-introspection.ffi
+gobject-introspection.loader gobject-introspection.types io
+io.files io.pathnames kernel lexer make namespaces parser
+sequences splitting summary vocabs vocabs.parser xdg xml ;
IN: gobject-introspection
-: with-child-vocab ( name quot -- )
- swap current-vocab name>>
- [ swap "." glue set-current-vocab call ] keep
- set-current-vocab ; inline
+ERROR: gir-not-found name paths ;
-:: define-gir-vocab ( file-name -- )
- file-name file>xml xml>repository
+M: gir-not-found summary
+ [ name>> "“" "” file not found on paths:\n" surround ]
+ [ paths>> join-lines ] bi
+ "\n\nUse the existing path or declare GIR_DIRS environment variable"
+ 3append ;
- current-vocab name>> dup ffi-vocab tail?
- [ ffi-vocab length 1 + head* current-lib set-global ]
- [ drop ] if ! throw the error
+<PRIVATE
+
+: system-gir-dirs ( -- dirs )
+ xdg-data-dirs [ "gir-1.0" append-path ] map ;
+
+: custom-gir-dirs ( -- dirs )
+ "GIR_DIRS" os-env ":" split ;
+
+: current-vocab-path ( -- path )
+ current-vocab vocab-name "." split "/" join vocab-path ;
+
+: current-vocab-dirs ( -- dirs )
+ [
+ current-vocab-path
+ [ , ] [ "/ffi" ?tail [ , ] [ drop ] if ] bi
+ ] { } make ;
+
+:: resolve-gir-path ( path -- path )
+ path file-exists?
+ [ path ] [
+ current-vocab-dirs custom-gir-dirs system-gir-dirs
+ 3append sift :> paths
+ paths [ path append-path file-exists? ] find nip
+ [ path append-path ] [ path paths gir-not-found ] if*
+ ] if ;
+
+: define-gir-vocab ( path -- )
+ resolve-gir-path dup "Loading " write print
+ file>xml xml>repository
{
- [ define-ffi-repository ]
+ [ namespace>> name>> current-namespace-name set-global ]
+ [ def-ffi-repository ]
} cleave
- V{ } clone implement-structs set-global
- H{ } clone replaced-c-types set-global ;
+ V{ } clone implement-structs set-global ;
+
+PRIVATE>
-SYNTAX: GIR: scan define-gir-vocab ;
+SYNTAX: GIR: scan-token define-gir-vocab ;
SYNTAX: IMPLEMENT-STRUCTS:
";" parse-tokens
implement-structs [ swap append! ] change-global ;
-SYNTAX: REPLACE-C-TYPE:
- scan unescape-string scan swap
- replaced-c-types get-global set-at ;
+SYNTAX: FOREIGN-ATOMIC-TYPE:
+ scan-token scan-object swap register-atomic-type ;
+
+SYNTAX: FOREIGN-ENUM-TYPE:
+ scan-token scan-object swap register-enum-type ;
+
+SYNTAX: FOREIGN-RECORD-TYPE:
+ scan-token scan-object swap register-record-type ;