OpenMCL provides a fairly rich language for defining and specifying foreign data types (this language is derived from CMUCL's "alien type" system.) In practice, most foreign type definitions are introduced into OpenMCL via its interface database, though it's also possible to define foreign types interactively and/or programmatically.
OpenMCL's foreign type system is "evolving" (a polite word for not-quite-complete): there are some inconsistencies involving package usage, for instance. Symbols used in foreign type specifiers should be keywords, but this convention isn't always enforced.
Foreign type, record, and field names are case-sensitive; OpenMCL uses some escaping conventions to allow keywords to be used to denote these names.
Some foreign types are builtin: keywords denote primitive, builtin types such as the IEEE-double-float type (denoted :DOUBLE-FLOAT), in much the same way as certain symbols (CONS, FIXNUM, etc.) define primitive CL types.
Constructors such as :SIGNED and :UNSIGNED can be used to denote signed and unsigned integer subtypes (analogous to the CL type specifiers SIGNED-BYTE and UNSIGNED-BYTE.) :SIGNED is shorthand for (:SIGNED 32) and :UNSIGNED is shorthand for (:UNSIGNED 32).
Aliases for other (perhaps more complicated) types can
be defined via CCL::DEF-FOREIGN-TYPE (sort of like CL:DEFTYPE
or the C typedef
facility). The type :CHAR
is defined as an alias for (:SIGNED 8) under Darwin, or as
(:UNSIGNED 8) under LinuxPPC.
The construct (:STRUCT <name>) can be used to refer to a named structure type; (:UNION <name>) can be used to refer to a named union type. It isn't necessary to enumerate a structure or union type's fields in order to refer to the type.
If X
is a valid foreign type reference, then
(:* X
) denotes the foreign type "pointer to
X
". By convention, (:* T) denotes an anonymous
pointer type, vaguely equivalent to "void*" in C.
If a fieldlist
is a list of lists, each of
whose CAR
is a foreign field name (keyword) and
whose CADR
is a foreign type specifier, then
(:STRUCT <name> ,@fieldlist
) is a
definition of the structure type <name>, and (:UNION
<name> ,@fieldlist
) is a definition of
the union type <name>. Note that it's necessary to
define a structure or union type in order to include that
type in a structure, union, or array, but only necessary to
"refer to" a strucure or union type in order to define a
type alias or a pointer type.
If X
is a defined foreign type , then
(:array X
&rest dims) denotes the foreign
type "array of X
". Although multiple array
dimensions are allowed by the :array constructor, only
single-dimensioned arrays are (at all) well-supported in
OpenMCL.
Syntax | ccl::def-foreign-type name foreign-type-spec |
Description |
If
If [Note that there are separate namespaces for type names and for struct/union names.] |
Arguments |
|
Syntax | ccl::make-record typespec &rest initforms |
Description |
Record fields that aren't explicitly initialized are set to binary 0.
The value of the |
Arguments |
|
Syntax | rlet (var typespec &rest initforms)* &body body |
Description |
Executes Record fields that aren't explicitly initialized have unspecified contents. |
Arguments |
|
Syntax | rlet (var typespec &rest initforms)* &body body |
Description |
Executes
Unlike |
Arguments |
|
Syntax | pref ptr accessor-form |
Description |
References an instance of a foreign type (or a component
of a foreign type) accessible via
Expands into code which references the indicated scalar type or component, or returns a pointer to a composite type.
|
Arguments |
|