uho / preForth

a minimalistic Forth kernel that can bootstrap
GNU General Public License v3.0
74 stars 8 forks source link

Execution token is address #14

Open nickd4 opened 2 years ago

nickd4 commented 2 years ago

Since initially coming to preForth, the execute word has bothered me a bit. It takes on the stack an integer token number, then executes the equivalent of h@ to read the corresponding address from the headers table, and then "calls" the defined word at that address (by a tail call). I have wanted to remove the h@ for efficiency reasons, i.e. simply pop an address and execute it.

This required me to undertake an analysis of all calls to hp, h@, h, and token to understand where the integer tokens originate and make sure they are all replaced with addresses. This PR contains the corresponding changes, in summary:

It works. I think this is more efficient and simpler code. Also, it opens the door to some further improvements that would aim to use the headers table only for communication with the tokenizer, maybe even reclaiming that memory once *.seed is running.