factor/library/alien/aliens.factor

57 lines
1.3 KiB
Factor
Raw Normal View History

2005-04-09 18:30:46 -04:00
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
2005-04-10 18:58:30 -04:00
USING: hashtables kernel lists math namespaces parser stdio ;
2005-04-09 18:30:46 -04:00
BUILTIN: dll 15 [ 1 "dll-path" f ] ;
BUILTIN: alien 16 ;
BUILTIN: byte-array 19 ;
BUILTIN: displaced-alien 20 ;
: NULL ( -- null )
#! C null value.
0 <alien> ;
: null? ( alien -- ? ) dup [ alien-address 0 = ] when ;
: null>f ( alien -- alien/f )
dup alien-address 0 = [ drop f ] when ;
M: alien hashcode ( obj -- n )
alien-address >fixnum ;
M: alien = ( obj obj -- ? )
over alien? [
alien-address swap alien-address =
] [
2drop f
] ifte ;
2005-04-17 18:34:09 -04:00
: ALIEN: scan-word <alien> swons ; parsing
2005-04-09 18:30:46 -04:00
: DLL" skip-blank parse-string dlopen swons ; parsing
: library ( name -- object )
dup [ "libraries" get hash ] when ;
: load-dll ( name -- dll )
#! Higher level wrapper around dlopen primitive.
library dup [
[
"dll" get dup [
drop "name" get dlopen dup "dll" set
] unless
] bind
] when ;
: add-library ( library name abi -- )
"libraries" get [
<namespace> [
"abi" set
"name" set
2005-04-16 00:23:27 -04:00
] extend swap set
2005-04-09 18:30:46 -04:00
] bind ;
: library-abi ( library -- abi )
library [ [ "abi" get ] bind ] [ "cdecl" ] ifte* ;