On 7/03/2024 12:28 am, Ruvim wrote:
...
In SP-Forth v3 and v4 (they generate native code), "DO" pushes three items on the return stack, and among them the address that "LEAVE" then jumps to. ...
That is the classic implementation as suggested by Bob Berkey - inventor of >the Forth-83 DO LOOP. IIUC Anton is asking about systems that push the loop >address - not the exit address.
Yes, kForth uses this method. DO pushes three items onto the return
stack, the two loop parameters, and the virtual instruction pointer.
\ From ForthVM.cpp
int CPP_do ()
{
// stack: ( -- | generate opcodes for beginning of loop structure )
pCurrentOps->push_back(OP_PUSH);
pCurrentOps->push_back(OP_PUSH);
pCurrentOps->push_back(OP_PUSHIP);
dostack.push(pCurrentOps->size());
return 0;
}
DO LOOP in FIG / ISO say FORTH is a mess anyway. The idea that >signed/unsigned numbers can be handled uniformly was cute at the
time, when you could not spare 10 bytes. In the 50 years no novice
even dared to try negative indices or negative increments.
dxf <dxforth@gmail.com> writes:
On 7/03/2024 12:28 am, Ruvim wrote:
...
In SP-Forth v3 and v4 (they generate native code), "DO" pushes three items on the return stack, and among them the address that "LEAVE" then jumps to. ...
That is the classic implementation as suggested by Bob Berkey - inventor of >> the Forth-83 DO LOOP. IIUC Anton is asking about systems that push the loop >> address - not the exit address.
Correct.
So, to summarize the answers:
kForth keeps the loop-back address on the return stack in addition to
index and limit.
A number of systems (at least ciForth, VFX, SP-Forth) have followed
Bob Berkey's suggestion of keeping the loop-exit address on the return
stack for LEAVE. That is not what I was asking about, but it's also interesting.
On 10/03/2024 5:09 am, Anton Ertl wrote:
It's difficult to imagine under
what circumstances a loop address on the stack is faster, but it suggests
one is starting from an inefficient or compromised base.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 914 |
Nodes: | 10 (1 / 9) |
Uptime: | 233:28:52 |
Calls: | 12,157 |
Files: | 186,518 |
Messages: | 2,232,635 |