1
0
Fork 0
cl-sites/ecl.common-lisp.dev/static/manual/Evaluation-and-compilation.html

268 lines
13 KiB
HTML
Raw Permalink Normal View History

2024-12-24 19:15:49 +01:00
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Evaluation and compilation (ECL Manual)</title>
<meta name="description" content="Evaluation and compilation (ECL Manual)">
<meta name="keywords" content="Evaluation and compilation (ECL Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Indexes.html" rel="index" title="Indexes">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Standards.html" rel="up" title="Standards">
<link href="Types-and-classes.html" rel="next" title="Types and classes">
<link href="Overview.html" rel="prev" title="Overview">
<style type="text/css">
<!--
/* colors */
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
@media (prefers-color-scheme: dark) {
/* dark theme */
html { color: seashell;
background: #1A1A1A; }
body { background: #1A1A1A; }
th { border-bottom: 2px solid lightgray; }
h1, h2, h3, h4, h5 { background-image: linear-gradient(to left, #202020, #3A3A3A); }
code, var, code a { color: darkorange;
background: #2A2A2A; }
a { color: seashell; }
pre { background: #2A2A2A;
color: seashell;
/* mark longer code block with stripe on the left */
border-left: 5px solid darkorange;
padding-left: 10px; }
pre.screen { background: #2A2A2A;
border: 1px solid lightgray; }
pre.programlisting { background: #2A2A2A;
border-left: 1px solid lightgray;
border-top: 1px solid lightgray; }
/* we need a light background in order for the images to be readable */
img { background: white }
}
@media (prefers-color-scheme: light) {
/* light theme */
html { background: white }
body { background: white }
th { border-bottom: 2px solid gray; }
h1, h2, h3, h4, h5 { background: lightgray; }
code, var, code a { color: darkred;
background: whitesmoke; }
a { color: #000; }
pre { background: whitesmoke;
color: black;
/* mark longer code block with stripe on the left */
border-left: 5px solid darkred;
padding-left: 10px; }
pre.screen { background: #EEE;
border: 1px solid black; }
pre.programlisting { background: #EEEEEE;
border-left: 1px solid black;
border-top: 1px solid black; }
}
body {
margin: 1em 125px 0 10%;
line-height: 1.5em;
padding: 0 2em 1em 2em;
font: 13px Verdana,Arial, sans-serif
}
ul, dd, dl, dt { margin-top: 0; margin-bottom: 0; }
p, code, td, dl, dt {
line-height: 1.5em;
}
table {
font: inherit;
border-collapse: collapse;
}
th, td {
vertical-align: top;
}
h1, h2, h3 { padding-left: 15px; }
h4, h5 { padding-left: 5px; }
code, pre {
font-size: 1em;
font-family: monospace;
}
var {
font-size: 1em;
}
/* links inside code appear the same as the code itself */
code a {
font-weight: normal;
text-decoration: none;
}
/* but get an underline when hovering */
code a:hover {
text-decoration: underline;
}
/* ordinary links appear in bold */
a { font-weight: bold; }
pre.verbatim {
margin: 0 0 0 0;
}
pre {
overflow: auto;
}
pre.screen {
font-weight: bold;
padding: 0.5em;
}
pre.programlisting {
padding: 0.5em;
}
div p { padding: 0 2em }
li p { padding: 0; margin: 0 }
hr { display: none; }
div.funcsynopsis p {
text-indent: -2em;
}
div.variablelist {
padding: 0 2em;
}
.type, .funcsynopsis, .symbol {
font-family: monospace;
}
.type, .symbol, .replaceable {
white-space: nowrap;
}
-->
</style>
</head>
<body lang="en">
<div class="section-level-extent" id="Evaluation-and-compilation">
<div class="nav-panel">
<p>
Next: <a href="Types-and-classes.html" accesskey="n" rel="next">Types and classes</a>, Previous: <a href="Overview.html" accesskey="p" rel="prev">Overview</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
</div>
<h3 class="section" id="Evaluation-and-compilation-1">2.2 Evaluation and compilation</h3>
<ul class="mini-toc">
<li><a href="Evaluation-and-compilation.html#Compiler-declaration-optimize" accesskey="1">Compiler declaration <code class="code">optimize</code></a></li>
<li><a href="Evaluation-and-compilation.html#declaim-and-proclaim" accesskey="2"><code class="code">declaim</code> and <code class="code">proclaim</code></a></li>
<li><a href="Evaluation-and-compilation.html#C-Reference-2" accesskey="3">C Reference</a></li>
</ul>
<div class="subsection-level-extent" id="Compiler-declaration-optimize">
<h4 class="subsection">2.2.1 Compiler declaration <code class="code">optimize</code></h4>
<a class="index-entry-id" id="index-Compiler-declarations"></a>
<a class="index-entry-id" id="index-optimize"></a>
<a class="index-entry-id" id="index-debug"></a>
<a class="index-entry-id" id="index-speed"></a>
<a class="index-entry-id" id="index-safety"></a>
<a class="index-entry-id" id="index-space"></a>
<p>The <code class="code">optimize</code> declaration includes three concepts: <code class="code">debug</code>,
<code class="code">speed</code>, <code class="code">safety</code> and <code class="code">space</code>. Each of these declarations
can take one of the integer values 0, 1, 2 and 3. According to these
values, the implementation may decide how to compile or interpret a given
lisp form.
</p>
<p>ECL currently does not use all these declarations, but some of them
definitely affect the speed and behavior of compiled functions. For
instance, the <code class="code">debug</code> declaration, as shown in
<a class="ref" href="Evaluation-and-compilation.html#tab_003aoptimize_002ddebug">Table 2.1</a>, the value of debugging is zero, the function
will not appear in the debugger and, if redefined, some functions might
not see the redefinition.
</p>
<div class="float" id="tab_003aoptimize_002ddebug">
<table class="multitable">
<thead><tr><th>Behavior</th><th>0</th><th>1</th><th>2</th><th>3</th></tr></thead>
<tbody><tr><td>Compiled functions in the same source file are called directly</td><td>Y</td><td>Y</td><td>N</td><td>N</td></tr>
<tr><td>Compiled function appears in debugger backtrace</td><td>N</td><td>N</td><td>Y</td><td>Y</td></tr>
<tr><td>All functions get a global entry (SI:C-LOCAL is ignored)</td><td>N</td><td>N</td><td>Y</td><td>Y</td></tr>
</tbody>
</table>
<div class="caption"><p><strong class="strong">Table 2.1: </strong>Behavior for different levels of <code class="code">debug</code></p></div></div>
<p>A bit more critical is the value of <code class="code">safety</code> because as shown in
<a class="ref" href="Evaluation-and-compilation.html#tab_003aoptimize_002dsafety">Table 2.2</a>, it may affect the safety checks generated
by the compiler. In particular, in some circumstances the compiler may
assume that the arguments to a function are properly typed. For
instance, if you compile with a low value of <code class="code">safety</code>, and invoke
<code class="code">rplaca</code> with an object which is not a list, the consequences are
unspecified.
</p>
<div class="float" id="tab_003aoptimize_002dsafety">
<table class="multitable">
<thead><tr><th>Behavior</th><th>0</th><th>1</th><th>2</th><th>3</th></tr></thead>
<tbody><tr><td>The compiler generates type checks for the arguments of a lambda form, thus enforcing any type declaration written by the user.</td><td>N</td><td>Y</td><td>Y</td><td>Y</td></tr>
<tr><td>The value of an expression or a variable declared by the user is assumed to be right.</td><td>Y</td><td>Y</td><td>N</td><td>N</td></tr>
<tr><td>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 class="code">car</code>, <code class="code">cdr</code>, etc</td><td>Y</td><td>Y</td><td>N</td><td>N</td></tr>
<tr><td>We believe types defined before compiling a file do not change before the compiled code is loaded.</td><td>Y</td><td>Y</td><td>N</td><td>N</td></tr>
<tr><td>Arguments in a lisp form are assumed to have the appropriate types so that the form will not fail.</td><td>Y</td><td>N</td><td>N</td><td>N</td></tr>
<tr><td>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 class="code">pathname-type</code>, <code class="code">car</code>, <code class="code">rest</code>, etc.</td><td>Y</td><td>N</td><td>N</td><td>N</td></tr>
</tbody>
</table>
<div class="caption"><p><strong class="strong">Table 2.2: </strong>Behavior for different levels of <code class="code">safety</code></p></div></div>
</div>
<div class="subsection-level-extent" id="declaim-and-proclaim">
<h4 class="subsection">2.2.2 <code class="code">declaim</code> and <code class="code">proclaim</code></h4>
<p>Declarations established with <code class="code">proclaim</code> stay in force
indefinitely. Declarations established with <code class="code">declaim</code> in a file
do not persist after the file has been compiled. However, they are
established with <code class="code">proclaim</code> at load time when the compiled file
is loaded. This means that when compiling two files, <code class="code">declaim</code>
declarations in the first file will not be in force when compiling the
second file unless the first file was loaded before the second one was
compiled.
</p>
</div>
<div class="subsection-level-extent" id="C-Reference-2">
<h4 class="subsection">2.2.3 C Reference</h4>
<a class="anchor" id="ecl_005fprocess_005fenv"></a><a class="index-entry-id" id="index-ecl_005fprocess_005fenv"></a>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-ecl_005fprocess_005fenv-1"><span class="category-def">C/C++ identifier: </span><span><code class="def-type">cl_env_ptr</code> <strong class="def-name">ecl_process_env</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href='Evaluation-and-compilation.html#index-ecl_005fprocess_005fenv-1'> &para;</a></span></dt>
<dd><p>ECL stores information about each thread on a dedicated structure, which
is the process environment. A pointer to this structure can be retrieved
using the function or macro above. This pointer can be used for a
variety of tasks, such as defining special variable bindings,
controlling interrupts, retrieving function output values, etc.
</p></dd></dl>
<ul class="mini-toc">
<li><a href="Evaluation-and-compilation.html#ANSI-Dictionary" accesskey="1">ANSI Dictionary</a></li>
</ul>
<div class="subsubsection-level-extent" id="ANSI-Dictionary">
<h4 class="subsubsection">2.2.3.1 ANSI Dictionary</h4>
<p>Common Lisp and C equivalence
</p>
<table class="multitable">
<thead><tr><th width="30%">Lisp symbol</th><th width="70%">C function</th></tr></thead>
<tbody><tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_cmp.htm">compile</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_eval.htm">eval</a></td><td width="70%">cl_object cl_eval (cl_object form) - <strong class="strong">DEPRECATED, see <a class="pxref" href="Manipulating-Lisp-objects.html#si_005fsafe_005feval">si_safe_eval</a></strong></td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_mexp_.htm">macroexpand</a></td><td width="70%">cl_object cl_macroexpand(cl_narg narg, cl_object form, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_mexp_.htm">macroexpand-1</a></td><td width="70%">cl_object cl_macroexpand_1(cl_narg narg, cl_object form, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_procla.htm">proclaim</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_specia.htm">special-operator-p</a></td><td width="70%">cl_object cl_special_operator_p(cl_object form)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_consta.htm">constantp</a></td><td width="70%">cl_object cl_constantp (cl_narg narg, cl_object arg, ...)</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Types-and-classes.html" accesskey="n" rel="next">Types and classes</a>, Previous: <a href="Overview.html" accesskey="p" rel="prev">Overview</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>