Next: Calling C functions from Scheme, Up: C interface
Shared bindings are the means by which named values are shared between
Scheme & C code. There are two separate tables of shared bindings, one
for values defined in Scheme and accessed from C and the other for the
opposite direction. Shared bindings actually bind names to cells, to
allow a name to be resolved before it has been assigned. This is
necessary because C initialization code may run before or after the
corresponding Scheme code, depending on whether the Scheme code is in
the resumed image or run in the current session. The Scheme bindings
described here are available from the shared-bindings
structure.
Shared-binding?
is the disjoint type predicate for all shared bindings, imported or exported;shared-binding-is-import?
returns true if shared-binding was imported into Scheme from C, and false if it has the converse direction.
Shared-binding-ref
returns the value of shared-binding;shared-binding-set!
sets the value of shared-binding to be value.
Lookup-imported-binding
returns the binding imported from C to Scheme with the given name; a binding is created if none exists.Define-imported-binding
creates a new such binding, anomalously from within Scheme; such bindings are usually created instead from within C using the Cs48_define_exported_binding
function.Undefine-imported-binding
removes the shared binding whose name is name from the table of imported bindings.
Equivalents of the above three procedures, but for bindings exported from Scheme to C.
Define-imported-binding
, unlikedefine-exported-binding
, is customary to use in Scheme, as its intended use is to make a Scheme value available to C code from within Scheme.
Returns a vector of all bindings imported into Scheme from C with undefined values, i.e. those created implicitly by lookups that have not yet been assigned rather than those created explicitly by the shared binding definers (
define-exported-binding
, &c.).
These macros are C counterparts to Scheme's
shared-binding?
,shared-binding-name
,shared-binding-is-import?
,shared-binding-ref
, andshared-binding-set!
, respectively.
Signals an exception if and only if binding's value is Scheme48's `unspecific' value.
Huh?: Undefined shared bindings are not initialized with the `unspecific' value, but rather with an entirely different special token referred to internally as `undefined,' used in circumstances such as this — yet
S48_SHARED_BINDING_CHECK
, as defined in scheme48.h, definitely checks whether binding's value is the `unspecific' value.
Returns the shared binding defined in Scheme for name, creating it if necessary.
Defines a shared binding named name with the value value that can be accessed from Scheme.
This is a convenience for the common case of exporting a C function to Scheme. This expands into
s48_define_exported_binding("fn", s48_enter_pointer(fn))which boxes the function into a Scheme48 byte vector and then exports it as a shared binding. Note that
s48_enter_pointer
allocates space in the Scheme heap and may trigger a garbage collection; see Interacting with the Scheme heap in C.