]> gitweb.factorcode.org Git - factor.git/blob - core/compiler/alien/aliens.facts
595ae0143bb749f0454b0fc4a52d3cab9e848ffb
[factor.git] / core / compiler / alien / aliens.facts
1 IN: alien
2 USING: arrays help ;
3
4 HELP: alien
5 { $class-description "The class of alien pointers. See " { $link "syntax-aliens" } " for syntax and " { $link "c-data" } " for general information." } ;
6
7 HELP: dll
8 { $class-description "The class of native library handles. See " { $link "syntax-aliens" } " for syntax and " { $link "dll-internals" } " for general information." } ;
9
10 HELP: expired? ( c-ptr -- ? )
11 { $values { "c-ptr" "an alien, byte array, or " { $link f } } { "?" "a boolean" } }
12 { $description "Tests if the alien is a relic from an earlier session. When an image is loaded, any alien objects which persisted in the image are marked as being expired."
13 $terpri
14 "A byte array is never considered to be expired, whereas passing " { $link f } " always yields true." } ;
15
16 HELP: <displaced-alien> ( displacement c-ptr -- alien )
17 { $values { "displacement" "an integer" } { "c-ptr" "an alien, byte array, or " { $link f } } { "alien" "a new alien" } }
18 { $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" } "." }
19 { $notes "Passing a value of " { $link f } " for " { $snippet "c-ptr" } " creates an alien with an absolute address; this is how " { $link <alien> } " is implemented."
20 $terpri
21 "Passing a zero absolute address does not construct a new alien object, but instead makes the word output " { $link f } "." }
22 { $see-also <alien> alien-address } ;
23
24 HELP: alien-address ( c-ptr -- addr )
25 { $values { "c-ptr" "an alien or " { $link f } } { "addr" "a non-negative integer" } }
26 { $description "Outputs the address of an alien." }
27 { $notes "Taking the address of a " { $link byte-array } " is explicitly prohibited since byte arrays can be moved by the garbage collector between the time the address is taken, and when it is accessed. If you need to pass pointers to C functions which will persist across alien calls, you must allocate unmanaged memory instead. See " { $link "malloc" } "." } ;
28
29 HELP: <alien>
30 { $values { "address" "a non-negative integer" } { "alien" "a new alien address" } }
31 { $description "Creates an alien object, wrapping a raw memory address." }
32 { $notes "Alien objects are invalidated between image saves and loads." }
33 { $see-also <displaced-alien> alien-address } ;
34
35 HELP: c-ptr
36 { $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*" } "." } ;
37
38 HELP: library
39 { $values { "name" "a string" } { "library" "a hashtable" } }
40 { $description "Looks up a library by its logical name. The library object is a hashtable with the following keys:"
41     { $list
42         { { $snippet "name" } " - the full path of the C library binary" }
43         { { $snippet "abi" } " - the ABI used by the library, either " { $snippet "cdecl" } " or " { $snippet "stdcall" } }
44         { { $snippet "dll" } " - an instance of the " { $link dll } " class; only set if the library is loaded" }
45     }
46 } ;
47
48 HELP: dlopen ( path -- dll )
49 { $values { "path" "a path name string" } { "dll" "a DLL handle" } }
50 { $description "Opens a native library and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." }
51 { $errors "Throws an error if the library could not be found, or if loading fails for some other reason." }
52 { $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ;
53
54 HELP: dlsym ( name dll -- alien )
55 { $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" "an alien pointer" } }
56 { $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable." }
57 { $errors "Throws an error if the symbol could not be found." } ;
58
59 HELP: dlclose ( dll -- )
60 { $values { "dll" "a DLL handle" } }
61 { $description "Closes a DLL handle created by " { $link dlopen } ". This word might not be implemented on all platforms." } ;
62
63 HELP: load-library
64 { $values { "name" "a string" } { "dll" "a DLL handle" } }
65 { $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." }
66 { $errors "Throws an error if the library could not be found, or if loading fails for some other reason." } ;
67
68 HELP: add-library
69 { $values { "name" "a string" } { "path" "a string" } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } }
70 { $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } "and the specified ABI." }
71 { $examples { $code "\"gif\" \"libgif.so\" \"cdecl\" add-library" } } ;