silo:std.effects.ffi

Source src/silo:std.effects.ffi

1##! FFI effect — load dynamic libraries and call native symbols.
2##!
3##! The surface today is minimal: `Library` and `Symbol` are untyped
4##! `AnyUInt` handles, and only `.load-library`, `.lookup`, and a single
5##! `.call-void` shape (no args, no return) are exposed. The typed
6##! `(Symbol sig)` with quotation-parameterised signatures and typed
7##! `.call` arrive once the compile-time marshalling machinery lands.
8
9:use
10  :open core AnyUInt Str Unit Result
11  :open effects.io IO
12:end
13
14# si[impl effect.ffi.decl]
15## FFI effect — load dynamic libraries and call native symbols.
16## `Library` and `Symbol` handles are `AnyUInt` identifiers in this
17## provisional decl; the typed `(Symbol sig)` form lands later.
18:effect(pub) Ffi IO
19  # si[impl effect.ffi.load]
20  ## Load a dynamic library from the given path, returning a handle.
21  .load-library ( Str -> (Result AnyUInt Str) )
22  # si[impl effect.ffi.lookup]
23  ## Look up a symbol by name within a previously loaded `Library`.
24  .lookup ( AnyUInt Str -> (Result AnyUInt Str) )
25  # si[impl effect.ffi.call]
26  ## Call a symbol that takes no args and returns nothing. Richer
27  ## signatures arrive with the typed-marshalling WP.
28  .call-void ( AnyUInt -> (Result Unit Str) )
29:end