Go to the first, previous, next, last section, table of contents.


Structure Implementation

The central idea in the implementation is to pass the data about the structure being built on the stack, not in some global variable. Everything else falls into place naturally once this design decision is made.

The type description on the stack is of the form align size. Keeping the size on the top-of-stack makes dealing with arrays very simple.

field is a defining word that uses create and does>. The body of the field contains the offset of the field, and the normal does> action is

 +

i.e., add the offset to the address, giving the stack effect addr1 -- addr2 for a field.

This simple structure is slightly complicated by the optimization for fields with offset 0, which requires a different does>-part (because we cannot rely on there being something on the stack if such a field is invoked during compilation). Therefore, we put the different does>-parts in separate words, and decide which one to invoke based on the offset. For a zero offset, the field is basically a noop; it is immediate, and therefore no code is generated when it is compiled.


Go to the first, previous, next, last section, table of contents.