From 004f684b103b49f38d28d4282624c09975688b99 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Thu, 14 Nov 2019 17:32:21 +0100 Subject: [PATCH] Add notes about dictionary --- notes | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/notes b/notes index c50b57b..c23bee7 100644 --- 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. + -- 2.39.2