S
SM Ryan
# Keith Thompson wrote:
#
# > [...]
# >> Languages like C actually use two virtual stacks, a protocol
# >> stack and an operand stack, but the language semantics are such
# >> to allow the stacks to be interleaved onto one physical stack.
# > [...]
# >
# > What is an "operand stack"?
#
# As I understand the post, SM Ryan used the terms 'protocol stack'
# and 'operand stack' in this way:
#
# Protocol stack: data structure with stack semantics that contains the
# return addresses for the currently active functions.
Also called the return stack. It contains the call/return linkages.
# Operand stack: data structure with stack semantics that contains the
# arguments and return values of the currently active functions.
Also called the value or parameter stack. Contains operator parameters
and return values.
# This distinction between two stacks can be useful if a system only has
# hardware support for, for example, a stack of return addresses.
It's useful for understanding language semantics. The reason structs
could not originally be function returns and why arrays still cannot
is because the function return is sandwiched between the operand stack
frames of the caller and callee. The compiler needs some way to slide
the function result through the return linkage. That was easy when
the function result could be entirely included in the registers.
Forth and Postscript maintain separate stacks. Ada implementations
often use two stacks as well to avoid copying function returns.
#
# > [...]
# >> Languages like C actually use two virtual stacks, a protocol
# >> stack and an operand stack, but the language semantics are such
# >> to allow the stacks to be interleaved onto one physical stack.
# > [...]
# >
# > What is an "operand stack"?
#
# As I understand the post, SM Ryan used the terms 'protocol stack'
# and 'operand stack' in this way:
#
# Protocol stack: data structure with stack semantics that contains the
# return addresses for the currently active functions.
Also called the return stack. It contains the call/return linkages.
# Operand stack: data structure with stack semantics that contains the
# arguments and return values of the currently active functions.
Also called the value or parameter stack. Contains operator parameters
and return values.
# This distinction between two stacks can be useful if a system only has
# hardware support for, for example, a stack of return addresses.
It's useful for understanding language semantics. The reason structs
could not originally be function returns and why arrays still cannot
is because the function return is sandwiched between the operand stack
frames of the caller and callee. The compiler needs some way to slide
the function result through the return linkage. That was easy when
the function result could be entirely included in the registers.
Forth and Postscript maintain separate stacks. Ada implementations
often use two stacks as well to avoid copying function returns.