]> gitweb.factorcode.org Git - factor.git/commitdiff
update code for usages of add-library
authorDoug Coleman <erg@jobim.local>
Thu, 26 Mar 2009 04:00:19 +0000 (23:00 -0500)
committerDoug Coleman <erg@jobim.local>
Thu, 26 Mar 2009 04:00:19 +0000 (23:00 -0500)
26 files changed:
basis/alien/syntax/syntax.factor
basis/cairo/ffi/ffi.factor
basis/compiler/codegen/codegen.factor
basis/compression/zlib/ffi/ffi.factor
basis/core-text/utilities/utilities.factor
basis/db/postgresql/ffi/ffi.factor
basis/db/sqlite/ffi/ffi.factor
basis/debugger/debugger-docs.factor
basis/glib/glib.factor
basis/opengl/gl/macosx/macosx.factor
basis/openssl/libcrypto/libcrypto.factor
basis/openssl/libssl/libssl.factor
basis/pango/pango.factor
basis/stack-checker/alien/alien.factor
basis/stack-checker/known-words/known-words.factor
basis/tools/disassembler/udis/udis.factor
basis/ui/tools/profiler/profiler.factor
basis/windows/ce/ce.factor
basis/windows/dinput/dinput.factor
basis/windows/nt/nt.factor
core/alien/alien-docs.factor
core/alien/alien-tests.factor
core/alien/alien.factor
core/bootstrap/primitives.factor
extra/curses/ffi/ffi.factor
extra/freetype/freetype.factor

index 5406970364f54da685f27539d774ca3a1dd89414..6a1bf7f635ff9bc502b163713b9d12e99dd3369b 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors arrays alien alien.c-types alien.structs
 alien.arrays alien.strings kernel math namespaces parser
 sequences words quotations math.parser splitting grouping
 effects assocs combinators lexer strings.parser alien.parser 
-fry vocabs.parser words.constant ;
+fry vocabs.parser words.constant alien.libraries ;
 IN: alien.syntax
 
 SYNTAX: DLL" lexer get skip-blank parse-string dlopen parsed ;
index e7c0a1766043b600b362d0f33eeb922c7cc3656a..2930843ad7a9c44115f38178f3ae1464d4c6d7ba 100644 (file)
@@ -5,7 +5,8 @@
 ! License: http://factorcode.org/license.txt
 
 USING: system combinators alien alien.syntax alien.c-types
