Previous: , Up: layout   [Contents][Index]


2.3 Block objects

Block objects are represented by a pointer to a C language structure with a header and a data block; slightly simplified, it looks like this:

#define C_uword  unsigned C_word
#define C_header C_uword

typedef struct
{
  C_header header;
  C_word data[];    /* Variable-length array: header determines length */
} C_SCHEME_BLOCK;

The header’s bit pattern is broken up into three parts:

The representation in machine words uses the least significant byte:

XXXXYYYY ZZZZZZZZ ZZZZZZZZ ZZZZZZZZ
 GC type size of object (slot or byte count)

this is the meaning of the bit groups:

The type bits are assigned incrementally. There is room for 16 types, only 2 of which are currently unused. Let’s look at the definitions, which should also help to explain the practical use of the latter 3 GC bits:

#define C_SYMBOL_TYPE            (0x01000000L)
#define C_STRING_TYPE            (0x02000000L | C_BYTEBLOCK_BIT)
#define C_PAIR_TYPE              (0x03000000L)
#define C_CLOSURE_TYPE           (0x04000000L | C_SPECIALBLOCK_BIT)
#define C_FLONUM_TYPE            (0x05000000L | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)
/*      unused                   (0x06000000L ...) */
#define C_PORT_TYPE              (0x07000000L | C_SPECIALBLOCK_BIT)
#define C_STRUCTURE_TYPE         (0x08000000L)
#define C_POINTER_TYPE           (0x09000000L | C_SPECIALBLOCK_BIT)
#define C_LOCATIVE_TYPE          (0x0a000000L | C_SPECIALBLOCK_BIT)
#define C_TAGGED_POINTER_TYPE    (0x0b000000L | C_SPECIALBLOCK_BIT)
#define C_LAMBDA_INFO_TYPE       (0x0d000000L | C_BYTEBLOCK_BIT)
/*      unused                   (0x0e000000L ...) */
#define C_BUCKET_TYPE            (0x0f000000L)

Most of the types should be self–explanatory to a seasoned Schemer, but a few things deserve further explanation.

So far, the only numeric types we’ve seen are fixnums and flonums. What about the other numeric types? After all, CHICKEN 5 has a full numeric tower!

In CHICKEN 5, rational and complex numbers are viewed as two simpler numbers stuck together. They’re stored as records with a special tag, which the runtime system recognises. Bignums are also represented as a record with a special tag and a slot that refers to the byte blob containing the actual bignum value.


Previous: , Up: layout   [Contents][Index]