Skip to content
stefano edited this page Sep 12, 2010 · 2 revisions

Welcome to the nyac wiki!

The type system

Every object in the runtime system is represented by a 4 bytes pointer. The lowest 3 bits of this pointer decide its type, and the others 29 bits its content. The content can be either an immediate value or a pointer to a memory area in the heap. In order to assure that an address in the heap have the lowest 3 bits set to 0 so that they don’t interfere with the tag every object must be allocated at 8 byte boundaries. Fixnums are treated specially beacuse they use only 2 bits as a tag.

Simple Types Tag Table

Type Content Tag
Fixnum 30-bit integer 00
Cons cell 29-bit adrdess 001
Vector 29-bit address 101
Closure 29-bit address 010
Symbol 29-bit address 011
Extended 29-bit adress 110

Objects with the tag 111 are treated as fixed values:

Fixed Values Table

Name Content
Nil 0000 0000 0000 0000 0000 0000 0010 1111
T 0000 0000 0000 0000 0000 0000 0110 1111
Unbound Value 0000 0000 0000 0000 0000 0000 1111 1111

Characters are 8-bit ASCII characters.

Character Configuration

Character 0000 0000 0000 0000 <8-bit ASCII value> 0000 1111

Objects tagged with 110 are treated as extended objects: the first 4 bytes of the memory area referenced by the address content contain an extended type tag. The extended type tag is then followed by the contents of the object

Extended Objects Tag Table

Type Tag Followed by
String <30-bit fixnum> 00 8-bit characters, as many as specified by the fixnum in the tag
Float 0000 0000 0000 0000 0000 0000 1100 1111 8-byte double precision floating point number

Structures

Cons cell: 8 bytes divided in 2 4-byte parts: the car and the cdr, which can have any value

size 4 byte 4 byte
content car cdr

Vector: 4 bytes telling the length of the vector followed by the 4-byte elements

size 4 byte 4 byte 4 byte 4 byte
content length element 0 element 1 element n-1

Closure: 3 mandatory fields holding the address of the code of the function, the number of the other fields (symbol + closed variables), a symbol representing the function for printing purposes, and then the references to the closed variables.

size 4 byte 4 byte 4 byte 4 byte 4 byte
content number of closed vars + 1 code address function name 1st closed variable n-th closed variable

Symbol: string representing the symbol, a global value associated with it (eventually the unbound value), and a pointer to its property list

size 4 byte 4 byte 4 byte
content pointer to a string global value associated with the symbol p-list