-alien.destructors kernel accessors sequences arrays ui.gadgets ;
+alien.destructors kernel accessors sequences arrays ui.gadgets
+alien.libraries ;
 
 IN: cairo.ffi
 << {
index 4ddd0c030011797832a868410604bfd16b3d233e..7df80c6b6e4159f84893152affc8fb617b509fe9 100755 (executable)
@@ -3,7 +3,7 @@
 USING: namespaces make math math.order math.parser sequences accessors
 kernel kernel.private layouts assocs words summary arrays
 combinators classes.algebra alien alien.c-types alien.structs
-alien.strings alien.arrays alien.complex sets libc
+alien.strings alien.arrays alien.complex sets libc alien.libraries
 continuations.private fry cpu.architecture
 compiler.errors
 compiler.alien
index d369c22e4c4b6bf0936167bcf3a525d193a8791c..a472f9a2fe85479c52d161f48ca05abfedf91a46 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.syntax combinators system ;
+USING: alien alien.syntax combinators system alien.libraries ;
 IN: compression.zlib.ffi
 
 << "zlib" {
index 7de601c433a5d32fb3e67700d22bdf6d734ab675..d3b1352750a20ede8721e6433e9be054f12dd342 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: words parser alien alien.c-types kernel fry accessors ;
+USING: words parser alien alien.c-types kernel fry accessors
+alien.libraries ;
 IN: core-text.utilities
 
 SYNTAX: C-GLOBAL:
index fc407b06bd2f4d81c5c675b8e5f211214e2e881f..93f93c9a13ce1952fbc7d1961155be7b13d9bfb7 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 ! tested on debian linux with postgresql 8.1
-USING: alien alien.syntax combinators system ;
+USING: alien alien.syntax combinators system alien.libraries ;
 IN: db.postgresql.ffi
 
 << "postgresql" {
index 341995634e1a971cfc0032d6f939a9602489686b..61394391a00cc5b285ba30e406bc58f0d83e68e9 100644 (file)
@@ -3,7 +3,7 @@
 ! An interface to the sqlite database. Tested against sqlite v3.1.3.
 ! Not all functions have been wrapped.
 USING: alien compiler kernel math namespaces sequences strings alien.syntax
-    system combinators alien.c-types ;
+system combinators alien.c-types alien.libraries ;
 IN: db.sqlite.ffi
 
 << "sqlite" {
index 30c9fd37abf529c106699bfe84bd1a84e1a460ca..ff5869efab5c9634627dc6df81398e6f000f860b 100644 (file)
@@ -1,6 +1,7 @@
 USING: alien arrays generic generic.math help.markup help.syntax
 kernel math memory strings sbufs vectors io io.files classes
-help generic.standard continuations io.files.private listener ;
+help generic.standard continuations io.files.private listener
+alien.libraries ;
 IN: debugger
 
 ARTICLE: "debugger" "The debugger"
index 1805f4bff9c729d57ee69cd9d2092915662e66c5..ca481cb900fc9645f068d25daf631539881c953a 100755 (executable)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Matthew Willis.
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license
-USING: alien alien.syntax alien.destructors combinators system ;
+USING: alien alien.syntax alien.destructors combinators system
+alien.libraries ;
 IN: glib
 
 <<
index eb8dda5e33ebd14345347a75d32dc20430e287f6..9e095a62e6b205314023943dfde6fca03fc893e7 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel alien ;
+USING: kernel alien alien.libraries ;
 IN: opengl.gl.macosx
 
 : gl-function-context ( -- context ) 0 ; inline
index 1a25b4d01966c868d2c4184c399259cd85d0c369..b9e00b6c8d879f550ccf256fe801a175bcb0712b 100644 (file)
@@ -5,7 +5,8 @@
 !
 ! export LD_LIBRARY_PATH=/opt/local/lib
 
-USING: alien alien.syntax combinators kernel system ;
+USING: alien alien.syntax combinators kernel system
+alien.libraries ;
 
 IN: openssl.libcrypto
 
index 8ed15a4e5e2b2dd53963abdef639b0bf2f3cc035..21f712fdc85f9420af21bf4e3d2e43a0436360a6 100644 (file)
@@ -2,7 +2,8 @@
 ! Portions copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax combinators kernel system namespaces
-assocs parser lexer sequences words quotations math.bitwise ;
+assocs parser lexer sequences words quotations math.bitwise
+alien.libraries ;
 
 IN: openssl.libssl
 
index 540d1cb9f770a932d51f219ba792ac3fe1b07cfc..ec5afa3c3d1b924d85c436806e738c0caec12240 100644 (file)
@@ -2,7 +2,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license
 USING: arrays system alien.destructors alien.c-types alien.syntax alien
-combinators math.rectangles kernel math ;
+combinators math.rectangles kernel math alien.libraries ;
 IN: pango
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -34,4 +34,4 @@ C-STRUCT: PangoRectangle
 : PangoRectangle>rect ( PangoRectangle -- rect )
     [ [ PangoRectangle-x pango>float ] [ PangoRectangle-y pango>float ] bi 2array ]
     [ [ PangoRectangle-width pango>float ] [ PangoRectangle-height pango>float ] bi 2array ] bi
-    <rect> ;
\ No newline at end of file
+    <rect> ;
index f52632040d23725697604b0d8186b764fcb0bde0..0b135319fffec3ab72176a54dc0e3605e8e27093 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences accessors combinators math namespaces
-init sets words
+init sets words alien.libraries
 alien alien.c-types
 stack-checker.backend stack-checker.errors stack-checker.visitor ;
 IN: stack-checker.alien
index a7f348d36b624a84c9745c103acf70c35e5cbb62..a38bb42c7efa5cad2089d20f899e703c492e7f55 100644 (file)
@@ -12,6 +12,7 @@ classes.tuple.private vectors vectors.private words definitions
 words.private assocs summary compiler.units system.private
 combinators locals locals.backend locals.types words.private
 quotations.private combinators.private stack-checker.values
+alien.libraries
 stack-checker.alien
 stack-checker.state
 stack-checker.errors
index 304595f41cb2316e201501aac25c19c2e4314953..51e399c1c3d1d708635515d4544881d9eab55163 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: tools.disassembler namespaces combinators
 alien alien.syntax alien.c-types lexer parser kernel
-sequences layouts math math.order
+sequences layouts math math.order alien.libraries
 math.parser system make fry arrays ;
 IN: tools.disassembler.udis
 
index 6bca4b40c4a0bd217ea6e96985c716324e85c78e..1c2318a35e94328d30cdf8f41231591ebb638cc5 100644 (file)
@@ -210,4 +210,4 @@ profiler-gadget "toolbar" f {
 
 : com-profile ( quot -- ) profile profiler-window ;
 
-MAIN: profiler-window
\ No newline at end of file
+MAIN: profiler-window
index 18c48a01392afdb4506f5a32e6efbad6bb5f1f23..ff6a9ad4fcb4eeaeca9c7a429f230227bd07b961 100644 (file)
@@ -1,4 +1,4 @@
-USING: alien sequences ;
+USING: alien sequences alien.libraries ;
 {
     { "advapi32" "\\windows\\coredll.dll" "stdcall" }
     { "gdi32"    "\\windows\\coredll.dll" "stdcall" }
index dc544858b6e231d1759ab52ff3837200eb72071d..20a54dff9884ca6eb94205c9d2e9b0b262e6a95a 100755 (executable)
@@ -2,12 +2,6 @@ USING: windows.kernel32 windows.ole32 windows.com windows.com.syntax
 alien alien.c-types alien.syntax kernel system namespaces math ;
 IN: windows.dinput
 
-<<
-    os windows?
-    [ "dinput" "dinput8.dll" "stdcall" add-library ]
-    when
->>
-
 LIBRARY: dinput
 
 TYPEDEF: void* LPDIENUMDEVICESCALLBACKW
index 24d0032c5b4ed726fa06186962289d238f099086..e05a409e67e4f479ab29aef8183fcd8115df6ed7 100644 (file)
@@ -1,6 +1,7 @@
-USING: alien sequences ;
+USING: alien sequences alien.libraries ;
 {
     { "advapi32" "advapi32.dll" "stdcall" }
+    { "dinput"   "dinput8.dll"  "stdcall" }
     { "gdi32"    "gdi32.dll"    "stdcall" }
     { "user32"   "user32.dll"   "stdcall" }
     { "kernel32" "kernel32.dll" "stdcall" }
index edac8c09cc6a46dfefbfbb18e6487d751d690688..398d04e4dd2b65182a863f87ca80d39127b013d5 100644 (file)
@@ -1,7 +1,7 @@
 USING: byte-arrays arrays help.syntax help.markup
-alien.syntax compiler definitions math libc
-debugger parser io io.backend system
-alien.accessors eval ;
+alien.syntax compiler definitions math libc eval
+debugger parser io io.backend system alien.accessors
+alien.libraries ;
 IN: alien
 
 HELP: alien
@@ -22,16 +22,6 @@ HELP: <bad-alien>
 { $values  { "alien" c-ptr } }
 { $description "Constructs an invalid alien pointer that has expired." } ;
 
-HELP: <library>
-{ $values
-     { "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $snippet "cdecl" } " or " { $snippet "stdcall" } }
-     { "library" library } }
-{ $description "Opens a C library using the path and ABI parameters and outputs a library tuple." }
-{ $notes "User code should use " { $link add-library } " so that the opened library is added to a global hashtable, " { $link libraries } "." } ;
-
-HELP: libraries
-{ $description "A global hashtable that keeps a list of open libraries. Use the " { $link add-library } " word to construct a library and add it with a single call." } ;
-
 HELP: <displaced-alien> ( displacement c-ptr -- alien )
 { $values { "displacement" "an integer" } { "c-ptr" c-ptr } { "alien" "a new alien" } }
 { $description "Creates a new alien address object, wrapping a raw memory address. The alien points to a location in memory which is offset by " { $snippet "displacement" } " from the address of " { $snippet "c-ptr" } "." }
@@ -54,61 +44,6 @@ HELP: <alien>
 HELP: c-ptr
 { $class-description "Class of objects consisting of aliens, byte arrays and " { $link f } ". These objects can convert to pointer C types, which are all aliases of " { $snippet "void*" } "." } ;
 
-HELP: library
-{ $values { "name" "a string" } { "library" "a hashtable" } }
-{ $description "Looks up a library by its logical name. The library object is a hashtable with the following keys:"
-    { $list
-        { { $snippet "name" } " - the full path of the C library binary" }
-        { { $snippet "abi" } " - the ABI used by the library, either " { $snippet "cdecl" } " or " { $snippet "stdcall" } }
-        { { $snippet "dll" } " - an instance of the " { $link dll } " class; only set if the library is loaded" }
-    }
-} ;
-
-HELP: dlopen ( path -- dll )
-{ $values { "path" "a pathname string" } { "dll" "a DLL handle" } }
-{ $description "Opens a native library and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." }
-{ $errors "Throws an error if the library could not be found, or if loading fails for some other reason." }
-{ $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ;
-
-HELP: dlsym ( name dll -- alien )
-{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" "an alien pointer" } }
-{ $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable." }
-{ $errors "Throws an error if the symbol could not be found." } ;
-
-HELP: dlclose ( dll -- )
-{ $values { "dll" "a DLL handle" } }
-{ $description "Closes a DLL handle created by " { $link dlopen } ". This word might not be implemented on all platforms." } ;
-
-HELP: load-library
-{ $values { "name" "a string" } { "dll" "a DLL handle" } }
-{ $description "Loads a library by logical name and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } ". If the library is already loaded, returns the existing handle." } ;
-
-HELP: add-library
-{ $values { "name" "a string" } { "path" "a string" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } }
-{ $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } "and the specified ABI." }
-{ $notes "Because the entire source file is parsed before top-level forms are executed, " { $link add-library } " cannot be used in the same file as " { $link POSTPONE: FUNCTION: } " definitions from that library. The " { $link add-library } " call will happen too late, after compilation, and the alien calls will not work."
-$nl
-"Instead, " { $link add-library } " calls must either be placed in different source files from those that use that library, or alternatively, " { $link "syntax-immediate" } " can be used to load the library before compilation." }
-{ $examples "Here is a typical usage of " { $link add-library } ":"
-{ $code
-    "<< \"freetype\" {"
-    "    { [ os macosx? ] [ \"libfreetype.6.dylib\" \"cdecl\" add-library ] }"
-    "    { [ os windows? ] [ \"freetype6.dll\" \"cdecl\" add-library ] }"
-    "    [ drop ]"
-    "} cond >>"
-}
-"Note the parse time evaluation with " { $link POSTPONE: << } "." } ;
-
-HELP: alien-invoke-error
-{ $error-description "Thrown if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
-    { $list
-        { "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
-        { "The return type or parameter list references an unknown C type." }
-        { "The symbol or library could not be found." }
-        { "One of the four inputs to " { $link alien-invoke } " is not a literal value. To call functions which are not known at compile-time, use " { $link alien-indirect } "." }
-    }
-} ;
-
 HELP: alien-invoke
 { $values { "..." "zero or more objects passed to the C function" } { "return" "a C return type" } { "library" "a logical library name" } { "function" "a C function name" } { "parameters" "a sequence of C parameter types" } }
 { $description "Calls a C library function with the given name. Input parameters are taken from the data stack, and the return value is pushed on the data stack after the function returns. A return type of " { $snippet "\"void\"" } " indicates that no value is to be expected." }
@@ -226,6 +161,16 @@ ARTICLE: "alien-invoke" "Calling C from Factor"
 { $subsection alien-indirect }
 "There are some details concerning the conversion of Factor objects to C values, and vice versa. See " { $link "c-data" } "." ;
 
+HELP: alien-invoke-error
+{ $error-description "Thrown if the word calling " { $link alien-invoke } " was not compiled with the optimizing compiler. This may be a result of one of several failure conditions:"
+    { $list
+        { "This can happen when experimenting with " { $link alien-invoke } " in this listener. To fix the problem, place the " { $link alien-invoke } " call in a word; word definitions are automatically compiled with the optimizing compiler." }
+        { "The return type or parameter list references an unknown C type." }
+        { "The symbol or library could not be found." }
+        { "One of the four inputs to " { $link alien-invoke } " is not a literal value. To call functions which are not known at compile-time, use " { $link alien-indirect } "." }
+    }
+} ;
+
 ARTICLE: "alien-callback-gc" "Callbacks and code GC"
 "A callback consits of two parts; the callback word, which pushes the address of the callback on the stack when executed, and the callback body itself. If the callback word is redefined, removed from the dictionary using " { $link forget } ", or recompiled, the callback body will not be reclaimed by the garbage collector, since potentially C code may be holding a reference to the callback body."
 $nl
@@ -321,6 +266,7 @@ $nl
 { $warning "C does not perform runtime type checking, automatic memory management or array bounds checks. Incorrect usage of C library functions can lead to crashes, data corruption, and security exploits." }
 { $subsection "loading-libs" }
 { $subsection "aliens" }
+{ $subsection "alien.libraries" }
 { $subsection "alien-invoke" }
 { $subsection "alien-callback" }
 { $subsection "c-data" }
index e4063b733cdd61b6fe42d968ad44f0a3f526e540..57dc298c00c19de11fe8e4d385a126cedf4e4724 100644 (file)
@@ -1,7 +1,7 @@
-IN: alien.tests
 USING: accessors alien alien.accessors alien.syntax byte-arrays arrays
 kernel kernel.private namespaces tools.test sequences libc math
-system prettyprint layouts ;
+system prettyprint layouts alien.libraries ;
+IN: alien.tests
 
 [ t ] [ -1 <alien> alien-address 0 > ] unit-test
 
@@ -85,4 +85,4 @@ f initialize-test set-global
 
 [ ] [ initialize-test get BAD-ALIEN >>alien drop ] unit-test
 
-[ 7575 ] [ initialize-test [ 7575 ] initialize-alien ] unit-test
\ No newline at end of file
+[ 7575 ] [ initialize-test [ 7575 ] initialize-alien ] unit-test
index 8e48ac770c8933bdcd8fcd8035ae7d1a7748dd05..ea0cb9208e19378ac519e15ea7dce845fecc3a04 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs kernel math namespaces sequences system
-kernel.private byte-arrays arrays init io.backend ;
+kernel.private byte-arrays arrays init ;
 IN: alien
 
 ! Some predicate classes used by the compiler for optimization
@@ -49,24 +49,6 @@ M: alien equal?
         2drop f
     ] if ;
 
-SYMBOL: libraries
-
-libraries [ H{ } clone ] initialize
-
-TUPLE: library path abi dll ;
-
-: library ( name -- library ) libraries get at ;
-
-: <library> ( path abi -- library )
-    over dup [ dlopen ] when \ library boa ;
-
-: load-library ( name -- dll )
-    library dup [ dll>> ] when ;
-
-: add-library ( name path abi -- )
-    [ dup [ normalize-path ] when ] dip
-    <library> swap libraries get set-at ;
-
 ERROR: alien-callback-error ;
 
 : alien-callback ( return parameters abi quot -- alien )
index ed645715821331f39255731dc4d9227546eabb2f..e3803f21500b14ddf6841862fb196c195ff26221 100644 (file)
@@ -62,6 +62,7 @@ bootstrapping? on
 {
     "alien"
     "alien.accessors"
+    "alien.libraries"
     "arrays"
     "byte-arrays"
     "classes.private"
@@ -458,9 +459,9 @@ tuple
     { "code-room" "memory" (( -- code-free code-total )) }
     { "micros" "system" (( -- us )) }
     { "modify-code-heap" "compiler.units" (( alist -- )) }
-    { "dlopen" "alien" (( path -- dll )) }
-    { "dlsym" "alien" (( name dll -- alien )) }
-    { "dlclose" "alien" (( dll -- )) }
+    { "dlopen" "alien.libraries" (( path -- dll )) }
+    { "dlsym" "alien.libraries" (( name dll -- alien )) }
+    { "dlclose" "alien.libraries" (( dll -- )) }
     { "<byte-array>" "byte-arrays" (( n -- byte-array )) }
     { "(byte-array)" "byte-arrays" (( n -- byte-array )) }
     { "<displaced-alien>" "alien" (( displacement c-ptr -- alien )) }
index b1c481a5769c5333b3ce462ae47c3994f162a250..3ff9404bff39955c3017619380e7cc565f531b66 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.syntax combinators kernel system ;
+USING: accessors alien alien.syntax combinators kernel system
+alien.libraries ;
 IN: curses.ffi
 
 << "curses" {
index 06c875b2fadb7839a167a83d2d35a8d98a9674bb..c45475cefa30a9b81567e7232959c84e3f9e4f0b 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2005, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.syntax kernel system combinators ;
+USING: alien alien.syntax kernel system combinators
+alien.libraries ;
 IN: freetype
 
 << "freetype" {