Stack Frames and Local Variables
نویسنده
چکیده
The stack frame technique for dynamic local variable storage in Algol and descendant languages may be adopted in Forth to expand the number of elements easily handJed directly on the stack, reducing the need for variables. The required extensions to Forth can preserve the interactive quality of Forth by using the parameter stack exclusively and by using a built-in set of local variable names rather than an argument list compiler. Special techniques such as wildcard names, code pointer arrays, and modifications of TO can reduce the overhead involved. Forth provides a computation stack to store temporary data along with stack operators to rearrange that data, but lacks a facility found in Algol and similar post-Fortran languages to allocate variable storage on the stack. In these languages variables so allocated are local to a particular procedure and referred to loosely as "local variables", even though that term encompasses statically as well as dynamically allocated variables. When their storage is dynamically allocated such variables allow calling procedures recursively and recovering memory occupied when procedures are completed. The allocation is accomplished by pushing on the stack a block of space, called a stack frame, to hold all the variables for each recursive call to a procedure, and dropping the block when returning from each call. Each variable is then represented in object code by an offset relative to the frame boundary instead of by an absolute memory address. Data is fetched from and stored into the framed memory the same as ordinary variables, in contrast to Forth's emphasis on rearranging the order in which data is stored on the stack. CPU makers have supported dynamic local variables with hardware registers specifically for base relative addressing on the stack, as in the Burroughs mainframes and the Intel 8086 microprocessor. In Forth, however, local variables have not been used much, at least outside of Europe; as early as 1977 Paul Bartholdi at the Geneva Observatory introduced Forth extensions to employ local variables on the stack[2]. They are rarely found in commercially available systems, and the Forth Standard[4] not only does not include them, but prohibits indexing into the stacks of the Forth pseudo-machine as well. More recently, and with increasing frequency, a number of papers have appeared expressing a need for local variables in Forth and describing a variety of Forth extensions to provide them [3,4,10,11,12,15,16,17]. This paper develops further the particular technique of using a set oflocal variable names built into the system and available for use in all procedures, as opposed to defining new local variable names in every instance. Methods for implementing this technique are examined from the standpoint of achieving general applicability, minimizing the costs incurred, and preserving the interactive features of the Forth environment. I An extension of remarks at the FORML conference in Taiwan, Republic of China, September, 1984. The Journal of Forth Application and Research Volume 3, Number 1, 1985
منابع مشابه
Suspension Frames on the WAM Heap
A suspension encapsulates everything needed to execute a piece of code many times in the same context: the need for this feature exists in constraint solver programming, where (part of) a predicate checking the satisfiability of a set of a constraints needs to be re-executed every time the domain of a concerned variable changes. Traditional extensions of the WAM support a heap term and metacall...
متن کاملOptimizing the stack size of recursive functions
For memory constrained environments, optimization for program size is often as important as, if not more important than, optimization for execution speed. Commonly, compilers try to reduce the code segment but neglect the stack segment, although the stack can significantly grow during the execution of recursive functions because a separate activation record is required for each recursive call. ...
متن کاملOptimizing Stack Frame Accesses for Processors with Restricted Addressing Modes
Random access to local variables stored in a stack frame is more difficult for compiled functions when the target processor lacks register-plus-offset addressing. One alternative technique employs a roving pointer which the program increments or decrements as needed between stack accesses. Processors which support auto-increment and auto-decrement addressing modes are often capable of performin...
متن کاملSI 413, Unit 9: Implementation Issues
Recall from Unit 6 that there are three ways variable storage can be allocated in a program: statically, on the stack, or from the heap. Statically allocated variables have a lifetime equal to the entire program execution; they never die. Stack allocation is tied to function calls, so anything allocated on the stack (such as local variables within a function) will simply be de-allocated when th...
متن کاملExtended Weighted Pushdown Systems
Recent work on weighted-pushdown systems shows how to generalize interprocedural-dataflow analysis to answer “stack-qualified queries”, which answer the question “what dataflow values hold at a program node for a particular set of calling contexts?” The generalization, however, does not account for precise handling of local variables. Extended-weighted-pushdown systems address this issue, and p...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2010