Next: Exceptions and Control Flow
Up: Mixing Core and Signed
Previous: Adding a Signature to
The unit/sig, compound-unit/sig, invoke-unit/sig,
and invoke-open-unit/sig forms expand into expressions using the
unit, compound-unit, invoke-unit, and
invoke-open-unit forms, respectively. The exapnsion 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
- 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 signalling 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,
an exception is raised:
- If the signatures fail to match because src-sig is missing an element,
then the exn:unit:signature:match:missing exception is raised.
- If the signatures fail to match because src-sig contains an extra element
(exact matching mode only), then the exn:unit:signature:match:extra exception is raised.
- If the signatures fail to match because src-dest and src-sig
contain the same element name but for different element types, then the
exn:unit:signature:match:kind exception is raised.
- (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, an exception is raised:
- If any value in the units list is not a signed unit, then the
exn:unit:signature:non-signed-unit exception is raised.
- If 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, then the
exn:unit:signature:arity exception is raised.
- If a linking signature does not exactly match the signature
expected by an importing unit, one of exn:unit:signature:missing,
exn:unit:signature:extra, or exn:unit:signature:kind
is raised.
Next: Exceptions and Control Flow
Up: Mixing Core and Signed
Previous: Adding a Signature to
PLT