factor/core/compiler/alien/aliens.factor

51 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2007 Slava Pestov.
2006-02-11 02:30:18 -05:00
! See http://factorcode.org/license.txt for BSD license.
2005-04-09 18:30:46 -04:00
IN: alien
USING: bit-arrays byte-arrays assocs io kernel math
namespaces parser sequences generic ;
2006-02-11 02:30:18 -05:00
: <alien> ( address -- alien ) f <displaced-alien> ; inline
: alien>native-string ( alien -- string )
os { "windows" "wince" } member?
[ alien>u16-string ] [ alien>char-string ] if ;
: dll-path ( dll -- string )
(dll-path) alien>native-string ;
M: alien equal?
2006-03-17 03:21:09 -05:00
over alien? [
2dup [ expired? ] either? [
[ expired? ] both?
2006-03-17 03:21:09 -05:00
] [
[ alien-address ] 2apply =
] if
2006-03-17 03:21:09 -05:00
] [
2drop f
] if ;
2006-02-11 02:30:18 -05:00
SYMBOL: libraries
H{ } clone libraries set-global
TUPLE: library path abi dll ;
2005-04-09 18:30:46 -04:00
C: library ( path abi -- library )
[ set-library-abi ] keep [ set-library-path ] keep ;
: library ( name -- library ) libraries get at ;
2005-04-09 18:30:46 -04:00
2005-05-05 03:12:37 -04:00
: load-library ( name -- dll )
2005-04-09 18:30:46 -04:00
library dup [
dup library-dll [ ] [
dup library-path dup [
dlopen dup rot set-library-dll
] [
2drop f
] if
] ?if
2005-04-09 18:30:46 -04:00
] when ;
2006-08-16 21:55:53 -04:00
: add-library ( name path abi -- )
<library> swap libraries get set-at ;