Add notes about dictionary
authorJonas Hvid <mail@johv.dk>
Thu, 14 Nov 2019 16:32:21 +0000 (17:32 +0100)
committerJonas Hvid <mail@johv.dk>
Thu, 14 Nov 2019 16:32:21 +0000 (17:32 +0100)
notes

diff --git a/notes b/notes
index c50b57b0ac58a9c1015e8046af6bb3a137423333..c23bee740dcee51e2d91f95f1c6691baa0c5d68d 100644 (file)
--- a/notes
+++ b/notes
@@ -5,3 +5,31 @@ FASM:
 
 JONESFORTH:
 - https://github.com/nornagon/jonesforth/blob/master/jonesforth.S
+
+# Notes on implementation
+
+## Dictionary
+
+In Forth, words are stored in a dictionary. The dictionary is a linked list whose entries look like this:
+    +------------------------+--------+---------- - - - - +----------- - - - -
+    | LINK POINTER           | LENGTH/| NAME              | DEFINITION
+    |                        | FLAGS  |                   |
+    +--- (4 bytes) ----------+- byte -+- n bytes  - - - - +----------- - - - -
+For example, DOUBLE and QUADRUPLE may be stored like this:
+      pointer to previous word
+       ^
+       |
+    +--|------+---+---+---+---+---+---+---+---+------------- - - - -
+    | LINK    | 6 | D | O | U | B | L | E | 0 | (definition ...)
+    +---------+---+---+---+---+---+---+---+---+------------- - - - -
+       ^       len                         padding
+       |
+    +--|------+---+---+---+---+---+---+---+---+---+---+---+---+------------- - - - -
+    | LINK    | 9 | Q | U | A | D | R | U | P | L | E | 0 | 0 | (definition ...)
+    +---------+---+---+---+---+---+---+---+---+---+---+---+---+------------- - - - -
+       ^       len                                     padding
+       |
+       |
+  LATEST
+The Forth variable LATEST contains a pointer to the most recently defined word.
+