| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<chapter xml:id="The-interpreter"> |
| 8 |
<title>The Interpreter</title> |
| 9 |
<para>Former versions of &ECL;, as well as many other lisps, used linked lists to |
| 10 |
represent code. As of version 0.3 a bytecodes compiler and a bytecodes |
| 11 |
interpreter were developed to circumvent the limitations of linked lists.</para> |
| 12 |
<para>When you enter code at the lisp prompt, or when you load a source file, |
| 13 |
&ECL; begins a process known as minimal compilation. Barely this |
| 14 |
process consists on parsing each form, macroexpanding it and translating |
| 15 |
it into an intermediate language made of <emphasis>bytecodes</emphasis>.</para> |
| 16 |
<para>The bytecodes compiler is implemented in <filename>src/c/compiler.d</filename>. The main |
| 17 |
entry point is the lisp function <literal>SI::MAKE-LAMBDA</literal>, which takes a |
| 18 |
name for the function and the body of the lambda lists, and produces a |
| 19 |
lisp object that can be invoked. For instance,</para> |
| 20 |
<para><screen> |
| 21 |
> (defvar fun (si::make-lambda 'f '((x) (1+ x)))) |
| 22 |
*FUN* |
| 23 |
> (funcall fun 2) |
| 24 |
3 |
| 25 |
</screen></para> |
| 26 |
<para>&ECL; can only execute bytecodes. When a list is passed to <literal>EVAL</literal> it |
| 27 |
must be first compiled to bytecodes and, if the process succeeds, then the |
| 28 |
resulting bytecodes are passed to the interpreter. Similarly, every time a |
| 29 |
function object is created, such as in <literal>DEFUN</literal> or <literal>DEFMACRO</literal>, the |
| 30 |
bytecodes compiler processes the lambda form to produce a suitable bytecodes |
| 31 |
object.</para> |
| 32 |
<para>The fact that &ECL; performs this eager compilation means that changes on |
| 33 |
a macro are not immediately seen in code which was already compiled. This has |
| 34 |
subtle implications. Take the following code:<screen> |
| 35 |
> (defmacro f (a b) `(+ ,a ,b)) |
| 36 |
F |
| 37 |
> (defun g (x y) (f x y)) |
| 38 |
G |
| 39 |
> (g 1 2) |
| 40 |
3 |
| 41 |
> (defmacro f (a b) `(- ,a ,b)) |
| 42 |
F |
| 43 |
> (g 1 2) |
| 44 |
3 |
| 45 |
</screen></para> |
| 46 |
<para role="continues">The last statement always outputs <literal>3</literal> while in former |
| 47 |
implementations based on processing of lambda lists it would produce <literal>-1</literal>.</para> |
| 48 |
</chapter> |
| 49 |
<!-- Keep this comment at the end of the file |
| 50 |
Local variables: |
| 51 |
sgml-parent-document: "ecl.xml" |
| 52 |
sgml-indent-step: 1 |
| 53 |
nxml-child-indent: 1 |
| 54 |
nxml-outline-child-indent: 1 |
| 55 |
fill-column: 79 |
| 56 |
End: |
| 57 |
--></book> |