Tail-Recursive Stack Disciplines for an Interpreter
Tail-Recursive Stack Disciplines for an Interpreter
复制标题
解释器的尾递归堆栈规则
DOI:
--
复制
发表时间:
1992
期刊:
影响因子:
--
通讯作者:
R. Kelsey
中科院分区:
文献类型:
--
作者:
R. Kelsey
Many languages, including Scheme, ML, and Haskell, require that their implementations support tail-recursive calls to arbitrary depth. This requirement means that a traditional stack discipline cannot be used for these languages. This paper examines several diierent methods of implementing proper tail recursion in a stack-based interpeter, including passing arguments in a heap, copying arguments to tail-recursive calls, and garbage collecting the stack. Benchmark timings and other run-time statistics are used to compare the diierent methods. The results show that using a stack is a good idea, and that the overhead of the interpreter largely overshadows the diierences in performance of the various stack disciplines. 1 The Problem A programming language implementation is properly tail recursive if unbounded iterative computations that are expressed recursively can be executed in constant space. Implementations of languages such as Scheme Rees 86], ML Milner 88], and Haskell Hudak 90] are required to be tail recursive. These languages also require that some lexical environments have in-deenite extent. That is, arguments passed to a procedure may need to be preserved until long after the procedure has returned. Similarly, in Scheme, continuations also may have indeenite extent. A continuation is all of the information that is saved across a procedure call and used to restart the procedure's caller once the procedure returns. In Scheme procedure invoca-tions may return more than once, so continuations may need to be saved for later use.