blob: 3a6091fc438179d2ee37c3b133d9c00767bbc0fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
Foreign Function Interface
==========================
Elymas supports loading of shared object based libraries (`*.so`) utilizing the standard libc facilities.
This support is only available in the `shared` interpreter, which different from all other interpreters,
dynamically links against libc.
sys .so ":" via
"/lib/x86_64-linux-gnu/libm.so.6" :dlopen not { "Failed to load." die } rep
"sin" "d" "d" :resolveFunction =*sin
0 31 range { 10.0 div sin dump } each
`sys .so .dlopen`
-----------------
Takes a filename of a shared object from the stack and loads that shared object. A handle is returned
but can savely be ignored except to test it against zero, which would signify an error.
`sys .so .resolveFunction`
--------------------------
Takes a function name, a string describing function arguments and a string describing the return type
from the stack. It resolves the name within all currently loaded objects, and returns an elymas function
object which wraps the underlying foreign function.
The input specification string consists of single characters, each describing the type of one input
argument.
* `p` - A pointer argument.
* `i` - An integer (of any width).
* `f` - A float.
* `d` - A double.
* `s` - A string. A pointer to a zero-terminated string is passed to the C-function.
* `b` - A buffer. A pointer the beginning of the string contents is passed to the C-function.
When specifying the return type of the function, integer widths matter, hence the following
options are available.
* `v` - No return value
* `p` - Pointer return value
* `u8` - `uint8_t` return value
* `u16` - `uint16_t` return value
* `u32` - `uint32_t` return value
* `u64` - `uint64_t` return value
* `i8` - `int8_t` return value
* `i16` - `int16_t` return value
* `i32` - `int32_t` return value
* `i64` - `int64_t` return value
* `s` - String return value (will be copied)
* `f` - float return value
* `d` - double return value
`sys .so .rawContentAddress`
----------------------------
Returns the address of the first byte of a string. This can be handy to build complex C structures
within a string memory and then passing the pointer to a foreign function.
`sys .so .peekString`
---------------------
Takes an address and scans that address for a C-style zero-terminated string
(of some implementation defined maximum length). This string is subsequently returned.
`sys .so .freeze`
-----------------
A binary created by `sys .freeze` will have no dynamic dependencies, hence libc is not available. If you
want to use dynamic libraries in your binary, use `sys .so .freeze` which will create an ELF binary which
is dynamically linked against libc. The loaded libc is then used to call `dlopen` and `dlsym` to load
further libraries. The `shared` interpreter has been created with `sys .so .freeze`.
Libraries interfaced so far
---------------------------
* `ffi .pq` - PostgreSQL
|