Shared bindings are the means by which named values are shared between Scheme code and C code. There are two separate tables of shared bindings, one for values defined in Scheme and accessed from C and the other for values going the other way. Shared bindings actually bind names to cells, to allow a name to be looked up before it has been assigned. This is necessary because C initialization code may be run before or after the corresponding Scheme code, depending on whether the Scheme code is in the resumed image or is run in the current session.
s48_value s48_get_imported_binding(char *name)
s48_value S48_SHARED_BINDING_REF(s48_value shared_binding)
value available to C code
name which must be a
string, creating a new shared
binding if necessary.
The C function
s48_get_imported_binding returns the shared binding
name, again creating it if necessary.
The C macro
S48_SHARED_BINDING_REF dereferences a shared binding,
returning its current value.
void s48_define_exported_binding(char *name, s48_value v)
These are used to define shared bindings from C and to access them from Scheme. Again, if a name is looked up before it has been defined, a new binding is created for it.
The common case of exporting a C function to Scheme can be done using
This expands into
which boxes the function into a Scheme byte vector and then
s48_enter_pointer allocates space in the Scheme heap
and might trigger a
c-name is as supplied for the second form.
For the first form
c-name is derived from
-' with `
_' and converting letters to lowercase.
(import-definition my-foo) expands into
(define my-foo (lookup-imported-binding "my_foo"))
There are a number of other Scheme functions related to shared bindings;
these are in the structure
(shared-binding? x) -> boolean
(shared-binding-name shared-binding) -> string
(shared-binding-is-import? shared-binding) -> boolean
(shared-binding-set! shared-binding value)
(define-imported-binding string value)
Shared-binding? is the predicate for shared-bindings.
Shared-binding-name returns the name of a binding.
Shared-binding-is-import? is true if the binding was defined from C.
Shared-binding-set! changes the value of a binding.
Scheme versions of
undefine- procedures remove bindings from the two tables.
They do nothing if the name is not found in the table.
The following C macros correspond to the Scheme functions above.
int S48_SHARED_BINDING_IS_IMPORT_P(s48_value s_b)
s48_value S48_SHARED_BINDING_NAME(s48_value s_b)
void S48_SHARED_BINDING_SET(s48_value s_b, s48_value v)
Previous: Shared bindings | Next: Shared bindings