A language like C uses the system stack for local variables and return addresses. Forth has the data stack and the return stack. Is there an implementation of Forth that uses the system stack as the return stack and hence uses the return instruction to end execution of a word? Is this a feasible approach?
4
votes
Welcome to SO! Please see how to ask. It is unclear what you are trying to do here.
– DCTID
Does this answer your question? Can a Forth-like language be implemented with just one stack?
– Philippos
@DCTID It does no harm to reread how to ask. I'm into Forth and I can assure you that the question makes sense
– Albert van der Horst
3 Answers
2
votes
The native call
and ret
instructions are used in the subroutine-threaded code. And in this case the system stack plays role of the return stack in Forth.
SP-Forth/4 is an example of a Forth system that uses this approach (see forthproc) along with peephole optimization.
0
votes
0
votes
It's possible to make a Forth-like language that uses only one stack, but if you want a Forth that's compatible with standard Forth programs you would need separate data stack and return stack. Forth passes arguments from function to function by just leaving them on the data stack; if you use one stack for both data and flow control you need to be careful to clean the data off the stack before a function ends.