previous up next     contents index
Next: Standard Types Up: MzScheme Architecture Previous: MzScheme Architecture

Scheme Values and Types

    A Scheme value is represented in 32 bits. The low bit is a mark bit: a 1 in the low bit indicates a 31-bit immediate integer, a 0 indicates a (word-aligned) pointer.gif

A Scheme value pointer references a structure that begins with a type tag. This type tag has the C type  Scheme_Type. The rest of the structure (following the type tag) is type-dependent. Examples of Scheme_Type values include  scheme_pair_type,  scheme_symbol_type, and  scheme_compiled_closure_type.

MzScheme's C interface gives Scheme values the type Scheme_Object *. (The ``Object'' here does not refer to objects in the sense of object-oriented programming.) The struct type  Scheme_Object is defined in ``scheme.h'', but never access this structure directly. Instead, use macros (such as SCHEME_CAR) which are provided to access the data of common Scheme types. A Scheme_Object structure is actually only used by types which need 64 bits of data (in addition to the type tag).

For all standard Scheme types, constructors are provided for creating Scheme values. For example, scheme_make_pair takes two Scheme_Object * values and returns the  cons of the values.

The macro  SCHEME_TYPE takes a Scheme_Object * and returns the type of the object. This macro performs the tag-bit check, and returns  scheme_integer_type when the value is an immediate integer; otherwise, SCHEME_TYPE follows the pointer to get the type tag. Macros are provided to test for common Scheme types; for example, SCHEME_PAIRP returns 1 if the value is a Scheme cons cell, or 0 otherwise.

  In addition to the standard Scheme data types, there are six global constant Scheme values:  scheme_true,  scheme_false,  scheme_null,  scheme_eof,  scheme_void, and  scheme_undefined.

  Applications can create new a primitive data type by calling  scheme_make_type. Create objects for this type by allocating memory with  scheme_malloc. The only constraint on the data format of an instance of the type data is that it must start with the Scheme_Type value returned by scheme_make_type.




previous up next     contents index
Next: Standard Types Up: MzScheme Architecture Previous: MzScheme Architecture

PLT