A pointer is a fixed length memory block, two words wide, referenced by machine words tagged as vectors. The first machine word of a pointer block is tagged has pointer in its least significant bits and it has the most significant bits set to zero. The second machine word of a pointer block holds the actual pointer value.
|------------------------|-------------| reference to pointer
heap pointer vector tag
|------------------------|-------------| pointer first word
all set to zero pointer tag
|--------------------------------------| pointer second word
pointer value
Pointers are allocated on the Scheme heap as follows:
ikpcb * pcb = ik_the_pcb();
ikptr s_ptr;
s_ptr = ik_safe_alloc(pcb, pointer_size) | vector_tag;
IK_REF(s_ptr, off_pointer_tag) = pointer_tag;
to identify an object as pointer we do:
ikptr X = the_object;
if ((vector_tag == IK_TAGOF(X)) &&
(pointer_tag == IK_REF(X, -vector_tag)))
it_is_a_pointer();
else
it_is_not();
to set or retrieve the pointer value we do:
ikptr s_ptr = the_pointer;
void * ptr;
ptr = (void *)IK_REF((X), off_pointer_data);
IK_REF((X), off_pointer_data) = (ikptr)ptr;
The tag of
ikptrvalues used as first words in pointer memory blocks.
Displacement of secondary tag word. The number of bytes to add to an untagged pointer to pointer object to get the pointer to the first byte in the word holding the pointer tag.
Displacement of data area. The number of bytes to add to an untagged pointer to pointer object to get the pointer to the first byte of the data area.
An integer to add to add to a tagged
ikptrpointer to pointer object to get the pointer to the first byte in the word holding the pointer tag.
An integer to add to a tagged
ikptrpointer to pointer object to get the pointer to the first byte of the word holding the pointer value.
Return the value of the pointer cast to a specific type.
Reset to ptr the value of the pointer X.
Evaluate to true if the pointer value is
NULL.
Allocate a pointer object using
ik_safe_alloc()and return a tagged reference to it. The pointer is initialised to memory.