(@|eq|) type object for similar (possibly merely @|equal|) arguments. Where
not specified, clients may still not rely on receiving fresh objects.
-A convenient S-expression notation is provided by the @|c-type| macro. Use
-of this macro is merely an abbreviation for corresponding use of the various
-constructor functions, and therefore interns type objects in the same manner.
-The syntax accepted by the macro can be extended in order to support new
-classes: see @|defctype|, @|c-type-alias| and @|define-c-type-syntax|.
+A convenient S-expression notation is provided by the
+\descref{c-type}[macro]{mac}. Use of this macro is merely an abbreviation
+for corresponding use of the various constructor functions, and therefore
+interns type objects in the same manner. The syntax accepted by the macro
+can be extended in order to support new classes: see \descref{defctype}{mac},
+\descref{c-type-alias}{mac} and \descref{define-c-type-syntax}{mac}.
The descriptions of each of the various classes include descriptions of the
initargs which may be passed to @|make-instance| when constructing a new
There are two protocols for printing C types. Unfortunately they have
similar names.
\begin{itemize}
-\item The @|print-c-type| function prints a C type value using the
- S-expression notation. It is mainly useful for diagnostic purposes.
-\item The @|pprint-c-type| function prints a C type as a C-syntax
- declaration.
+\item The \descref{print-c-type}[function]{gf} prints a C type value using
+ the S-expression notation. It is mainly useful for diagnostic purposes.
+\item The \descref{pprint-c-type}[function]{gf} prints a C type as a
+ C-syntax declaration.
\end{itemize}
Neither generic function defines a default primary method; subclasses of
@|c-type| must define their own methods in order to print correctly.
+
\subsection{The C type root class} \label{sec:clang.c-types.root}
\begin{describe}{cls}{c-type ()}
The class @|c-type| is abstract.
\end{describe}
+
\subsection{C type S-expression notation} \label{sec:clang.c-types.sexp}
The S-expression representation of a type is described syntactically as a
\end{describe}
\begin{describe}{mac}
- {defctype @{ @<name> @! (@<name> @<nickname>^*) @} @<type-spec>
- @> @<names>}
+ {defctype \=@{ @<name> @! (@<name>^+) @} @<type-spec> \+ \\
+ @[[ @|:export| @<export-flag> @]]^* \-
+ \nlret @<names>}
Defines a new symbolic type specifier @<name>; if a list of @<name>s is
given, then all are defined in the same way. The type constructed by using
any of the @<name>s is as described by the type specifier @<type-spec>.
The resulting type object is constructed once, at the time that the macro
expansion is evaluated; the same (@|eq|) value is used each time any
@<name> is used in a type specifier.
+
+ A variable named @|c-type-@<name>|, for the first @<name> only, is defined
+ and initialized to contain the C type object so constructed. Altering or
+ binding this name is discouraged.
+
+ If @<export-flag> is true, then the variable name, and all of the @<name>s,
+ are exported from the current package.
\end{describe}
\begin{describe}{mac}{c-type-alias @<original> @<alias>^* @> @<aliases>}
default method.
\end{describe}
+
\subsection{Comparing C types} \label{sec:clang.c-types.cmp}
It is necessary to compare C types for equality, for example when checking
\end{describe}
\end{describe}
+
\subsection{Outputting C types} \label{sec:clang.c-types.output}
\begin{describe}{gf}{pprint-c-type @<c-type> @<stream> @<kernel>}
directly attached. If the @<kernel> function intends to provide its own
additional declarator operators, it should check the @<priority> in order
to determine whether parentheses are necessary. See also the
- @|maybe-in-parens| macro (page~\pageref{mac:maybe-in-parens}).
+ \descref{maybe-in-parens}[macro]{mac}.
The @<spacep> argument indicates whether a space needs to be printed in
order to separate the declarator from the declaration specifiers. A kernel
which contains an identifier should insert a space before the identifier
when @<spacep> is non-nil. An `empty' kernel, as found in an abstract
declarator (one that specifies no name), looks more pleasing without a
- trailing space. See also the @|c-type-space| function
- (page~\pageref{fun:c-type-space}).
+ trailing space. See also the \descref{c-type-space}[function]{fun}.
Every concrete subclass of @|c-type| is expected to provide a primary
method on this function. There is no default primary method.
within the @<form>s.
\end{describe}
+
\subsection{Type qualifiers and qualifiable types}
\label{sec:clang.ctypes.qual}
qualifiers; others keywords may be used, though this isn't recommended.
Two qualifiable types are equal only if they have \emph{matching
- qualifiers}: i.e., every qualifier attached to one is also attached to
- the other: order is not significant, and neither is multiplicity.
+ qualifiers}: i.e., every qualifier attached to one is also attached to the
+ other: order is not significant, and neither is multiplicity.
The class @|qualifiable-c-type| is abstract.
\end{describe}
type will be interned.
\end{describe}
-\begin{describe}{fun}{format-qualifiers @<qualifiers>}
+\begin{describe}{fun}{format-qualifiers @<qualifiers> @> @<string>}
Returns a string containing the qualifiers listed in @<qualifiers> in C
syntax, with a space after each. In particular, if @<qualifiers> is
non-null then the final character of the returned string will be a space.
\end{describe}
+
\subsection{Leaf types} \label{sec:clang.c-types.leaf}
A \emph{leaf type} is a type which is not defined in terms of another type.
\end{describe}
\begin{describe}{mac}
- {define-simple-c-type @{ @<name> @! (@<name>^*) @} @<string> @> @<name>}
+ {define-simple-c-type \=@{ @<name> @! (@<name>^+) @} @<string> \+ \\
+ @[[ @|:export| @<export-flag> @]] \-
+ \nlret @<name>}
Define type specifiers for a new simple C type. Each symbol @<name> is
defined as a symbolic type specifier for the (unique interned) simple C
type whose name is the value of @<string>. Further, each @<name> is
defined to be a type operator: the type specifier @|(@<name>
@<qualifier>^*)| evaluates to the (unique interned) simple C type whose
name is @<string> and which has the @<qualifiers> (which are evaluated).
+
+ Furthermore, a variable @|c-type-@<name>| is defined, for the first @<name>
+ only, and initialized with the newly constructed C type object.
+
+ If @<export-flag> is true, then the @|c-type-@<name>| variable name, and
+ all of the @<name>s, are exported from the current package.
\end{describe}
\begin{describe}{cls}{tagged-c-type (qualifiable-c-type)
keywords).
\end{describe}
+
\subsection{Compound C types} \label{sec:code.c-types.compound}
Some C types are \emph{compound types}: they're defined in terms of existing
this means depends on the class of @<c-type>.
\end{describe}
+
\subsection{Pointer types} \label{sec:clang.c-types.pointer}
-Pointers compound types. The subtype of a pointer type is the type it points
-to.
+Pointers are compound types. The subtype of a pointer type is the type it
+points to.
\begin{describe}{cls}
{c-pointer-type (qualifiable-c-type) \&key :qualifiers :subtype}
interned also.
\end{describe}
+
\subsection{Array types} \label{sec:clang.c-types.array}
Arrays implement the compound-type protocol. The subtype of an array type is
Returns the dimensions of @<c-type>, an array type, as an immutable list.
\end{describe}
+
\subsection{Function types} \label{sec:clang.c-types.fun}
Function types implement the compound-type protocol. The subtype of a
\end{describe}
\begin{describe*}
- {\dhead{fun}{argument-name @<argument> @> @<name>}
- \dhead{fun}{argument-type @<argument> @> @<c-type>}}
+ {\dhead{fun}{argument-name @<argument> @> @<name>}
+ \dhead{fun}{argument-type @<argument> @> @<c-type>}}
Accessor functions for @|argument| objects. They return the name (for
@|argument-name|) or type (for @|argument-type|) from the object, as passed
to @|make-argument|.
@|commentify-argument-names| to the argument list of the given type.
\end{describe}
+
\subsection{Parsing C types} \label{sec:clang.c-types.parsing}
\begin{describe}{fun}
\nlret @<result> @<success-flag> @<consumed-flag>}
\end{describe}
+
\subsection{Class types} \label{sec:clang.c-types.class}
\begin{describe}{cls}
This section deals with Sod's facilities for constructing and manipulating C
expressions, declarations, instructions and definitions.
+
\subsection{Temporary names} \label{sec:clang.codegen.temporaries}
Many C-level objects, especially ones with external linkage or inclusion in a
\begin{tabular}[C]{*2{>{\codeface}l}} \hlx*{hv}
\thd{\textbf{Variable}} & \thd{\textbf{Name format}} \\ \hlx{vhv}
{}*sod-ap* & sod__ap \\
- {}*sod-master-ap* & sod__master_ap \\ \hlx*{vh}
+ {}*sod-master-ap* & sod__master_ap \\
+ {}*null-pointer* & NULL \\ \hlx*{vh}
\end{tabular}
\caption{Well-known temporary names}
\label{tab:codegen.codegen.well-known-temps}
\end{table}
+
\subsection{Instructions} \label{sec:clang.codegen.insts}
\begin{describe}{cls}{inst () \&key}
\thd{Class name} &
\thd{Arguments} &
\thd{Output format} \\ \hlx{vhv}
- @|var| & @<name> @<type> @<init> & @<type> @<name> @[= @<init>@];
+ @|var| & @<name> @<type> @|\&optional| @<init>
+ & @<type> @<name> @[= @<init>@];
\\ \hlx{v}
@|set| & @<var> @<expr> & @<var> = @<expr>; \\ \hlx{v}
@|update| & @<var> @<op> @<expr> & @<var> @<op>= @<expr>;
@|break| & --- & break; \\ \hlx{v}
@|continue| & --- & continue; \\ \hlx{v}
@|expr| & @<expr> & @<expr>; \\ \hlx{v}
- @|call| & @<func> @<args> & @<func>(@<arg>_1,
+ @|call| & @<func> @|\&rest| @<args>
+ & @<func>(@<arg>_1,
$\ldots$,
- @<arg>_n) \\ \hlx{v}
- @|va-start| & @<ap> @<arg> & va_start(@<ap>, @<arg>);
- \\ \hlx{v}
- @|va-copy| & @<to> @<from> & va_copy(@<to>, @<from>);
- \\ \hlx{v}
- @|va-end| & @<ap> & va_end(@<ap>); \\ \hlx{vhv}
+ @<arg>_n) \\ \hlx{vhv}
@|block| & @<decls> @<body> & \{ @[@<decls>@] @<body> \}
\\ \hlx{v}
- @|if| & @<cond> @<conseq> @<alt> & if (@<cond>) @<conseq>
+ @|if| & @<cond> @<conseq> @|\&optional| @<alt>
+ & if (@<cond>) @<conseq>
@[else @<alt>@] \\ \hlx{v}
@|while| & @<cond> @<body> & while (@<cond>) @<body>
\\ \hlx{v}
@|do-while| & @<body> @<cond> & do @<body> while (@<cond>);
\\ \hlx{v}
@|function| & @<name> @<type> @<body> &
- @<type>_0 @<name>(@<type>_1 @<arg>_1, $\ldots$,
- @<type>_n @<arg>_n @[, \dots@])
- @<body> \\ \hlx*{vh}
+ \vtop{\hbox{\strut @<type>_0 @<name>(@<type>_1 @<arg>_1, $\ldots$,
+ @<type>_n @<arg>_n @[, \dots@])}
+ \hbox{\strut \quad @<body>}} \\ \hlx*{vh}
\end{tabular}
\caption{Instruction classes}
\label{tab:codegen.codegen.insts}
\end{table}
+
\subsection{Code generation} \label{sec:clang.codegen.codegen}
\begin{describe}{gf}{codegen-functions @<codegen> @> @<list>}
\begin{describe}{fun}{deliver-expr @<codegen> @<target> @<expr>}
\end{describe}
+\begin{describe}{fun}
+ {deliver-call @<codegen> @<target> @<func> \&rest @<args>}
+\end{describe}
+
\begin{describe}{fun}{convert-stmts @<codegen> @<target> @<type> @<func>}
\end{describe}