Next: , Previous: , Up: Value methods   [Contents]


17.4 Maintaining the stack

This section discusses in detail the requirements for maintaining the stack. In some cases, such as implementation using a Perl array, fulfilling these requirements is trivial. Perl auto-extends its arrays, and initializes the element values, on every read or write. For the C programmer, things are not quite so easy.

In this section, we will assume a C90 or C99 standard-conformant C application. This assumption is convenient on two grounds. First, this will be the intended use for many readers. Second, standard-conformant C is a “worst case”. Any issue faced by a programmer of another environment is likely to also be one that must be solved by the C programmer.

Libmarpa often optimizes away unnecessary stack writes to stack locations. When it does so, it will not necessarily optimize away all reads to that stack location. This means that a location’s first access, as suggested by the Libmarpa step instructions, may be a read. This possibility requires a special awareness from the C programmer, as discussed in the sections Sizing the stack and Initializing locations in the stack.

In the discussions in this document, stack locations are non-negative integers. The bottom of the stack is location 0. In moving from the bottom of the stack to the top, the numbers increase. Stack location Y is said to be “greater” than stack location X if stack location Y is closer to the top of stack than location X, and therefore stack locations are considered greater or lesser if the integers that represent them are greater or lesser. Another way to state that a stack location Y is greater (lesser) than stack location X is to say that a stack location Y is later (earlier) than stack location X.


Next: , Previous: , Up: Value methods   [Contents]