herkforth dictionary format
The herkforth dictionary format will change. e.g. color_mod will be removed, and at some point I won't use a struct anymore. This data will be stored in separate arrays.
The dictionary is simply an array of dictionary entry structures. New
entries are added at the end. dict-start
and dict-new
point to the
first (oldest) entry and to the first free entry (the one which will be
used for the next new definition), respectively.
Dictionary entries are 32 bytes long. They have the following fields:
- data (4 bytes) use depends on word color (see below)
- flags (4 bytes) (see below)
- variable value (4 bytes) (unused for non-variables)
- source (4 bytes) Where this word is defined (block number (first two bytes) and which token
- name (16 bytes) string. up to 16 chars padded (if nessesary) on the right with null bytes.
data element has the following meanings:
- For colors 0, 1 and 7: pointer to the compiled code for the word (CFA)
- For colors 2, 3 and 6: number (to be compiled (LIT) or put on the stack)
- For variables this is a pointer to another field in the dictionary where the variable's value is
I am about to change the flags element. It will be a simple type field stored in a separate arary. The types will be:
- 0: unknown
- 1: word
- 2: number
- 3: literal
- 4: variable
- 5: data
You can get these values with dicti->type
. The constants are/should-be
named wtype-unknown
, wtype-word
etc.. Create the one you want if it
doesn't exist yet.
flags element starts with a byte with the following bit flags (starting with the most significant)
- true if this is a number, named constant or variable
- number
- constant
- variable
- data (eg string)
The second byte in the flags element is the color_mod. The editor remembers the color you are typing in (0: yellow, 1: green). Adding color_mod to this gives the correct color bits for the new source token.