正在加载图片...
Solutions Solution 1 (a la C):disallow nested procedures: when we have no nested procedures,we never access non-static non-locals and so we need not preserve our caller's stack frame Solution 2(a la Pascal):disallow returning procedures from the scope where they are created: when we call a procedure indirectly,we are guaranteed that the stack frames for scopes within which it is nested exist on stack this requires eliminating assignment of procedures to local variables,but allows for passing procedures as parameters Solution 3(a la Lisp/Scheme):use tree instead of stack for procedure's local data this creates a record for each procedure(called closure)when a procedure is defined(not when it is called) allocating closures is costly;freeing requires a garbage collector (to be discussed later in the course) CS308 Compiler TheorySolutions • Solution 1 (a la C): disallow nested procedures: – when we have no nested procedures, we never access non-static non-locals and so we need not preserve our caller’s stack frame • Solution 2 (a la Pascal): disallow returning procedures from the scope Solution 2 (a la Pascal): disallow returning procedures from the scope where they are created: – when we call a procedure indirectly, we are guaranteed that the stack frames for scopes within which it is nested exist on stack – this requires eliminating assignment of procedures to local variables, but allows for passing procedures as parameters • Solution 3 (a la Lisp/Scheme): use tree instead of stack for procedure’s local data – this creates a record for each procedure (called closure) when a procedure is defined (not when it is called) – allocating closures is costly; freeing requires a garbage collector (to be discussed later in 9 the course) CS308 Compiler Theory
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有