Preface: I've written extensions for hardware debuggers to trace some problems with messed call stacks, so I've seen some hex dumps of actual C
stacks.
The C
stack consists of a mixture of return addresses, local variables and function parameters. For each function you can find out where it expects which value, but this knowledge stops at the scope of the function.
You can do it this way with forth
as well, but this means a giant overhead: You can place your parameters on the stack and call the function, placing the return address on top of the same stack. No problem: Each command knows that the operands are second and following on the stack. But now the command wants to call another command with these values: This makes it neccessary to change the order of the stack to put the values on top again, as the called command can't know where they are buried in the stack, as you wrote.
A more complex forth
compiler could keep track of how many values each command takes and sort the stack before each command call. But at what cost!
Of course, C
programs have this overhead, too. If you see non-inline function calls in inline assembly, there is always some register swapping overhead. But good forth
programs consist of tiny functions, so you have a lot more function calling and a lot more overhead.
And without any benefit, as in modern computer architecture each register can be used as stack pointer, so you could have a handful of stacks without any problem.
So finally, the answer to your question is: Yes, you can implement a one-stack derivative of forth
, but it's pain without gain.