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:
After token insert h@ everywhere.
Otherwise, remove h@ everywhere, and recode the execute word accordingly.
The compile, then becomes a synonym for , so replace that everywhere as well, and move another token down into the spot previously occupied by compile,.
Make new and create leave an address rather than a token on the stack, by replacing hp @ here h, with here dup h,.
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.
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 ofh@
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 theh@
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,
andtoken
to understand where the integer tokens originate and make sure they are all replaced with addresses. This PR contains the corresponding changes, in summary:token
inserth@
everywhere.h@
everywhere, and recode theexecute
word accordingly.compile,
then becomes a synonym for,
so replace that everywhere as well, and move another token down into the spot previously occupied bycompile,
.new
andcreate
leave an address rather than a token on the stack, by replacinghp @ here h,
withhere dup h,
.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.