dpp.txi 2.19 KB
Newer Older
Daniel Kochmański's avatar
Daniel Kochmański committed
1 2 3 4
@node Defun preprocessor
@section Defun preprocessor

@cindex Defun preprocessor
5 6 7 8 9
The defun preprocessor allows for convenient definition of Lisp
functions with optional and keyword arguments and the use of Lisp
symbols in ECL's own C source code. It generates the C code necessary
to use optional function arguments and to access symbols in ECL's
builtin symbol table.
Daniel Kochmański's avatar
Daniel Kochmański committed
10 11

Usage:
12
@verbatim
Daniel Kochmański's avatar
Daniel Kochmański committed
13
        dpp [in-file [out-file]]
14
@end verbatim
Daniel Kochmański's avatar
Daniel Kochmański committed
15 16 17 18 19 20 21 22 23

The file named in-file is preprocessed and the output will be
written to the file whose name is out-file. If in-file is "-"
program is read from standard input, while if out-file is "-"
C-program is written to standard output.

The function definition:

@exindex dpp: function definition
Marius Gerbershagen's avatar
Marius Gerbershagen committed
24
@example
25
@verbatim
Daniel Kochmański's avatar
Daniel Kochmański committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
@(defun name ({var}*
              [&optional {var | (var [initform [svar]])}*]
              [&rest var]
              [&key {var |
                     ({var | (keyword var)} [initform [svar]])}*
                    [&allow_other_keys]]
              [&aux {var | (var [initform])}*])

        C-declaration

@ {

        C-body

} @)
41
@end verbatim
Marius Gerbershagen's avatar
Marius Gerbershagen committed
42
@end example
Daniel Kochmański's avatar
Daniel Kochmański committed
43

44
name is the name of the lisp function
Daniel Kochmański's avatar
Daniel Kochmański committed
45

46 47 48 49 50
&optional may be abbreviated as &o.@*
&rest may be abbreviated as &r.@*
&key may be abbreviated as &k.@*
&allow_other_keys may be abbreviated as &aok.@*
&aux may be abbreviated as &a.
Daniel Kochmański's avatar
Daniel Kochmański committed
51

52
Each variable becomes a C variable.
Daniel Kochmański's avatar
Daniel Kochmański committed
53

54
Each supplied-p parameter becomes a boolean C variable.
Daniel Kochmański's avatar
Daniel Kochmański committed
55

56 57 58
Initforms are C expressions.
If an expression contains non-alphanumeric characters,
it should be surrounded by backquotes (`).
Daniel Kochmański's avatar
Daniel Kochmański committed
59 60


61
Function return:
Marius Gerbershagen's avatar
Marius Gerbershagen committed
62
@example
63 64 65
@verbatim
        @(return {form}*);
@end verbatim
Marius Gerbershagen's avatar
Marius Gerbershagen committed
66
@end example
Daniel Kochmański's avatar
Daniel Kochmański committed
67

68 69 70 71
Return function expands into a lexical block @verb{|{}|}, so if it's
used inside IF/ELSE, then it should be enclosed, even if we
use sole @verb{|@(return);|}, because ";" will be treated as the next
instruction.
Daniel Kochmański's avatar
Daniel Kochmański committed
72

73
Symbols:
Daniel Kochmański's avatar
Daniel Kochmański committed
74

Marius Gerbershagen's avatar
Marius Gerbershagen committed
75
@example
76 77 78
@verbatim
@'name'
@end verbatim
Marius Gerbershagen's avatar
Marius Gerbershagen committed
79
@end example
80 81 82 83

Expands into a C statement, whole value is the given symbol
from symbols_list.h

Marius Gerbershagen's avatar
Marius Gerbershagen committed
84
@example
85 86 87
@verbatim
@[name]
@end verbatim
Marius Gerbershagen's avatar
Marius Gerbershagen committed
88
@end example
89 90 91 92

Expands into a C statement, whole value is a fixnum
corresponding to the index in the builtin symbols table of the
given symbol from symbols_list.h. Used for handling type errors.