| 1 |
@node Evaluation and compilation |
| 2 |
@section Evaluation and compilation |
| 3 |
|
| 4 |
@subsection Compiler declaration @code{optimize} |
| 5 |
@cindex Compiler declarations |
| 6 |
@lspindex optimize |
| 7 |
@lspindex debug |
| 8 |
@lspindex speed |
| 9 |
@lspindex safety |
| 10 |
@lspindex space |
| 11 |
|
| 12 |
The @code{optimize} declaration includes three concepts: @code{debug}, |
| 13 |
@code{speed}, @code{safety} and @code{space}. Each of these declarations |
| 14 |
can take one of the integer values 0, 1, 2 and 3. According to these |
| 15 |
values, the implementation may decide how to compile or interpret a given |
| 16 |
lisp form. |
| 17 |
|
| 18 |
ECL currently does not use all these declarations, but some of them |
| 19 |
definitely affect the speed and behavior of compiled functions. For |
| 20 |
instance, the @code{debug} declaration, as shown in |
| 21 |
@ref{tab:optimize-debug}, the value of debugging is zero, the function |
| 22 |
will not appear in the debugger and, if redefined, some functions might |
| 23 |
not see the redefinition. |
| 24 |
|
| 25 |
@float Table, tab:optimize-debug |
| 26 |
@caption{Behavior for different levels of @code{debug}} |
| 27 |
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {a} {a} {a} {a} |
| 28 |
@headitem Behavior |
| 29 |
@tab 0 |
| 30 |
@tab 1 |
| 31 |
@tab 2 |
| 32 |
@tab 3 |
| 33 |
|
| 34 |
@item Compiled functions in the same source file are called directly |
| 35 |
@tab Y |
| 36 |
@tab Y |
| 37 |
@tab N |
| 38 |
@tab N |
| 39 |
|
| 40 |
@item Compiled function appears in debugger backtrace |
| 41 |
@tab N |
| 42 |
@tab N |
| 43 |
@tab Y |
| 44 |
@tab Y |
| 45 |
|
| 46 |
@item All functions get a global entry (SI:C-LOCAL is ignored) |
| 47 |
@tab N |
| 48 |
@tab N |
| 49 |
@tab Y |
| 50 |
@tab Y |
| 51 |
|
| 52 |
@end multitable |
| 53 |
@end float |
| 54 |
|
| 55 |
A bit more critical is the value of @code{safety} because as shown in |
| 56 |
@ref{tab:optimize-safety}, it may affect the safety checks generated |
| 57 |
by the compiler. In particular, in some circumstances the compiler may |
| 58 |
assume that the arguments to a function are properly typed. For |
| 59 |
instance, if you compile with a low value of @code{safety}, and invoke |
| 60 |
@code{rplaca} with an object which is not a list, the consequences are |
| 61 |
unspecified. |
| 62 |
|
| 63 |
@float Table, tab:optimize-safety |
| 64 |
@caption{Behavior for different levels of @code{safety}} |
| 65 |
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {a} {a} {a} {a} |
| 66 |
@headitem Behavior |
| 67 |
@tab 0 |
| 68 |
@tab 1 |
| 69 |
@tab 2 |
| 70 |
@tab 3 |
| 71 |
|
| 72 |
@item The compiler generates type checks for the arguments of a lambda form, thus enforcing any type declaration written by the user. |
| 73 |
@tab N |
| 74 |
@tab Y |
| 75 |
@tab Y |
| 76 |
@tab Y |
| 77 |
|
| 78 |
@item The value of an expression or a variable declared by the user is assumed to be right. |
| 79 |
@tab Y |
| 80 |
@tab Y |
| 81 |
@tab N |
| 82 |
@tab N |
| 83 |
|
| 84 |
@item We believe type declarations and type inference and, if the type of a form is inferred to be right for a function, slot accessor, etc, this may be inlined. Affects functions like @code{car}, @code{cdr}, etc |
| 85 |
@tab Y |
| 86 |
@tab Y |
| 87 |
@tab N |
| 88 |
@tab N |
| 89 |
|
| 90 |
@item We believe types defined before compiling a file do not change before the compiled code is loaded. |
| 91 |
@tab Y |
| 92 |
@tab Y |
| 93 |
@tab N |
| 94 |
@tab N |
| 95 |
|
| 96 |
@item Arguments in a lisp form are assumed to have the appropriate types so that the form will not fail. |
| 97 |
@tab Y |
| 98 |
@tab N |
| 99 |
@tab N |
| 100 |
@tab N |
| 101 |
|
| 102 |
@item The slots or fields in a lisp object are accessed directly without type checks even if the type of the object could not be inferred (see line above). Affects functions like @code{pathname-type}, @code{car}, @code{rest}, etc. |
| 103 |
@tab Y |
| 104 |
@tab N |
| 105 |
@tab N |
| 106 |
@tab N |
| 107 |
|
| 108 |
@end multitable |
| 109 |
@end float |
| 110 |
|
| 111 |
@subsection @code{declaim} and @code{proclaim} |
| 112 |
Declarations established with @code{proclaim} stay in force |
| 113 |
indefinitely. Declarations established with @code{declaim} in a file |
| 114 |
do not persist after the file has been compiled. However, they are |
| 115 |
established with @code{proclaim} at load time when the compiled file |
| 116 |
is loaded. This means that when compiling two files, @code{declaim} |
| 117 |
declarations in the first file will not be in force when compiling the |
| 118 |
second file unless the first file was loaded before the second one was |
| 119 |
compiled. |
| 120 |
|
| 121 |
@subsection C Reference |
| 122 |
|
| 123 |
@cppdef ecl_process_env |
| 124 |
@deftypefn @cind{} cl_env_ptr ecl_process_env () |
| 125 |
ECL stores information about each thread on a dedicated structure, which |
| 126 |
is the process environment. A pointer to this structure can be retrieved |
| 127 |
using the function or macro above. This pointer can be used for a |
| 128 |
variety of tasks, such as defining special variable bindings, |
| 129 |
controlling interrupts, retrieving function output values, etc. |
| 130 |
@end deftypefn |
| 131 |
|
| 132 |
@subsubsection ANSI Dictionary |
| 133 |
Common Lisp and C equivalence |
| 134 |
|
| 135 |
@multitable @columnfractions .3 .7 |
| 136 |
@headitem Lisp symbol @tab C function |
| 137 |
@item @clhs{f_cmp.htm,compile} @tab [Only in Common Lisp] |
| 138 |
@item @clhs{f_eval.htm,eval} @tab cl_object cl_eval (cl_object form) - @strong{DEPRECATED, @pxref{si_safe_eval}} |
| 139 |
@item @clhs{f_mexp_.htm,macroexpand} @tab cl_object cl_macroexpand(cl_narg narg, cl_object form, ...) |
| 140 |
@item @clhs{f_mexp_.htm,macroexpand-1} @tab cl_object cl_macroexpand_1(cl_narg narg, cl_object form, ...) |
| 141 |
@item @clhs{f_procla.htm,proclaim} @tab [Only in Common Lisp] |
| 142 |
@item @clhs{f_specia.htm,special-operator-p} @tab cl_object cl_special_operator_p(cl_object form) |
| 143 |
@item @clhs{f_consta.htm,constantp} @tab cl_object cl_constantp (cl_narg narg, cl_object arg, ...) |
| 144 |
@end multitable |