11

I am studying Forth for a personal project I have on my mind. It looks to be a really cool and simple language to implement in a small virtual machine.

I am especially impressed by the possibilities of the use of vocabularies on it. On the other hand, I think the way the dictionary works is overly complex for a language that is overall so simple. I say this, because I have read some papers about it, and I know that much controversy exist.

There are some microprocessors which implement some features of Forth in their instructions, and I am interested to know how they implement the dictionary and features like the vocabulary on them, so I can implement a virtual machine which look like those microprocessors.

That is, the dictionary is not a simple heap which grows up, and is not a simple linear vector which we can simply index, so it is not an easy thing for the microcode of a microprocessor to do (I guess). I would be really impressed if those special processors are capable to implement the dictionary like it should be, without any extra code, of course. I think this is impossible.

So for my project, I am considering to code the interpreter with a heap, with opcodes to manipulate it, like it is for example in the 6852. And the code for the dictionary, shall be compiled along with the interpreter and the editor in Forth. I think this should look more like the reality.

What is all this controversy about? How do these special processors work, with relation to the dictionary and the use of vocabularies?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • @otkins How are you planning to implement the virtual machine? In assembler? ANSI C? The choice of the implementation language and target architectures will have the greatest impact on how the dictionary could be implemented. – Vijay Mathew Sep 08 '10 at 04:01
  • Tell once again more precise, what microprocesor do You use, and what implementation of Forth You use at start? – Jacek Cz Apr 02 '16 at 08:31

2 Answers2

5

The Wikipedia article on Forth contains a short description on the original implementation of the Dictionary. Also see "Development and Dissemination" in The Evolution of Forth. The original implementation used a linked list. But a hashtable(map) seems to be a better approximation.

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
  • 2
    Here is the thing: The memory-management of a Linked list is a lot easier to implement than a hashmap. Linked-lists do have O(n) lookup (whereas hashmaps have amortized O(1)) but this is not a problem since name-lookup is only done once: when a word is compiled. What is then stored, are internal pointer references, rather than names. – Qqwy Mar 24 '18 at 14:02
0

Pick something smallish that runs on your machine, and go from there. Look for ciforth (need to be a m4 wizard, though...), eForth (lots of variants), ff, lbForth.

If you want to go all the way down to the iron, check out jonesforth (for x86_32) or jonesforth64 (for x86_64, bit i386 comments). It will explain how/why much of the mess hangs together.

vonbrand
  • 11,412
  • 8
  • 32
  • 52