4.1.2 Creating foreign structure types
18.104.22.168 Foreign types A foreign type is a set of abstract attributes of an area in memory that specifies how the bits stored in the area are to be interpreted. The compiler uses these attributes to determine how to expand certain expressions--assignment statements, for example. A location in memory that can be used by foreign code and that is associated with a foreign type is known as foreign storage. As an example, the foreign type
:signed-32bit defines a correspondence between the Lisp data type
integer and the C data type
long. If 32 bits of foreign storage are assigned for the foreign type
long, Lisp has predefined access and update functions to convert these bits to and from Lisp objects of type
Procedural languages such as C associate foreign storage with the term variable; however, that term is used differently in Lisp. The Foreign Function Interface calls foreign storage that has a name a foreign variable.
The foreign type system supports both named types and derived types:
- There are three kinds of named types:
- A predefined type is predefined in the implementation; these types are listed in Section 4.1.6 on page 104. A primitive type is a predefined type that has a corresponding Lisp type; Lisp can directly convert foreign storage that is associated with a primitive type into Lisp objects. You cannot create new predefined types.
- A structure type is a type that is defined with the macro
def-foreign-struct and that is formed by concatenating previously defined types, much like the
struct type in C.
- A synonym type is a type that attaches a new name to a previously defined type; it is defined with the macro
- A derived type is either a pointer to a previously defined type, a pointer to another derived type, an array of a previously defined type, or an array of a derived type.
The Advanced User's Guide - 9 SEP 1996
Generated with Harlequin WebMaker