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 ; help.syntax io.backend kernel namespaces strings ;
IN: alien.libraries IN: alien.libraries
HELP: <library> HELP: make-library
{ $values { $values
{ "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } } { "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
{ "library" library } } { "library" library } }

View File

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

View File

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