Next: Exceptions and Control Flow
Up: Mixing Core and Signed
Previous: Adding a Signature to
The unit/sig, compound-unit/sig, and invoke-unit/sig
forms expand into expressions using the unit,
compound-unit, and invoke-unit forms, respectively. The
expansion may also use global-defined-signature rather than
inlining a signature that is bound to a global identifier.
A signed unit value is represented by a unit-with-signature structure
with the following fields:
- unit -- the primitive unit implementing the signed unit's content
- imports -- the import signatures, represented as a list
of pairs, where each pair consists of
- a tag symbol, used for error reporting; and
- an ``exploded signature''; an exploded signature is a vector of
signature elements, where each element is either
- a symbol, representing a variable in the signature; or
- a pair consisting of a symbol and an exploded signature,
representing a name sub-signature.
- exports -- the export signature, represented as an
exploded signature
To perform the signature checking needed by compound-unit/sig,
MzScheme provides two procedures:
- (verify-signature-match where exact? dest-context dest-sig src-context src-sig) raises an exception unless the exploded
signatures dest-sig and src-sig match. If exact? is
#f, then src-sig need only satisfy dest-sig,
otherwise the signatures must match exactly. The where symbol
and dest-context and src-context strings are used for
generating an error message string: where is used as the name
of the signaling procedure and dest-context and
src-context are used as the respective signature names.
If the match succeeds, void is returned. If the match fails, the
exn:unit exception is raised for one of the following reasons:
- The signatures fail to match because src-sig is missing
an element.
- The signatures fail to match because src-sig contains
an extra element.
- The signatures fail to match because src-dest and
src-sig contain the same element name but for different
element types.
- (verify-linkage-signature-match where tags units export-sigs linking-sigs) performs all of the run-time signature
checking required by a compound-unit/sig or
invoke-unit/sig expression. The where symbol is used for
error reporting. The tags argument is a list of tag symbols,
and the units argument is the corresponding list of candidate
signed unit values. (The procedure will check whether these values
are actually signed unit values.)
The export-sigs list contains one exploded signature for each
tag; these correspond to the tag signatures provided in the original
compound-unit/sig expression. The linking-sigs list
contains a list of named exploded signatures for each tag (where a
``named signature'' is a pair consisting of a name symbol and an
exploded signature); every tag's list corresponds to the signatures
that were specified or inferred for the tag's linkage specification
in the original compound-unit/sig expression. The names on the
linking signatures are used for error messages.
If all linking checks succeed, void is returned. If any check
fails, the exn:unit exception is raised for one of the following reasons:
- A value in the units list is not a signed unit.
- The number of import signatures associated with a unit does
not agree with the number of linking signatures specified by the
corresponding list in linking-sigs.
- A linking signature does not exactly match the signature
expected by an importing unit.
Next: Exceptions and Control Flow
Up: Mixing Core and Signed
Previous: Adding a Signature to
PLT