alien.libraries: Change <library> to be just a constructor. Replace with make-library and try-make-library so that we throw better errors.

db4
Doug Coleman 2014-06-05 14:26:38 -07:00
parent 96884eab2a
commit 40a79766af
3 changed files with 19 additions and 8 deletions

View File

@ -4,7 +4,7 @@ USING: accessors alien alien.syntax assocs help.markup
help.syntax io.backend kernel namespaces strings ;
IN: alien.libraries
HELP: <library>
HELP: make-library
{ $values
{ "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
{ "library" library } }

View File

@ -17,16 +17,26 @@ SYMBOL: libraries
libraries [ H{ } clone ] initialize
TUPLE: library { path string } { abi abi initial: cdecl } dll dlerror ;
TUPLE: library { path string } dll dlerror { abi abi initial: cdecl } ;
C: <library> library
ERROR: no-library name ;
ERROR: library-path-is-f name path abi ;
: lookup-library ( name -- library ) libraries get at ;
: <library> ( path abi -- library )
over dup
[ dlopen dup dll-valid? [ f ] [ dlerror ] if ] [ f ] if
\ library boa ;
: open-dll ( path -- dll dll-error/f )
[ dlopen dup dll-valid? [ f ] [ dlerror ] if ]
[ f f ] if* ;
: make-library ( path abi -- library )
[ dup open-dll ] dip <library> ;
: try-make-library ( name path abi -- library )
over [ [ nip ] dip ] [ library-path-is-f ] if
make-library ;
: library-dll ( library -- dll )
dup [ dll>> ] when ;
@ -48,7 +58,8 @@ M: library dispose dll>> [ dispose ] when* ;
: add-library ( name path abi -- )
3dup add-library? [
[ 2drop remove-library ]
[ <library> swap libraries get set-at ] 3bi
[ try-make-library ]
[ 2drop libraries get set-at ] 3tri
] [ 3drop ] if ;
: library-abi ( library -- abi )

View File

@ -558,7 +558,7 @@ SYMBOL: deploy-vocab
"Preparing deployed libraries" show
deploy-libraries get [
libraries get [
[ path>> >deployed-library-path ] [ abi>> ] bi <library>
[ path>> >deployed-library-path ] [ abi>> ] bi make-library
] change-at
] each