Debian Codegraph @

src/doc/old-manual/ref_embed.xmlf

raw
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>
8 <title>Embedding</title>
9 <section xml:id="ext.embed.dict">
10 <title>Embedding Reference</title>
11
12 <!-- ====================================================================== -->
13 <!-- CL_CATCH_ALL -->
14 <!-- ====================================================================== -->
15
16 <refentry xml:id="ref.embed.cl_catch_all">
17 <refnamediv>
18 <refname><function>CL_CATCH_ALL</function></refname>
19 <refpurpose>Create a protected region.</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <title>C Macro</title>
24 <programlisting>
25 cl_env_ptr env = ecl_process_env();
26 CL_CATCH_ALL_BEGIN(env) {
27 /*
28 * Code that is protected. Uncaught lisp conditions, THROW,
29 * signals such as SIGSEGV and SIGBUS may cause jump to
30 * this region.
31 */
32 } CL_CATCH_ALL_IF_CAUGHT {
33 /*
34 * If the exception, lisp condition or other control transfer
35 * is caught, this code is executed.
36 */
37 } CL_CATCH_ALL_END
38 /*
39 * In all cases we exit here.
40 */
41 </programlisting>
42 </refsynopsisdiv>
43
44 <refsect1>
45 <title>Description</title>
46
47 <para>This is a set of three macros that create an
48 <function>UNWIND-PROTECT</function> region that prevents any nonlocal transfer
49 of control to outer loops. In the Lisp speak, the previous code is
50 equivalent to</para>
51 <programlisting>
52 (block nil
53 (unwind-protect
54 (progn
55 ;; Code that is protected
56 )
57 (return nil)))
58 </programlisting>
59
60 <para>As explained in <xref linkend="ref.embed.cl_unwind_protect" xrefstyle="select: label"/>,it is normally advisable to set up an unwind-protect frame to avoid the embedded lisp code to perform arbitary transfers of control.</para>
61 </refsect1>
62
63 <refsect1>
64 <title>See also</title>
65
66 <para><link linkend="ref.embed.cl_unwind_protect"><function>cl_unwind_protect</function></link></para>
67 </refsect1>
68 </refentry>
69
70 <!-- ====================================================================== -->
71 <!-- CL_UNWIND_PROTECT -->
72 <!-- ====================================================================== -->
73
74 <refentry xml:id="ref.embed.cl_unwind_protect">
75 <refnamediv>
76 <refname><function>CL_UNWIND_PROTECT</function></refname>
77 <refpurpose>Create a protected region.</refpurpose>
78 </refnamediv>
79
80 <refsynopsisdiv>
81 <title>C Macro</title>
82 <programlisting>
83 cl_env_ptr env = ecl_process_env();
84 CL_UNWIND_PROTECT_BEGIN(env) {
85 /*
86 * Code that is protected. Uncaught lisp conditions, THROW,
87 * signals such as SIGSEGV and SIGBUS may cause jump to
88 * this region.
89 */
90 } CL_UNWIND_PROTECT_EXIT {
91 /*
92 * If the exception, lisp condition or other control transfer
93 * is caught, this code is executed. After this code, the
94 * process will jump to the original destination of the
95 * THROW, GOTO or other control statement that was interrupted.
96 */
97 } CL_UNWIND_PROTECT_END
98 /*
99 * We only exit here if NO nonlocal jump was interrupted.
100 */
101 </programlisting>
102 </refsynopsisdiv>
103
104 <refsect1>
105 <title>Description</title>
106
107 <para>When embedding &ECL; it is normally advisable to set up an
108 unwind-protect frame to avoid the embedded lisp code to perform arbitary
109 transfers of control. Furthermore, the unwind protect form will be
110 used in at least in the following ocasions:</para>
111 <itemizedlist>
112 <listitem>
113 <para>In a normal program exit, caused by <function>ext:quit</function>,
114 &ECL; unwinds up to the outermost frame, which may be an <xref
115 linkend="ref.embed.cl_catch_all"/> or <xref
116 linkend="ref.embed.cl_unwind_protect"/> macro.</para>
117 </listitem>
118 </itemizedlist>
119
120 <para>Besides this, normal mechanisms for exit, such as
121 <function>ext:quit</function>, and uncaught exceptions, such as serious
122 signals (<xref linkend="ext.signals.synchronous"/>), are best handled using
123 unwind-protect blocks.</para>
124 </refsect1>
125
126 <refsect1>
127 <title>See also</title>
128
129 <para><xref linkend="ref.embed.cl_catch_all"/></para>
130 </refsect1>
131 </refentry>
132
133 <!-- ====================================================================== -->
134 <!-- cl_boot() -->
135 <!-- ====================================================================== -->
136
137 <refentry xml:id="ref.embed.cl_boot">
138 <refnamediv>
139 <refname><function>cl_boot</function></refname>
140 <refpurpose>Setup the lisp environment.</refpurpose>
141 </refnamediv>
142
143 <refsynopsisdiv>
144 <title>Function</title>
145 <funcsynopsis>
146 <?dbhtml funcsynopsis-style='ansi'?>
147 <funcprototype>
148 <funcdef>int <function>cl_boot</function></funcdef>
149 <paramdef>int <parameter>argc</parameter></paramdef>
150 <paramdef>char **<parameter>argv</parameter></paramdef>
151 </funcprototype>
152 </funcsynopsis>
153 <variablelist>
154 <varlistentry>
155 <term><replaceable>argc</replaceable></term>
156 <listitem><para>An integer with the number of arguments to this program.</para></listitem>
157 <term><replaceable>argv</replaceable></term>
158 <listitem><para>A vector of strings with the arguments to this program.</para></listitem>
159 </varlistentry>
160 </variablelist>
161 </refsynopsisdiv>
162
163 <refsect1>
164 <title>Description</title>
165
166 <para>This function must be called before any other function from the &ECL;
167 library, including the creation of any lisp object or evaluating any lisp code.
168 The only exception are <xref linkend="ref.embed.ecl_set_option"/>
169 and <xref linkend="ref.embed.ecl_get_option"/>.
170 </para>
171 </refsect1>
172 </refentry>
173
174 <!-- ====================================================================== -->
175 <!-- cl_shutdown() -->
176 <!-- ====================================================================== -->
177
178 <refentry xml:id="ref.embed.cl_shutdown">
179 <refnamediv>
180 <refname><function>cl_shutdown</function></refname>
181 <refpurpose>Close the lisp environment.</refpurpose>
182 </refnamediv>
183
184 <refsynopsisdiv>
185 <title>Function</title>
186 <funcsynopsis>
187 <?dbhtml funcsynopsis-style='ansi'?>
188 <funcprototype>
189 <funcdef>int <function>cl_shutdown</function></funcdef>
190 <paramdef>void</paramdef>
191 </funcprototype>
192 </funcsynopsis>
193 </refsynopsisdiv>
194
195 <refsect1>
196 <title>Description</title>
197
198 <para>This function must be called before exiting a program that uses the &ECL;
199 environment. It performs some cleaning, including the execution of any
200 finalizers, unloading shared libraries and deleting temporary files that were
201 created by the compiler.
202 </para>
203 </refsect1>
204 </refentry>
205
206 <!-- ====================================================================== -->
207 <!-- ecl_set_option() -->
208 <!-- ====================================================================== -->
209
210 <refentry xml:id="ref.embed.ecl_set_option">
211 <refnamediv>
212 <refname><function>ecl_set_option</function></refname>
213 <refpurpose>Set a boot option.</refpurpose>
214 </refnamediv>
215
216 <refsynopsisdiv>
217 <title>Function</title>
218 <funcsynopsis>
219 <?dbhtml funcsynopsis-style='ansi'?>
220 <funcprototype>
221 <funcdef>void <function>ecl_set_option</function></funcdef>
222 <paramdef>int <parameter>option</parameter></paramdef>
223 <paramdef>cl_fixnum <parameter>value</parameter></paramdef>
224 </funcprototype>
225 </funcsynopsis>
226 <variablelist>
227 <varlistentry>
228 <term><replaceable>option</replaceable></term>
229 <listitem><para>An integer from <xref linkend="table.boot_options"/>.</para></listitem>
230 </varlistentry>
231 <varlistentry>
232 <term><replaceable>value</replaceable></term>
233 <listitem><para>A <type>cl_index</type> value for this option.</para></listitem>
234 </varlistentry>
235 </variablelist>
236 </refsynopsisdiv>
237
238 <refsect1>
239 <title>Description</title>
240 <para>This functions sets the value of different options that have
241 to be customized <emphasis>before</emphasis> &ECL; boots. The table
242 of options and default values [<xref linkend="table.boot_options"/>]
243 shows that some of them are boolean, and some of them are unsigned
244 integers.</para>
245
246 <para>We distinguish three sets of values. The first set determines
247 whether &ECL; handles certain exceptions, such as access to forbidden
248 regions of memory, interrupts via <keycombo>Ctrl-C</keycombo>, floating point
249 exceptions, etc.</para>
250
251 <para>The second set is related to the sizes of different
252 stacks. Currently &ECL; uses four stacks: a bind stack for keeping
253 assignments to special variables; a frame stack for implementing
254 blocks, tagbodys and catch points; an interpreter stack for
255 evaluating bytecodes, and finally the machine or C stack, of the
256 computer we run in. We can set the expected size of these stacks,
257 together with the size of a safety area which, if penetrated, will
258 lead to the generation of a correctable error.</para>
259
260 <table xml:id="table.boot_options">
261 <title>Boot options for embedded &ECL;</title>
262 <tgroup cols="4">
263 <thead>
264 <row>
265 <entry>Name (<constant>ECL_OPT_*</constant>)</entry>
266 <entry>Type</entry>
267 <entry>Default</entry>
268 <entry>Description</entry>
269 </row>
270 </thead>
271 <tbody>
272 <row>
273 <entry><constant>INCREMENTAL_GC</constant></entry>
274 <entry><type>boolean</type></entry>
275 <entry><constant>TRUE</constant></entry>
276 <entry>Activate generational garbage collector.</entry>
277 </row>
278 <row>
279 <entry><constant>TRAP_SIGSEGV</constant></entry>
280 <entry><type>boolean</type></entry>
281 <entry><constant>TRUE</constant></entry>
282 <entry>Capture SIGSEGV signals.</entry>
283 </row>
284 <row>
285 <entry><constant>TRAP_SIGFPE</constant></entry>
286 <entry><type>boolean</type></entry>
287 <entry><constant>TRUE</constant></entry>
288 <entry>Capture floating point exceptions.</entry>
289 </row>
290 <row>
291 <entry><constant>TRAP_SIGINT</constant></entry>
292 <entry><type>boolean</type></entry>
293 <entry><constant>TRUE</constant></entry>
294 <entry>Capture user interrupts.</entry>
295 </row>
296 <row>
297 <entry><constant>TRAP_SIGILL</constant></entry>
298 <entry><type>boolean</type></entry>
299 <entry><constant>TRUE</constant></entry>
300 <entry>Capture SIGILL exception.</entry>
301 </row>
302 <row>
303 <entry><constant>TRAP_INTERRUPT_SIGNAL</constant></entry>
304 <entry><type>boolean</type></entry>
305 <entry><constant>TRUE</constant></entry>
306 <entry>Capture the signal that implements
307 <function>mp:interrupt-process</function>.</entry>
308 </row>
309 <row>
310 <entry><constant>SIGNAL_HANDLING_THREAD</constant></entry>
311 <entry><type>boolean</type></entry>
312 <entry><constant>TRUE</constant></entry>
313 <entry>Create a signal to capture and process asynchronous threads (See
314 <xref linkend="ext.signals.asynchronous-handler"/>).</entry>
315 </row>
316 <row>
317 <entry><constant>BOOTED</constant></entry>
318 <entry><type>boolean</type></entry>
319 <entry><constant>TRUE/FALSE</constant></entry>
320 <entry>Has &ECL; booted (read only).</entry>
321 </row>
322 <row>
323 <entry><constant>BIND_STACK_SIZE</constant></entry>
324 <entry><type>cl_index</type></entry>
325 <entry><constant>8192</constant></entry>
326 <entry>Size of stack for binding special variables.</entry>
327 </row>
328 <row>
329 <entry><constant>BIND_STACK_SAFETY_AREA</constant></entry>
330 <entry><type>cl_index</type></entry>
331 <entry><constant>128</constant></entry>
332 <entry></entry>
333 </row>
334 <row>
335 <entry><constant>FRAME_STACK_SIZE</constant></entry>
336 <entry><type>cl_index</type></entry>
337 <entry><constant>2048</constant></entry>
338 <entry>Size of stack for nonlocal jumps.</entry>
339 </row>
340 <row>
341 <entry><constant>FRAME_STACK_SAFETY_AREA</constant></entry>
342 <entry><type>cl_index</type></entry>
343 <entry><constant>128</constant></entry>
344 <entry></entry>
345 </row>
346 <row>
347 <entry><constant>LISP_STACK_SIZE</constant></entry>
348 <entry><type>cl_index</type></entry>
349 <entry><constant>32768</constant></entry>
350 <entry>Size of interpreter stack.</entry>
351 </row>
352 <row>
353 <entry><constant>LISP_STACK_SAFETY_AREA</constant></entry>
354 <entry><type>cl_index</type></entry>
355 <entry><constant>128</constant></entry>
356 <entry></entry>
357 </row>
358 <row>
359 <entry><constant>C_STACK_SIZE</constant></entry>
360 <entry><type>cl_index</type></entry>
361 <entry><constant>131072</constant></entry>
362 <entry>Size of C stack (not exact).</entry>
363 </row>
364 <row>
365 <entry><constant>C_STACK_SAFETY_AREA</constant></entry>
366 <entry><type>cl_index</type></entry>
367 <entry><constant>4192</constant></entry>
368 <entry></entry>
369 </row>
370 <row>
371 <entry><constant>THREAD_INTERRUPT_SIGNAL</constant></entry>
372 <entry><type>unsigned int</type></entry>
373 <entry><constant>0</constant></entry>
374 <entry>If nonzero, specify the unix signal which is used to
375 communicate different Lisp threads.</entry>
376 </row>
377 </tbody>
378 </tgroup>
379 </table>
380
381 </refsect1>
382
383 </refentry>
384
385 <!-- ====================================================================== -->
386 <!-- ecl_get_option() -->
387 <!-- ====================================================================== -->
388
389 <refentry xml:id="ref.embed.ecl_get_option">
390 <refnamediv>
391 <refname><function>ecl_get_option</function></refname>
392 <refpurpose>Read the value of a boot option.</refpurpose>
393 </refnamediv>
394
395 <refsynopsisdiv>
396 <title>Function</title>
397 <funcsynopsis>
398 <?dbhtml funcsynopsis-style='ansi'?>
399 <funcprototype>
400 <funcdef>cl_fixnum <function>ecl_get_option</function></funcdef>
401 <paramdef>int <parameter>option</parameter></paramdef>
402 </funcprototype>
403 </funcsynopsis>
404 <variablelist>
405 <varlistentry>
406 <term><replaceable>option</replaceable></term>
407 <listitem><para>An integer from <xref linkend="table.boot_options"/>.</para></listitem>
408 </varlistentry>
409 </variablelist>
410 </refsynopsisdiv>
411
412 <refsect1>
413 <title>Description</title>
414 <para>This functions reads the value of different options that have
415 to be customized <emphasis>before</emphasis> &ECL; boots. The table
416 of options and default values is <xref linkend="table.boot_options"/>.
417 </para>
418 </refsect1>
419 </refentry>
420
421 <!-- ====================================================================== -->
422 <!-- ecl_clear_interrupts() -->
423 <!-- ====================================================================== -->
424
425 <refentry xml:id="ref.embed.ecl_clear_interrupts">
426 <refnamediv>
427 <refname><function>ecl_clear_interrupts</function></refname>
428 <refpurpose>Clear all pending signals and exceptions.</refpurpose>
429 </refnamediv>
430
431 <refsynopsisdiv>
432 <title>Macro</title>
433 <funcsynopsis>
434 <?dbhtml funcsynopsis-style='ansi'?>
435 <funcprototype>
436 <funcdef><function>ecl_clear_interrupts</function></funcdef>
437 <paramdef></paramdef>
438 </funcprototype>
439 </funcsynopsis>
440 </refsynopsisdiv>
441
442 <refsect1>
443 <title>Description</title>
444 <para>This macro clears all pending interrupts.
445 </para>
446 </refsect1>
447
448 <refsect1>
449 <title>See also</title>
450 <para> <xref linkend="ref.embed.ecl_disable_interrupts"/> and <xref
451 linkend="ref.embed.ecl_enable_interrupts"/>.
452 </para>
453 </refsect1>
454 </refentry>
455
456 <!-- ====================================================================== -->
457 <!-- ecl_disable_interrupts() -->
458 <!-- ====================================================================== -->
459
460 <refentry xml:id="ref.embed.ecl_disable_interrupts">
461 <refnamediv>
462 <refname><function>ecl_disable_interrupts</function></refname>
463 <refpurpose>Postpone handling of signals and exceptions.</refpurpose>
464 </refnamediv>
465
466 <refsynopsisdiv>
467 <title>Macro</title>
468 <funcsynopsis>
469 <?dbhtml funcsynopsis-style='ansi'?>
470 <funcprototype>
471 <funcdef><function>ecl_disable_interrupts</function></funcdef>
472 <paramdef></paramdef>
473 </funcprototype>
474 </funcsynopsis>
475 </refsynopsisdiv>
476
477 <refsect1>
478 <title>Description</title>
479 <para>This macro sets a thread-local flag indicating that all received
480 signals should be queued for later processing.
481 </para>
482 </refsect1>
483
484 <refsect1>
485 <title>See also</title>
486 <para><xref linkend="ref.embed.ecl_enable_interrupts"/> and <xref
487 linkend="ref.embed.ecl_clear_interrupts"/>.
488 </para>
489 </refsect1>
490 </refentry>
491
492 <!-- ====================================================================== -->
493 <!-- ecl_enable_interrupts() -->
494 <!-- ====================================================================== -->
495
496 <refentry xml:id="ref.embed.ecl_enable_interrupts">
497 <refnamediv>
498 <refname><function>ecl_enable_interrupts</function></refname>
499 <refpurpose>Activate handling of signals and exceptions.</refpurpose>
500 </refnamediv>
501
502 <refsynopsisdiv>
503 <title>Macro</title>
504 <funcsynopsis>
505 <?dbhtml funcsynopsis-style='ansi'?>
506 <funcprototype>
507 <funcdef><function>ecl_enable_interrupts</function></funcdef>
508 <paramdef></paramdef>
509 </funcprototype>
510 </funcsynopsis>
511 </refsynopsisdiv>
512
513 <refsect1>
514 <title>Description</title>
515 <para>This macro sets a thread-local flag indicating that all received
516 signals can be handled. If there are any pending signals, they will be
517 immediately processed.
518 </para>
519 </refsect1>
520
521 <refsect1>
522 <title>See also</title>
523 <para><xref
524 linkend="ref.embed.ecl_disable_interrupts"/> and <xref
525 linkend="ref.embed.ecl_clear_interrupts"/>.
526 </para>
527 </refsect1>
528 </refentry>
529 </section>
530 </chapter>
531 </book>
532 <!-- Keep this comment at the end of the file
533 Local variables:
534 mode: nxml
535 sgml-parent-document: "ecl.xml"
536 sgml-indent-step: 1
537 nxml-child-indent: 1
538 nxml-outline-child-indent: 1
539 fill-column: 79
540 End:
541 -->