next up previous contents
Next: 5 Advanced Compiler Use Up: 4 The Compiler Previous: The Optimize-Interface Declaration

4.8 Open Coding and Inline Expansion

       

Since Common Lisp forbids the redefinition of standard functionsgif, the compiler can have special knowledge of these standard functions embedded in it. This special knowledge is used in various ways (open coding, inline expansion, source transformation), but the implications to the user are basically the same:

When a function call is ıopen coded, inline code whose effect is equivalent to the function call is substituted for that function call. When a function call is ıclosed coded, it is usually left as is, although it might be turned into a call to a different function with different arguments. As an example, if nthcdr were to be open coded, then

(nthcdr 4 foobar)
might turn into
(cdr (cdr (cdr (cdr foobar))))
or even
(do ((i 0 (1+ i))
     (list foobar (cdr foobar)))
    ((= i 4) list))

If nth is closed coded, then

(nth x l)
might stay the same, or turn into something like:
(car (nthcdr x l))

In general, open coding sacrifices space for speed, but some functions (such as car) are so simple that they are always open-coded. Even when not open-coded, a call to a standard function may be transformed into a different function call (as in the last example) or compiled as ıstatic call. Static function call uses a more efficient calling convention that forbids redefinition.


next up previous contents
Next: 5 Advanced Compiler Use Up: 4 The Compiler Previous: The Optimize-Interface Declaration

Raymond Toy
Mon Jul 14 09:11:27 EDT 1997