chiark / gitweb /
src/c-types-impl.lisp: Refactor pretty-printing of function types.
[sod] / doc / clang.tex
CommitLineData
dea4d055
MW
1%%% -*-latex-*-
2%%%
1f7d590d 3%%% C language utilities
dea4d055 4%%%
1f7d590d 5%%% (c) 2015 Straylight/Edgeware
dea4d055
MW
6%%%
7
8%%%----- Licensing notice ---------------------------------------------------
9%%%
e0808c47 10%%% This file is part of the Sensible Object Design, an object system for C.
dea4d055
MW
11%%%
12%%% SOD is free software; you can redistribute it and/or modify
13%%% it under the terms of the GNU General Public License as published by
14%%% the Free Software Foundation; either version 2 of the License, or
15%%% (at your option) any later version.
16%%%
17%%% SOD is distributed in the hope that it will be useful,
18%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
19%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20%%% GNU General Public License for more details.
21%%%
22%%% You should have received a copy of the GNU General Public License
23%%% along with SOD; if not, write to the Free Software Foundation,
24%%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
1f7d590d 26\chapter{C language utilities} \label{ch:clang}
dea4d055
MW
27
28%%%--------------------------------------------------------------------------
1f7d590d 29\section{C type representation} \label{sec:clang.c-types}
dea4d055 30
1f7d590d 31\subsection{Overview} \label{sec:clang.c-types.over}
dea4d055
MW
32
33The Sod translator represents C types in a fairly simple and direct way.
34However, because it spends a fair amount of its time dealing with C types, it
35provides a number of useful operations and macros.
36
64d1ecf7 37The class hierarchy is shown in~\xref{fig:codegen.c-types.classes}.
dea4d055
MW
38
39\begin{figure} \centering
40 \parbox{10pt}{\begin{tabbing}
1f7d590d
MW
41 @|c-type| \\ \ind
42 @|qualifiable-c-type| \\ \ind
43 @|simple-c-type| \\ \ind
dea4d055 44 @|c-class-type| \- \\
1f7d590d 45 @|tagged-c-type| \\ \ind
dea4d055
MW
46 @|c-struct-type| \\
47 @|c-union-type| \\
48 @|c-enum-type| \- \\
49 @|c-pointer-type| \- \\
50 @|c-array-type| \\
51 @|c-function-type|
52 \end{tabbing}}
53 \caption{Classes representing C types}
64d1ecf7 54\label{fig:codegen.c-types.classes}
dea4d055
MW
55\end{figure}
56
57C type objects are immutable unless otherwise specified.
58
59\subsubsection{Constructing C type objects}
60There is a constructor function for each non-abstract class of C type object.
61Note, however, that constructor functions need not generate a fresh type
62object if a previously existing type object is suitable. In this case, we
63say that the objects are \emph{interned}. Some constructor functions are
64specified to return interned objects: programs may rely on receiving the same
65(@|eq|) type object for similar (possibly merely @|equal|) arguments. Where
66not specified, clients may still not rely on receiving fresh objects.
67
58f9b400
MW
68A convenient S-expression notation is provided by the
69\descref{c-type}[macro]{mac}. Use of this macro is merely an abbreviation
70for corresponding use of the various constructor functions, and therefore
71interns type objects in the same manner. The syntax accepted by the macro
72can be extended in order to support new classes: see \descref{defctype}{mac},
73\descref{c-type-alias}{mac} and \descref{define-c-type-syntax}{mac}.
dea4d055
MW
74
75The descriptions of each of the various classes include descriptions of the
76initargs which may be passed to @|make-instance| when constructing a new
77instance of the class. However, the constructor functions and S-expression
78syntax are strongly recommended over direct use of @|make-instance|.
79
80\subsubsection{Printing}
81There are two protocols for printing C types. Unfortunately they have
82similar names.
83\begin{itemize}
58f9b400
MW
84\item The \descref{print-c-type}[function]{gf} prints a C type value using
85 the S-expression notation. It is mainly useful for diagnostic purposes.
86\item The \descref{pprint-c-type}[function]{gf} prints a C type as a
87 C-syntax declaration.
dea4d055
MW
88\end{itemize}
89Neither generic function defines a default primary method; subclasses of
90@|c-type| must define their own methods in order to print correctly.
91
31d4431b 92
1f7d590d 93\subsection{The C type root class} \label{sec:clang.c-types.root}
dea4d055
MW
94
95\begin{describe}{cls}{c-type ()}
96 The class @|c-type| marks the root of the built-in C type hierarchy.
97
98 Users may define subclasses of @|c-type|. All non-abstract subclasses must
99 have a primary method defined on @|pprint-c-type|; unless instances of the
100 subclass are interned, a method on @|c-type-equal-p| is also required.
101
102 The class @|c-type| is abstract.
103\end{describe}
104
31d4431b 105
1f7d590d 106\subsection{C type S-expression notation} \label{sec:clang.c-types.sexp}
dea4d055
MW
107
108The S-expression representation of a type is described syntactically as a
109type specifier. Type specifiers fit into two syntactic categories.
110\begin{itemize}
111\item A \emph{symbolic type specifier} consists of a symbol. It has a
112 single, fixed meaning: if @<name> is a symbolic type specifier, then each
113 use of @<name> in a type specifier evaluates to the same (@|eq|) type
114 object, until the @<name> is redefined.
115\item A \emph{type operator} is a symbol; the corresponding specifier is a
116 list whose @|car| is the operator. The remaining items in the list are
117 arguments to the type operator.
118\end{itemize}
119
1f7d590d 120\begin{describe}{mac}{c-type @<type-spec> @> @<c-type>}
dea4d055
MW
121 Evaluates to a C type object, as described by the type specifier
122 @<type-spec>.
123\end{describe}
124
1f7d590d 125\begin{describe}{mac}
e43d3532
MW
126 {defctype \=@{ @<name> @! (@<name>^+) @} @<type-spec> \+ \\
127 @[[ @|:export| @<export-flag> @]]^* \-
128 \nlret @<names>}
dea4d055
MW
129 Defines a new symbolic type specifier @<name>; if a list of @<name>s is
130 given, then all are defined in the same way. The type constructed by using
131 any of the @<name>s is as described by the type specifier @<type-spec>.
132
133 The resulting type object is constructed once, at the time that the macro
134 expansion is evaluated; the same (@|eq|) value is used each time any
135 @<name> is used in a type specifier.
e43d3532
MW
136
137 A variable named @|c-type-@<name>|, for the first @<name> only, is defined
138 and initialized to contain the C type object so constructed. Altering or
139 binding this name is discouraged.
140
141 If @<export-flag> is true, then the variable name, and all of the @<name>s,
142 are exported from the current package.
dea4d055
MW
143\end{describe}
144
1f7d590d 145\begin{describe}{mac}{c-type-alias @<original> @<alias>^* @> @<aliases>}
dea4d055
MW
146 Defines each @<alias> as being a type operator identical in behaviour to
147 @<original>. If @<original> is later redefined then the behaviour of the
148 @<alias>es changes too.
149\end{describe}
150
1f7d590d 151\begin{describe}{mac}
cac85e0b
MW
152 {define-c-type-syntax @<name> @<lambda-list> \\ \ind
153 @[[ @<declaration>^* @! @<doc-string> @]] \\
154 @<form>^* \-
155 \nlret @<name>}
dea4d055
MW
156 Defines the symbol @<name> as a new type operator. When a list of the form
157 @|(@<name> @<argument>^*)| is used as a type specifier, the @<argument>s
158 are bound to fresh variables according to @<lambda-list> (a destructuring
159 lambda-list) and the @<form>s evaluated in order in the resulting lexical
160 environment as an implicit @|progn|. The value should be a Lisp form which
161 will evaluate to the type specified by the arguments.
162
163 The @<form>s may call @|expand-c-type-spec| in order to recursively expand
164 type specifiers among its arguments.
165\end{describe}
166
1f7d590d 167\begin{describe}{fun}{expand-c-type-spec @<type-spec> @> @<form>}
dea4d055
MW
168 Returns the Lisp form that @|(c-type @<type-spec>)| would expand into.
169\end{describe}
170
1f7d590d
MW
171\begin{describe}{gf}
172 {print-c-type @<stream> @<type> \&optional @<colon> @<atsign>}
dea4d055
MW
173 Print the C type object @<type> to @<stream> in S-expression form. The
174 @<colon> and @<atsign> arguments may be interpreted in any way which seems
175 appropriate: they are provided so that @|print-c-type| may be called via
176 @|format|'s @|\char`\~/\dots/| command; they are not set when
177 @|print-c-type| is called by Sod functions.
178
179 There should be a method defined for every C type class; there is no
180 default method.
181\end{describe}
182
31d4431b 183
1f7d590d 184\subsection{Comparing C types} \label{sec:clang.c-types.cmp}
dea4d055
MW
185
186It is necessary to compare C types for equality, for example when checking
187argument lists for methods. This is done by @|c-type-equal-p|.
188
1f7d590d
MW
189\begin{describe}{gf}
190 {c-type-equal-p @<c-type>_1 @<c-type>_2 @> @<generalized-boolean>}
191 The generic function @|c-type-equal-p| compares two C types @<c-type>_1 and
192 @<c-type>_2 for equality; it returns true if the two types are equal and
dea4d055
MW
193 false if they are not.
194
195 Two types are equal if they are structurally similar, where this property
196 is defined by methods for each individual class; see the descriptions of
197 the classes for the details.
198
199 The generic function @|c-type-equal-p| uses the @|and| method combination.
200
1f7d590d 201 \begin{describe}{meth}{c-type-equal-p @<c-type>_1 @<c-type>_2}
dea4d055
MW
202 A default primary method for @|c-type-equal-p| is defined. It simply
203 returns @|nil|. This way, methods can specialize on both arguments
204 without fear that a call will fail because no methods are applicable.
205 \end{describe}
1f7d590d 206 \begin{describe}{ar-meth}{c-type-equal-p @<c-type>_1 @<c-type>_2}
dea4d055 207 A default around-method for @|c-type-equal-p| is defined. It returns
1f7d590d
MW
208 true if @<c-type>_1 and @<c-type>_2 are @|eql|; otherwise it delegates to
209 the primary methods. Since several common kinds of C types are interned,
dea4d055
MW
210 this is a common case worth optimizing.
211 \end{describe}
212\end{describe}
213
31d4431b 214
1f7d590d 215\subsection{Outputting C types} \label{sec:clang.c-types.output}
dea4d055 216
1f7d590d 217\begin{describe}{gf}{pprint-c-type @<c-type> @<stream> @<kernel>}
dea4d055 218 The generic function @|pprint-c-type| pretty-prints to @<stream> a C-syntax
1f7d590d 219 declaration of an object or function of type @<c-type>. The result is
dea4d055
MW
220 written to @<stream>.
221
222 A C declaration has two parts: a sequence of \emph{declaration specifiers}
223 and a \emph{declarator}. The declarator syntax involves parentheses and
224 operators, in order to reflect the operators applicable to the declared
225 variable. For example, the name of a pointer variable is preceded by @`*';
226 the name of an array is followed by dimensions enclosed in @`['\dots @`]'.
227
228 The @<kernel> argument must be a function designator (though see the
229 standard around-method); it is invoked as
230 \begin{quote} \codeface
231 (funcall @<kernel> @<stream> @<priority> @<spacep>)
232 \end{quote}
233 It should write to @<stream> -- which may not be the same stream originally
234 passed into the generic function -- the `kernel' of the declarator, i.e.,
235 the part to which prefix and/or postfix operators are attached to form the
236 full declarator.
237
238 The methods on @|pprint-c-type| specialized for compound types work by
239 recursively calling @|pprint-c-type| on the subtype, passing down a closure
240 which prints the necessary additional declarator operators before calling
241 the original @<kernel> function. The additional arguments @<priority> and
242 @<spacep> support this implementation technique.
243
244 The @<priority> argument describes the surrounding operator context. It is
245 zero if no type operators are directly attached to the kernel (i.e., there
246 are no operators at all, or the kernel is enclosed in parentheses), one if
247 a prefix operator is directly attached, or two if a postfix operator is
248 directly attached. If the @<kernel> function intends to provide its own
249 additional declarator operators, it should check the @<priority> in order
250 to determine whether parentheses are necessary. See also the
58f9b400 251 \descref{maybe-in-parens}[macro]{mac}.
dea4d055
MW
252
253 The @<spacep> argument indicates whether a space needs to be printed in
254 order to separate the declarator from the declaration specifiers. A kernel
255 which contains an identifier should insert a space before the identifier
256 when @<spacep> is non-nil. An `empty' kernel, as found in an abstract
257 declarator (one that specifies no name), looks more pleasing without a
58f9b400 258 trailing space. See also the \descref{c-type-space}[function]{fun}.
dea4d055
MW
259
260 Every concrete subclass of @|c-type| is expected to provide a primary
261 method on this function. There is no default primary method.
262
1f7d590d 263 \begin{describe}{ar-meth}{pprint-c-type @<c-type> @<stream> @<kernel>}
dea4d055
MW
264 A default around method is defined on @|pprint-c-type| which `canonifies'
265 non-function @<kernel> arguments. In particular:
266 \begin{itemize}
267 \item if @<kernel> is nil, then @|pprint-c-type| is called recursively
268 with a @<kernel> function that does nothing; and
269 \item if @<kernel> is any other kind of object, then @|pprint-c-type| is
270 called recursively with a @<kernel> function that prints the object as
271 if by @|princ|, preceded if necessary by space using @|c-type-space|.
272 \end{itemize}
273 \end{describe}
274\end{describe}
275
276\begin{describe}{fun}{c-type-space @<stream>}
277 Writes a space and other pretty-printing instructions to @<stream> in order
278 visually to separate a declarator from the preceding declaration
279 specifiers. The precise details are subject to change.
280\end{describe}
281
1f7d590d 282\begin{describe}{mac}
cac85e0b
MW
283 {maybe-in-parens (@<stream-var> @<guard-form>)
284 @<declaration>^*
285 @<form>^*}
dea4d055
MW
286 The @<guard-form> is evaluated, and then the @<form>s are evaluated in
287 sequence within a pretty-printer logical block writing to the stream named
288 by the symbol @<stream-var>. If the @<guard-form> evaluates to nil, then
289 the logical block has empty prefix and suffix strings; if it evaluates to a
290 non-nil value, then the logical block has prefix and suffix @`(' and @`)'
291 respectively.
292
293 Note that this may cause @<stream> to be bound to a different stream object
294 within the @<form>s.
295\end{describe}
296
31d4431b 297
dea4d055 298\subsection{Type qualifiers and qualifiable types}
1f7d590d 299\label{sec:clang.ctypes.qual}
dea4d055
MW
300
301\begin{describe}{cls}{qualifiable-c-type (c-type) \&key :qualifiers}
302 The class @|qualifiable-c-type| describes C types which can bear
303 `qualifiers' (\Cplusplus\ calls them `cv-qualifiers'): @|const|,
304 @|restrict| and @|volatile|.
305
306 The @<qualifiers> are a list of keyword symbols @|:const|, @|:restrict| and
307 @|:volatile|. There is no built-in limitation to these particular
308 qualifiers; others keywords may be used, though this isn't recommended.
309
310 Two qualifiable types are equal only if they have \emph{matching
31d4431b
MW
311 qualifiers}: i.e., every qualifier attached to one is also attached to the
312 other: order is not significant, and neither is multiplicity.
dea4d055
MW
313
314 The class @|qualifiable-c-type| is abstract.
315\end{describe}
316
1f7d590d
MW
317\begin{describe}{gf}{c-type-qualifiers @<c-type> @> @<list>}
318 Returns the qualifiers of the @|qualifiable-c-type| instance @<c-type> as
319 an immutable list.
dea4d055
MW
320\end{describe}
321
1f7d590d
MW
322\begin{describe}{fun}{qualify-type @<c-type> @<qualifiers> @> @<c-type>}
323 The argument @<c-type> must be an instance of @|qualifiable-c-type|,
dea4d055
MW
324 currently bearing no qualifiers, and @<qualifiers> a list of qualifier
325 keywords. The result is a C type object like @<c-type> except that it
326 bears the given @<qualifiers>.
327
1f7d590d 328 The @<c-type> is not modified. If @<c-type> is interned, then the returned
dea4d055
MW
329 type will be interned.
330\end{describe}
331
0b80399d 332\begin{describe}{fun}{format-qualifiers @<qualifiers> @> @<string>}
dea4d055
MW
333 Returns a string containing the qualifiers listed in @<qualifiers> in C
334 syntax, with a space after each. In particular, if @<qualifiers> is
335 non-null then the final character of the returned string will be a space.
336\end{describe}
337
31d4431b 338
1f7d590d 339\subsection{Leaf types} \label{sec:clang.c-types.leaf}
dea4d055
MW
340
341A \emph{leaf type} is a type which is not defined in terms of another type.
342In Sod, the leaf types are
343\begin{itemize}
344\item \emph{simple types}, including builtin types like @|int| and @|char|,
345 as well as type names introduced by @|typename|, because Sod isn't
346 interested in what the type name means, merely that it names a type; and
347\item \emph{tagged types}, i.e., enum, struct and union types which are named
348 by a keyword identifying the kind of type, and a \emph{tag}.
349\end{itemize}
350
351\begin{describe}{cls}{simple-c-type (qualifiable-c-type)
352 \&key :qualifiers :name}
353 The class of `simple types'; an instance denotes the type @<qualifiers>
354 @<name>.
355
356 A simple type object maintains a \emph{name}, which is a string whose
357 contents are the C name for the type. The initarg @|:name| may be used to
358 provide this name when calling @|make-instance|.
359
360 Two simple type objects are equal if and only if they have @|string=| names
361 and matching qualifiers.
362
363 A number of symbolic type specifiers for builtin types are predefined as
64d1ecf7 364 shown in \xref{tab:codegen.c-types.simple}. These are all defined as if by
dea4d055
MW
365 @|define-simple-c-type|, so can be used to construct qualified types.
366\end{describe}
367
368\begin{table}
fcb6c0fb
MW
369 \begin{tabular}[C]{ll} \hlx*{hv}
370 \thd{C type} & \thd{Specifiers} \\ \hlx{vhv}
371 @|void| & @|void| \\ \hlx{v}
a4434457
MW
372 @|_Bool| & @|bool| \\ \hlx{v}
373 @|char| & @|char| \\ \hlx{}
a4434457 374 @|wchar_t| & @|wchar-t| \\ \hlx{v}
d21ac4d9
MW
375 @|signed char| & @|signed-char|, @|schar| \\ \hlx{}
376 @|unsigned char| & @|unsigned-char|, @|uchar| \\ \hlx{v}
dea4d055 377 @|short| & @|short|, @|signed-short|, @|short-int|,
fcb6c0fb 378 @|signed-short-int| @|sshort| \\ \hlx{}
dea4d055 379 @|unsigned short| & @|unsigned-short|, @|unsigned-short-int|,
fcb6c0fb 380 @|ushort| \\ \hlx{v}
dea4d055 381 @|int| & @|int|, @|signed|, @|signed-int|,
fcb6c0fb
MW
382 @|sint| \\ \hlx{}
383 @|unsigned int| & @|unsigned|, @|unsigned-int|, @|uint| \\ \hlx{v}
dea4d055 384 @|long| & @|long|, @|signed-long|, @|long-int|,
fcb6c0fb 385 @|signed-long-int|, @|slong| \\ \hlx{}
dea4d055 386 @|unsigned long| & @|unsigned-long|, @|unsigned-long-int|,
fcb6c0fb 387 @|ulong| \\ \hlx{v}
dea4d055 388 @|long long| & @|long-long|, @|signed-long-long|,
d21ac4d9 389 @|long-long-int|, \\ \hlx{}
dea4d055
MW
390 & \qquad @|signed-long-long-int|,
391 @|llong|, @|sllong| \\ \hlx{v}
392 @|unsigned long long|
393 & @|unsigned-long-long|, @|unsigned-long-long-int|,
fcb6c0fb 394 @|ullong| \\ \hlx{v}
d21ac4d9
MW
395 @|size_t| & @|size-t| \\ \hlx{}
396 @|ptrdiff_t| & @|ptrdiff-t| \\ \hlx{v}
fcb6c0fb 397 @|float| & @|float| \\ \hlx{}
a4434457
MW
398 @|double| & @|double| \\ \hlx{}
399 @|long double| & @|long-double| \\ \hlx{v}
400 @|float _Imaginary| & @|float-imaginary| \\ \hlx{}
a4434457 401 @|double _Imaginary|& @|double-imaginary| \\ \hlx{}
a4434457 402 @|long double _Imaginary|
d21ac4d9
MW
403 & @|long-double-imaginary| \\ \hlx{v}
404 @|float _Complex| & @|float-complex| \\ \hlx{}
405 @|double _Complex| & @|double-complex| \\ \hlx{}
a4434457 406 @|long double _Complex|
d21ac4d9
MW
407 & @|long-double-complex| \\ \hlx{v}
408 @|va_list| & @|va-list| \\ \hlx*{vh}
dea4d055
MW
409 \end{tabular}
410 \caption{Builtin symbolic type specifiers for simple C types}
64d1ecf7 411 \label{tab:codegen.c-types.simple}
dea4d055
MW
412\end{table}
413
1f7d590d
MW
414\begin{describe}{fun}
415 {make-simple-type @<name> \&optional @<qualifiers> @> @<c-type>}
dea4d055
MW
416 Return the (unique interned) simple C type object for the C type whose name
417 is @<name> (a string) and which has the given @<qualifiers> (a list of
418 keywords).
419\end{describe}
420
1f7d590d
MW
421\begin{describe}{gf}{c-type-name @<c-type> @> @<string>}
422 Returns the name of a @|simple-c-type| instance @<c-type> as an immutable
dea4d055
MW
423 string.
424\end{describe}
425
1f7d590d 426\begin{describe}{mac}
e43d3532
MW
427 {define-simple-c-type \=@{ @<name> @! (@<name>^+) @} @<string> \+ \\
428 @[[ @|:export| @<export-flag> @]] \-
429 \nlret @<name>}
dea4d055
MW
430 Define type specifiers for a new simple C type. Each symbol @<name> is
431 defined as a symbolic type specifier for the (unique interned) simple C
432 type whose name is the value of @<string>. Further, each @<name> is
433 defined to be a type operator: the type specifier @|(@<name>
434 @<qualifier>^*)| evaluates to the (unique interned) simple C type whose
435 name is @<string> and which has the @<qualifiers> (which are evaluated).
e43d3532
MW
436
437 Furthermore, a variable @|c-type-@<name>| is defined, for the first @<name>
438 only, and initialized with the newly constructed C type object.
439
440 If @<export-flag> is true, then the @|c-type-@<name>| variable name, and
441 all of the @<name>s, are exported from the current package.
dea4d055
MW
442\end{describe}
443
444\begin{describe}{cls}{tagged-c-type (qualifiable-c-type)
445 \&key :qualifiers :tag}
446 Provides common behaviour for C tagged types. A @<tag> is a string
447 containing a C identifier.
448
449 Two tagged types are equal if and only if they have the same class, their
450 @<tag>s are @|string=|, and they have matching qualifiers. (User-defined
451 subclasses may have additional methods on @|c-type-equal-p| which impose
452 further restrictions.)
453\end{describe}
454\begin{boxy}[Bug]
455 Sod maintains distinct namespaces for the three kinds of tagged types. In
456 C, there is only one namespace for tags which is shared between enums,
457 structs and unions.
458\end{boxy}
459
1f7d590d
MW
460\begin{describe}{gf}{c-tagged-type-kind @<c-type> @> @<keyword>}
461 Returns a keyword classifying the tagged @<c-type>: one of @|:enum|,
462 @|:struct| or @|:union|. User-defined subclasses of @|tagged-c-type|
463 should return their own classification symbols. It is intended that
464 @|(string-downcase (c-tagged-type-kind @<c-type>))| be valid C
465 syntax.\footnote{%
dea4d055
MW
466 Alas, C doesn't provide a syntactic category for these keywords;
467 \Cplusplus\ calls them a @<class-key>.} %
1f7d590d
MW
468 There is a method defined for each of the built-in tagged type classes
469 @|c-struct-type|, @|c-union-type| and @|c-enum-type|.
470\end{describe}
471
472\begin{describe}{gf}{kind-c-tagged-type @<keyword> @> @<symbol>}
473 This is not quite the inverse of @|c-tagged-type-kind|. Given a keyword
474 naming a kind of tagged type, return the name of the corresponding C
475 type class as a symbol.
dea4d055
MW
476\end{describe}
477
478\begin{describe}{cls}{c-enum-type (tagged-c-type) \&key :qualifiers :tag}
479 Represents a C enumerated type. An instance denotes the C type @|enum|
480 @<tag>. See the direct superclass @|tagged-c-type| for details.
481
482 The type specifier @|(enum @<tag> @<qualifier>^*)| returns the (unique
483 interned) enumerated type with the given @<tag> and @<qualifier>s (all
484 evaluated).
485\end{describe}
1f7d590d
MW
486\begin{describe}{fun}
487 {make-enum-type @<tag> \&optional @<qualifiers> @> @<c-enum-type>}
dea4d055
MW
488 Return the (unique interned) C type object for the enumerated C type whose
489 tag is @<tag> (a string) and which has the given @<qualifiers> (a list of
490 keywords).
491\end{describe}
492
493\begin{describe}{cls}{c-struct-type (tagged-c-type) \&key :qualifiers :tag}
494 Represents a C structured type. An instance denotes the C type @|struct|
495 @<tag>. See the direct superclass @|tagged-c-type| for details.
496
497 The type specifier @|(struct @<tag> @<qualifier>^*)| returns the (unique
498 interned) structured type with the given @<tag> and @<qualifier>s (all
499 evaluated).
500\end{describe}
1f7d590d
MW
501\begin{describe}{fun}
502 {make-struct-type @<tag> \&optional @<qualifiers> @> @<c-struct-type>}
dea4d055
MW
503 Return the (unique interned) C type object for the structured C type whose
504 tag is @<tag> (a string) and which has the given @<qualifiers> (a list of
505 keywords).
506\end{describe}
507
508\begin{describe}{cls}{c-union-type (tagged-c-type) \&key :qualifiers :tag}
509 Represents a C union type. An instance denotes the C type @|union|
510 @<tag>. See the direct superclass @|tagged-c-type|
511 for details.
512
513 The type specifier @|(union @<tag> @<qualifier>^*)| returns the (unique
514 interned) union type with the given @<tag> and @<qualifier>s (all
515 evaluated).
516\end{describe}
1f7d590d
MW
517\begin{describe}{fun}
518 {make-union-type @<tag> \&optional @<qualifiers> @> @<c-union-type>}
dea4d055
MW
519 Return the (unique interned) C type object for the union C type whose tag
520 is @<tag> (a string) and which has the given @<qualifiers> (a list of
521 keywords).
522\end{describe}
523
31d4431b 524
1f7d590d
MW
525\subsection{Compound C types} \label{sec:code.c-types.compound}
526
527Some C types are \emph{compound types}: they're defined in terms of existing
528types. The classes which represent compound types implement a common
529protocol.
dea4d055 530
1f7d590d
MW
531\begin{describe}{gf}{c-type-subtype @<c-type> @> @<subtype>}
532 Returns the underlying type of a compound type @<c-type>. Precisely what
533 this means depends on the class of @<c-type>.
dea4d055
MW
534\end{describe}
535
31d4431b 536
1f7d590d
MW
537\subsection{Pointer types} \label{sec:clang.c-types.pointer}
538
cf7f1f46
MW
539Pointers are compound types. The subtype of a pointer type is the type it
540points to.
1f7d590d
MW
541
542\begin{describe}{cls}
543 {c-pointer-type (qualifiable-c-type) \&key :qualifiers :subtype}
dea4d055
MW
544 Represents a C pointer type. An instance denotes the C type @<subtype>
545 @|*|@<qualifiers>.
546
547 The @<subtype> may be any C type. Two pointer types are equal if and only
548 if their subtypes are equal and they have matching qualifiers.
549
550 The type specifier @|(* @<type-spec> @<qualifier>^*)| returns a type
551 qualified pointer-to-@<subtype>, where @<subtype> is the type specified by
552 @<type-spec> and the @<qualifier>s are qualifier keywords (which are
553 evaluated). The synonyms @|ptr| and @|pointer| may be used in place of the
554 star @`*'.
555
fcb6c0fb 556 The symbol @|string| is a type specifier for the type pointer to
dea4d055
MW
557 characters; the symbol @|const-string| is a type specifier for the type
558 pointer to constant characters.
559\end{describe}
1f7d590d
MW
560
561\begin{describe}{fun}
562 {make-pointer-type @<c-type> \&optional @<qualifiers>
563 @> @<c-pointer-type>}
fcb6c0fb 564 Return an object describing the type qualified pointer to @<subtype>.
dea4d055
MW
565 If @<subtype> is interned, then the returned pointer type object is
566 interned also.
567\end{describe}
568
31d4431b 569
1f7d590d
MW
570\subsection{Array types} \label{sec:clang.c-types.array}
571
fcb6c0fb
MW
572Arrays implement the compound-type protocol. The subtype of an array type is
573the array element type.
1f7d590d 574
dea4d055
MW
575\begin{describe}{cls}{c-array-type (c-type) \&key :subtype :dimensions}
576 Represents a multidimensional C array type. The @<dimensions> are a list
577 of dimension specifiers $d_0$, $d_1$, \ldots, $d_{n-1}$; an instance then
578 denotes the C type @<subtype> @|[$d_0$][$d_1$]$\ldots$[$d_{n-1}$]|. An
579 individual dimension specifier is either a string containing a C integral
580 constant expression, or nil which is equivalent to an empty string. Only
581 the first (outermost) dimension $d_0$ should be empty.
582
583 C doesn't actually have multidimensional arrays as a primitive notion;
584 rather, it permits an array (with known extent) to be the element type of
585 an array, which achieves an equivalent effect. C arrays are stored in
586 row-major order: i.e., if we write down the indices of the elements of an
587 array in order of ascending address, the rightmost index varies fastest;
588 hence, the type constructed is more accurately an array of $d_0$ arrays of
589 $d_1$ of \ldots\ arrays of $d_{n-1}$ elements of type @<subtype>. We shall
590 continue to abuse terminology and refer to multidimensional arrays.
591
592 The type specifier @|([] @<type-spec> @<dimension>^*)| constructs a
593 multidimensional array with the given @<dimension>s whose elements have the
594 type specified by @<type-spec>. If no dimensions are given then a
595 single-dimensional array with unspecified extent. The synonyms @|array|
596 and @|vector| may be used in place of the brackets @`[]'.
597\end{describe}
1f7d590d
MW
598
599\begin{describe}{fun}
600 {make-array-type @<subtype> @<dimensions> @> @<c-array-type>}
dea4d055
MW
601 Return an object describing the type of arrays with given @<dimensions> and
602 with element type @<subtype> (an instance of @|c-type|). The @<dimensions>
603 argument is a list whose elements are strings or nil; see the description
604 of the class @|c-array-type| above for details.
605\end{describe}
1f7d590d
MW
606
607\begin{describe}{gf}{c-array-dimensions @<c-type> @> @<list>}
608 Returns the dimensions of @<c-type>, an array type, as an immutable list.
609\end{describe}
610
31d4431b 611
1f7d590d
MW
612\subsection{Function types} \label{sec:clang.c-types.fun}
613
fcb6c0fb
MW
614Function types implement the compound-type protocol. The subtype of a
615function type is the type of the function's return value.
616
1f7d590d 617\begin{describe}{cls}{argument}
fcb6c0fb 618 Represents an ordinary function argument.
1f7d590d
MW
619\end{describe}
620
621\begin{describe}{fun}{argumentp @<value> @> @<generalized-boolean>}
fcb6c0fb
MW
622 Decide whether @<value> is an @<argument> object: if so, return non-nil; if
623 not return nil.
1f7d590d
MW
624\end{describe}
625
626\begin{describe}{fun}{make-argument @<name> @<c-type> @> @<argument>}
fcb6c0fb
MW
627 Construct and a return a new @<argument> object. The argument has type
628 @<c-type>, which must be a @|c-type| object, and is named @<name>.
629
630 The @<name> may be nil to indicate that the argument has no name: in this
631 case the argument will be formatted as an abstract declarator, which is not
632 suitable for function definitions. If @<name> is not nil, then the
633 @<name>'s print representation, with @|*print-escape*| nil, is used as the
634 argument name.
1f7d590d
MW
635\end{describe}
636
52e2a70f 637\begin{describe*}
31d4431b
MW
638 {\dhead{fun}{argument-name @<argument> @> @<name>}
639 \dhead{fun}{argument-type @<argument> @> @<c-type>}}
52e2a70f
MW
640 Accessor functions for @|argument| objects. They return the name (for
641 @|argument-name|) or type (for @|argument-type|) from the object, as passed
642 to @|make-argument|.
643\end{describe*}
dea4d055 644
fcb6c0fb 645\begin{describe}{gf}
1f7d590d 646 {commentify-argument-name @<name> @> @<commentified-name>}
fcb6c0fb
MW
647 Convert the argument name @<name> so that it's suitable to declare the
648 function in a header file.
dea4d055 649
fcb6c0fb
MW
650 Robust header files shouldn't include literal argument names in
651 declarations of functions or function types, since this restricts the
652 including file from defining such names as macros. This generic function
653 is used to convert names into a safe form.
654
655 \begin{describe}{meth}{commentify-argument-name (@<name> null) @> nil}
656 Returns nil: if the argument name is already omitted, it's safe for use
657 in a header file.
658 \end{describe}
659 \begin{describe}{meth}{commentify-argument-name (@<name> t) @> @<string>}
660 Returns the print form of @<name> wrapped in a C comment, as
661 @`/*@<name>*/'.
662 \end{describe}
1f7d590d
MW
663\end{describe}
664
665\begin{describe}{fun}
fcb6c0fb
MW
666 {commentify-argument-names @<arguments> @> @<commentified-arguments>}
667 Convert the @<arguments> list so that it's suitable for use in a header
668 file.
669
670 The @<arguments> list should be a list whose items are @|argument| objects
671 or the keyword @|:ellipsis|. The return value is a list constructed as
672 follows. For each @|argument| object in the input list, there is a
673 corresponding @|argument| object in the returned list, with the same type,
674 and whose name is the result of @|commentify-argument-name| applied to the
675 input argument name; an @|:ellipsis| in the input list is passed through
676 unchanged.
1f7d590d
MW
677\end{describe}
678
fcb6c0fb
MW
679\begin{describe}{cls}{c-function-type (c-type) \&key :subtype :arguments}
680 Represents C function types. An instance denotes the type of a C
681 function which accepts the @<arguments> and returns @<subtype>.
682
683 The @<arguments> are a possibly empty list. All but the last element of
684 the list must be @|argument| objects; the final element may instead be the
685 keyword @|:ellipsis|, which denotes a variable argument list.
686
687 An @<arguments> list consisting of a single argument with type @|void| is
688 converted into an empty list. On output as C code, an empty argument list
689 is written as @|void|. It is not possible to represent a pre-ANSI C
690 function without prototypes.
691
692 Two function types are considered to be the same if their return types are
693 the same, and their argument lists consist of arguments with the same type,
694 in the same order, and either both or neither argument list ends with
695 @|:ellipsis|; argument names are not compared.
696
ed76585e
MW
697 The type specifier
698 \begin{prog}
699 (fun @<return-type>
700 @{ (@<arg-name> @<arg-type>) @}^*
701 @[:ellipsis @! . @<form>@])
702 \end{prog}
703 constructs a function type. The function has the subtype @<return-type>.
704 The remaining items in the type-specifier list are used to construct the
705 argument list. The argument items are a possibly improper list, beginning
706 with zero or more \emph{explicit arguments}: two-item
707 @<arg-name>/@<arg-type> lists. For each such list, an @|argument| object
708 is constructed with the given name (evaluated) and type. Following the
709 explicit arguments, there may be
fcb6c0fb
MW
710 \begin{itemize}
711 \item nothing, in which case the function's argument list consists only of
712 the explicit arguments;
713 \item the keyword @|:ellipsis|, as the final item in the type-specifier
714 list, indicating a variable argument list may follow the explicit
715 arguments; or
716 \item a possibly-improper list tail, beginning with an atom either as a
717 list item or as the final list cdr, indicating that the entire list tail
718 is Lisp expression which is to be evaluated to compute the remaining
719 arguments.
720 \end{itemize}
721 A tail expression may return a list of @|argument| objects, optionally
722 followed by an @|:ellipsis|.
723
724 For example,
725 \begin{prog}
726 (c-type (fun \=(lisp (c-type-subtype other-func)) \+ \\
727 ("first" int) . (c-function-arguments other-func))
728 \end{prog}
729 evaluates to a function type like @|other-func|, only with an additional
730 argument of type @|int| added to the front of its argument list. This
731 could also have been written
732 \begin{prog}
733 (let (\=(args (c-function-arguments other-func)) \+ \\
734 (ret (c-type-subtype other-func))) \- \\ \ind
735 (c-type (fun \=(lisp ret) ("first" int) . args)
736 \end{prog}
1f7d590d
MW
737\end{describe}
738
739\begin{describe}{fun}
fcb6c0fb
MW
740 {make-function-type @<subtype> @<arguments> @> @<c-function-type>}
741 Construct and return a new function type, returning @<subtype> and
742 accepting the @<arguments>.
743\end{describe}
744
745\begin{describe}{gf}
746 {c-function-arguments @<c-function-type> @> @<arguments>}
747 Return the arguments list of the @<c-function-type>.
1f7d590d
MW
748\end{describe}
749
750\begin{describe}{fun}
fcb6c0fb
MW
751 {commentify-function-type @<c-function-type> @> @<commentified-c-type>}
752 Return a commentified version of the @<c-function-type>.
753
754 The returned type has the same subtype as the given type, and the argument
755 list of the returned type is the result of applying
756 @|commentify-argument-names| to the argument list of the given type.
dea4d055
MW
757\end{describe}
758
678b6c0f
MW
759\begin{describe}{fun}
760 {pprint-c-function-type @<return-type> @<stream>
761 @<print-args> @<print-kernel>}
762 Provides the top-level structure for printing C function types.
763
764 Output is written to @<stream> to describe a function type returning
765 @<return-type>, whose declarator kernel (containing the name, and any
766 further type operands) will be printed by @<print-kernel>, and whose
767 arguments, if any, will be printed by @<print-args>.
768
769 The @<print-kernel> function is a standard kernel-printing function
770 following the \descref{pprint-c-type}[protocol]{gf}.
771
772 The @<print-args> function is given a single argument, which is the
773 @<stream> to print on. It should not print the surrounding parentheses.
774
775 The output written to @<stream> looks approximately like
776 \begin{prog}
777 @<return-type> @<kernel>(@<args>)
778 \end{prog}
779\end{describe}
780
781\begin{describe}{fun}{pprint-argument-list @<args> @<stream> @> @<flag>}
782 Print an argument list to @<stream>.
783
784 The @<args> is a list of \descref{argument}[objects]{cls}, optionally
785 containing an @|:ellipsis| marker. The function returns true if any
786 arguments were actually printed.
787\end{describe}
788
31d4431b 789
1f7d590d
MW
790\subsection{Parsing C types} \label{sec:clang.c-types.parsing}
791
756f4928
MW
792\begin{describe}{fun}
793 {parse-c-type @<scanner>
794 @> @<result> @<success-flag> @<consumed-flag>}
795\end{describe}
796
797\begin{describe}{fun}
798 {parse-declarator @<scanner> @<base-type> \&key :kernel :abstractp
799 \nlret @<result> @<success-flag> @<consumed-flag>}
800\end{describe}
801
31d4431b 802
756f4928
MW
803\subsection{Class types} \label{sec:clang.c-types.class}
804
805\begin{describe}{cls}
806 {c-class-type (simple-c-type) \&key :class :tag :qualifiers :name}
807\end{describe}
808
809\begin{describe*}
810 {\dhead{gf}{c-type-class @<class-type> @> @<class>}
811 \dhead{gf}{setf (c-type-class @<class-type>) @<class>}}
812\end{describe*}
813
814\begin{describe}{fun}{find-class-type @<name> @> @<class-type-or-nil>}
815\end{describe}
816
817\begin{describe}{fun}
818 {make-class-type @<name> \&optional @<qualifiers> @> @<class-type>}
819\end{describe}
820
821\begin{describe}{fun}
822 {make-class-type @<name> \&optional @<qualifiers> @> @<class-type>}
823\end{describe}
824
825\begin{describe}{fun}{find-sod-class @<name> @> @<class>}
826\end{describe}
827
828\begin{describe}{fun}{record-sod-class @<class>}
829\end{describe}
830
1f7d590d
MW
831%%%--------------------------------------------------------------------------
832\section{Generating C code} \label{sec:clang.codegen}
833
fcb6c0fb
MW
834This section deals with Sod's facilities for constructing and manipulating C
835expressions, declarations, instructions and definitions.
836
31d4431b 837
fcb6c0fb
MW
838\subsection{Temporary names} \label{sec:clang.codegen.temporaries}
839
840Many C-level objects, especially ones with external linkage or inclusion in a
841header file, are assigned names which are simple strings, perhaps fixed ones,
842perhaps constructed. Other objects don't need meaningful names, and
843suitably unique constructed names would be tedious and most likely rather
844opaque. Therefore Sod has an ability to construct \emph{temporary names}.
845
846These aren't temporary in the sense that they name C objects which have
847limited lifetimes at runtime. Rather, the idea is that the names be
848significant only to small pieces of Lisp code, which will soon forget about
849them.
850
851\subsubsection{The temporary name protocol}
852Temporary names are represented by objects which implement a simple protocol.
853
854\begin{describe}{gf}{format-temporary-name @<var> @<stream>}
855\end{describe}
856
857\begin{describe*}
858 {\dhead{gf}{var-in-use-p @<var> @> @<generalized-boolean>}
859 \dhead[setf var-in-use-p]
860 {gf}{setf (var-in-use-p @<var>) @<generalized-boolean>}}
861\end{describe*}
862
863\subsubsection{Temporary name objects}
864
865\begin{describe}{cls}{temporary-name () \&key :tag}
866 A temporary name object. This is the root of a small collection of
867 subclasses, but is also usable on its own.
868\end{describe}
869
870\begin{describe}{meth}
871 {commentify-argument-name (@<name> temporary-name) @> nil}
872\end{describe}
873
874\begin{table}
875 \begin{tabular}[C]{*2{>{\codeface}l}} \hlx*{hv}
876 \thd{\textbf{Class}} & \thd{\textbf{Name format}} \\ \hlx{vhv}
877 temporary-name & @<tag> \\
878 temporary-argument & sod__a@<tag> \\
879 temporary-function & sod__f@<tag> \\
880 temporary-variable & sod__v@<tag> \\ \hlx*{vh}
881 \end{tabular}
882 \caption{Temporary name formats}
883 \label{tab:codegen.codegen.temps-format}
884\end{table}
885
886\begin{describe}{cls}{temporary-argument (temporary-name) \&key :tag}
887\end{describe}
888
889\begin{describe}{cls}{temporary-function (temporary-name) \&key :tag}
890\end{describe}
891
892\begin{describe}{fun}{temporary-function @> @<name>}
893\end{describe}
894
895\begin{describe}{cls}
896 {temporary-variable (temporary-name) \&key :tag :in-use-p}
897\end{describe}
898
899\subsubsection{Well-known `temporary' names}
900
901\begin{table}
902 \begin{tabular}[C]{*2{>{\codeface}l}} \hlx*{hv}
903 \thd{\textbf{Variable}} & \thd{\textbf{Name format}} \\ \hlx{vhv}
904 {}*sod-ap* & sod__ap \\
944caf84
MW
905 {}*sod-master-ap* & sod__master_ap \\
906 {}*null-pointer* & NULL \\ \hlx*{vh}
fcb6c0fb
MW
907 \end{tabular}
908 \caption{Well-known temporary names}
909 \label{tab:codegen.codegen.well-known-temps}
910\end{table}
911
31d4431b 912
fcb6c0fb
MW
913\subsection{Instructions} \label{sec:clang.codegen.insts}
914
915\begin{describe}{cls}{inst () \&key}
916\end{describe}
917
918\begin{describe}{gf}{inst-metric @<inst>}
919\end{describe}
920
921\begin{describe}{mac}
cac85e0b
MW
922 {definst @<code> (@<streamvar> \&key @<export>) (@<arg>^*) \\ \ind
923 @[[ @<declaration>^* @! @<doc-string> @]] \\
924 @<form>^* \-
925 \nlret @<code>}
fcb6c0fb
MW
926\end{describe}
927
928\begin{describe}{mac}
cac85e0b
MW
929 {format-compound-statement
930 (@<stream> @<child> \&optional @<morep>) \\ \ind
931 @<declaration>^* \\
932 @<form>^*}
fcb6c0fb
MW
933\end{describe}
934
7de8c666
MW
935\begin{describe}{fun}
936 {format-banner-comment @<stream> @<control> \&rest @<args>}
937\end{describe}
938
fcb6c0fb
MW
939\begin{table}
940 \begin{tabular}[C]{ll>{\codeface}l} \hlx*{hv}
941 \thd{Class name} &
942 \thd{Arguments} &
943 \thd{Output format} \\ \hlx{vhv}
167524b5
MW
944 @|var| & @<name> @<type> @|\&optional| @<init>
945 & @<type> @<name> @[= @<init>@];
fcb6c0fb
MW
946 \\ \hlx{v}
947 @|set| & @<var> @<expr> & @<var> = @<expr>; \\ \hlx{v}
948 @|update| & @<var> @<op> @<expr> & @<var> @<op>= @<expr>;
949 \\ \hlx{v}
2d8d81c5
MW
950 @|cond| & @<cond> @<conseq> @<alt> & @<cond> ? @<conseq> : @<alt>
951 \\ \hlx{v}
fcb6c0fb
MW
952 @|return| & @<expr> & return @[@<expr>@];
953 \\ \hlx{v}
954 @|break| & --- & break; \\ \hlx{v}
955 @|continue| & --- & continue; \\ \hlx{v}
956 @|expr| & @<expr> & @<expr>; \\ \hlx{v}
167524b5
MW
957 @|call| & @<func> @|\&rest| @<args>
958 & @<func>(@<arg>_1,
fcb6c0fb 959 $\ldots$,
7de8c666
MW
960 @<arg>_n) \\ \hlx{v}
961 @|banner| & @<control> @|\&rest| @<args>
962 & /* @<banner> */ \\ \hlx{vhv}
fcb6c0fb
MW
963 @|block| & @<decls> @<body> & \{ @[@<decls>@] @<body> \}
964 \\ \hlx{v}
167524b5
MW
965 @|if| & @<cond> @<conseq> @|\&optional| @<alt>
966 & if (@<cond>) @<conseq>
fcb6c0fb 967 @[else @<alt>@] \\ \hlx{v}
2d8d81c5
MW
968 @|for| & @<init> @<cond> @<update> @<body> &
969 for (@<init>; @<cond>; @<update>) @<body> \\ \hlx{v}
fcb6c0fb
MW
970 @|while| & @<cond> @<body> & while (@<cond>) @<body>
971 \\ \hlx{v}
972 @|do-while| & @<body> @<cond> & do @<body> while (@<cond>);
973 \\ \hlx{v}
7de8c666
MW
974 @|function| &
975 \vtop{\hbox{\strut @<name> @<type> @<body>}
976 \hbox{\strut \quad @|\&optional @<banner>|}
977 \hbox{\strut \quad @|\&rest| @<banner-args>}} &
978 \vtop{\hbox{\strut @[/* @<banner> */@]}
979 \hbox{\strut @<type>_0 @<name>(@<type>_1 @<arg>_1, $\ldots$,
167524b5
MW
980 @<type>_n @<arg>_n @[, \dots@])}
981 \hbox{\strut \quad @<body>}} \\ \hlx*{vh}
fcb6c0fb
MW
982 \end{tabular}
983 \caption{Instruction classes}
984 \label{tab:codegen.codegen.insts}
985\end{table}
986
31d4431b 987
fcb6c0fb
MW
988\subsection{Code generation} \label{sec:clang.codegen.codegen}
989
990\begin{describe}{gf}{codegen-functions @<codegen> @> @<list>}
991\end{describe}
992
993\begin{describe}{gf}
994 {ensure-var @<codegen> @<name> @<type> \&optional @<init>}
995\end{describe}
996
997\begin{describe}{gf}{emit-inst @<codegen> @<inst>}
998\end{describe}
999
1000\begin{describe}{gf}{emit-insts @<codegen> @<insts>}
1001\end{describe}
1002
1003\begin{describe}{gf}{emit-decl @<codegen> @<decl>}
1004\end{describe}
1005
7c3f8ae6 1006\begin{describe}{gf}{emit-decls @<codegen> @<decls>}
fcb6c0fb
MW
1007\end{describe}
1008
7de8c666
MW
1009\begin{describe}{fun}{emit-banner @<codegen> @<control> \&rest @<args>}
1010\end{describe}
1011
fcb6c0fb
MW
1012\begin{describe}{gf}{codegen-push @<codegen>}
1013\end{describe}
1014
1015\begin{describe}{gf}{codegen-pop @<codegen> @> @<decls> @<insts>}
1016\end{describe}
1017
1018\begin{describe}{gf}{codegen-pop-block @<codegen> @> @<block-inst>}
1019\end{describe}
1020
1021\begin{describe}{gf}
1022 {codegen-pop-function @<codegen> @<name> @<type> @> @<name>}
1023\end{describe}
1024
1025\begin{describe}{gf}{codegen-add-function @<codegen> @<function>}
1026\end{describe}
1027
1028\begin{describe}{fun}
1029 {codegen-build-function @<codegen> @<name> @<type> @<vars> @<insts>
1030 @> @<name>}
1031\end{describe}
1032
1033\begin{describe}{gf}{temporary-var @<codegen> @<type> @> @<name>}
1034\end{describe}
1035
1036\begin{describe}{mac}
cac85e0b
MW
1037 {with-temporary-var (@<codegen> @<var> @<type>) \\ \ind
1038 @<declaration>^* \\
1039 @<form>^* \-
1040 \nlret @<value>^*}
fcb6c0fb
MW
1041\end{describe}
1042
1043\begin{describe}{fun}{deliver-expr @<codegen> @<target> @<expr>}
1044\end{describe}
1045
357885be
MW
1046\begin{describe}{fun}
1047 {deliver-call @<codegen> @<target> @<func> \&rest @<args>}
1048\end{describe}
1049
fcb6c0fb
MW
1050\begin{describe}{fun}{convert-stmts @<codegen> @<target> @<type> @<func>}
1051\end{describe}
1052
1053\begin{describe}{cls}{codegen () \&key :vars :insts (:temp-index 0)}
1054\end{describe}
1055
2c7465ac
MW
1056%%%--------------------------------------------------------------------------
1057\section{Literal C code fragments} \label{sec:clang.fragment}
1058
1059\begin{describe}{cls}{c-fragment () \&key :location :text}
1060\end{describe}
1061
1062\begin{describe}{gf}{c-fragment-text @<fragment> @> @<string>}
1063\end{describe}
1064
1065\begin{describe}{fun}
1066 {scan-c-fragment @<scanner> @<end-chars>
1067 @> @<result> @<success-flag> @<consumed-flag>}
1068\end{describe}
1069
1070\begin{describe}{fun}
1071 {parse-delimited-fragment @<scanner> @<begin> @<end> \&key :keep-end
1072 \nlret @<result> @<success-flag> @<consumed-flag>}
1073\end{describe}
1074
dea4d055
MW
1075%%%----- That's all, folks --------------------------------------------------
1076
1077%%% Local variables:
1078%%% mode: LaTeX
1079%%% TeX-master: "sod.tex"
1080%%% TeX-PDF-mode: t
1081%%% End: