X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/6514430a3a91b340963ab7fb912a94a8d0b090fc..7de8c6661211bce3a2b2739b461f33a370294979:/doc/clang.tex diff --git a/doc/clang.tex b/doc/clang.tex index 8f3c676..87e8d47 100644 --- a/doc/clang.tex +++ b/doc/clang.tex @@ -7,7 +7,7 @@ %%%----- Licensing notice --------------------------------------------------- %%% -%%% This file is part of the Sensble Object Design, an object system for C. +%%% This file is part of the Sensible Object Design, an object system for C. %%% %%% SOD is free software; you can redistribute it and/or modify %%% it under the terms of the GNU General Public License as published by @@ -65,11 +65,12 @@ specified to return interned objects: programs may rely on receiving the same (@|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 @@ -80,14 +81,15 @@ syntax are strongly recommended over direct use of @|make-instance|. 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 ()} @@ -100,6 +102,7 @@ Neither generic function defines a default primary method; subclasses of 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 @@ -120,8 +123,9 @@ type specifier. Type specifiers fit into two syntactic categories. \end{describe} \begin{describe}{mac} - {defctype @{ @ @! (@ @^*) @} @ - @> @} + {defctype \=@{ @ @! (@^+) @} @ \+ \\ + @[[ @|:export| @ @]]^* \- + \nlret @} Defines a new symbolic type specifier @; if a list of @s is given, then all are defined in the same way. The type constructed by using any of the @s is as described by the type specifier @. @@ -129,6 +133,13 @@ type specifier. Type specifiers fit into two syntactic categories. 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 @ is used in a type specifier. + + A variable named @|c-type-@|, for the first @ only, is defined + and initialized to contain the C type object so constructed. Altering or + binding this name is discouraged. + + If @ is true, then the variable name, and all of the @s, + are exported from the current package. \end{describe} \begin{describe}{mac}{c-type-alias @ @^* @> @} @@ -169,6 +180,7 @@ type specifier. Type specifiers fit into two syntactic categories. 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 @@ -199,6 +211,7 @@ argument lists for methods. This is done by @|c-type-equal-p|. \end{describe} \end{describe} + \subsection{Outputting C types} \label{sec:clang.c-types.output} \begin{describe}{gf}{pprint-c-type @ @ @} @@ -235,15 +248,14 @@ argument lists for methods. This is done by @|c-type-equal-p|. directly attached. If the @ function intends to provide its own additional declarator operators, it should check the @ 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 @ 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 @ 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. @@ -282,6 +294,7 @@ argument lists for methods. This is done by @|c-type-equal-p|. within the @
s. \end{describe} + \subsection{Type qualifiers and qualifiable types} \label{sec:clang.ctypes.qual} @@ -295,8 +308,8 @@ argument lists for methods. This is done by @|c-type-equal-p|. 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} @@ -316,12 +329,13 @@ argument lists for methods. This is done by @|c-type-equal-p|. type will be interned. \end{describe} -\begin{describe}{fun}{format-qualifiers @} +\begin{describe}{fun}{format-qualifiers @ @> @} Returns a string containing the qualifiers listed in @ in C syntax, with a space after each. In particular, if @ 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. @@ -355,9 +369,11 @@ In Sod, the leaf types are \begin{tabular}[C]{ll} \hlx*{hv} \thd{C type} & \thd{Specifiers} \\ \hlx{vhv} @|void| & @|void| \\ \hlx{v} - @|char| & @|char| \\ \hlx{v} - @|unsigned char| & @|unsigned-char|, @|uchar| \\ \hlx{} - @|signed char| & @|signed-char|, @|schar| \\ \hlx{v} + @|_Bool| & @|bool| \\ \hlx{v} + @|char| & @|char| \\ \hlx{} + @|wchar_t| & @|wchar-t| \\ \hlx{v} + @|signed char| & @|signed-char|, @|schar| \\ \hlx{} + @|unsigned char| & @|unsigned-char|, @|uchar| \\ \hlx{v} @|short| & @|short|, @|signed-short|, @|short-int|, @|signed-short-int| @|sshort| \\ \hlx{} @|unsigned short| & @|unsigned-short|, @|unsigned-short-int|, @@ -370,17 +386,26 @@ In Sod, the leaf types are @|unsigned long| & @|unsigned-long|, @|unsigned-long-int|, @|ulong| \\ \hlx{v} @|long long| & @|long-long|, @|signed-long-long|, - @|long-long-int|, \\ + @|long-long-int|, \\ \hlx{} & \qquad @|signed-long-long-int|, @|llong|, @|sllong| \\ \hlx{v} @|unsigned long long| & @|unsigned-long-long|, @|unsigned-long-long-int|, @|ullong| \\ \hlx{v} + @|size_t| & @|size-t| \\ \hlx{} + @|ptrdiff_t| & @|ptrdiff-t| \\ \hlx{v} @|float| & @|float| \\ \hlx{} - @|double| & @|double| \\ \hlx{v} - @|va_list| & @|va-list| \\ \hlx{v} - @|size_t| & @|size-t| \\ \hlx{v} - @|ptrdiff_t| & @|ptrdiff-t| \\ \hlx*{vh} + @|double| & @|double| \\ \hlx{} + @|long double| & @|long-double| \\ \hlx{v} + @|float _Imaginary| & @|float-imaginary| \\ \hlx{} + @|double _Imaginary|& @|double-imaginary| \\ \hlx{} + @|long double _Imaginary| + & @|long-double-imaginary| \\ \hlx{v} + @|float _Complex| & @|float-complex| \\ \hlx{} + @|double _Complex| & @|double-complex| \\ \hlx{} + @|long double _Complex| + & @|long-double-complex| \\ \hlx{v} + @|va_list| & @|va-list| \\ \hlx*{vh} \end{tabular} \caption{Builtin symbolic type specifiers for simple C types} \label{tab:codegen.c-types.simple} @@ -399,13 +424,21 @@ In Sod, the leaf types are \end{describe} \begin{describe}{mac} - {define-simple-c-type @{ @ @! (@^*) @} @ @> @} + {define-simple-c-type \=@{ @ @! (@^+) @} @ \+ \\ + @[[ @|:export| @ @]] \- + \nlret @} Define type specifiers for a new simple C type. Each symbol @ is defined as a symbolic type specifier for the (unique interned) simple C type whose name is the value of @. Further, each @ is defined to be a type operator: the type specifier @|(@ @^*)| evaluates to the (unique interned) simple C type whose name is @ and which has the @ (which are evaluated). + + Furthermore, a variable @|c-type-@| is defined, for the first @ + only, and initialized with the newly constructed C type object. + + If @ is true, then the @|c-type-@| variable name, and + all of the @s, are exported from the current package. \end{describe} \begin{describe}{cls}{tagged-c-type (qualifiable-c-type) @@ -488,6 +521,7 @@ In Sod, the leaf types are 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 @@ -499,10 +533,11 @@ protocol. this means depends on the class of @. \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} @@ -531,6 +566,7 @@ to. 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 @@ -572,6 +608,7 @@ the array element type. Returns the dimensions of @, 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 @@ -597,13 +634,13 @@ function type is the type of the function's return value. argument name. \end{describe} -\begin{describe}{fun}{argument-name @ @> @} - Return the name of the @, as it was supplied to @|make-argument|. -\end{describe} - -\begin{describe}{fun}{argument-type @ @> @} - Return the type of the @, as it was supplied to @|make-argument|. -\end{describe} +\begin{describe*} + {\dhead{fun}{argument-name @ @> @} + \dhead{fun}{argument-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|. +\end{describe*} \begin{describe}{gf} {commentify-argument-name @ @> @} @@ -657,14 +694,19 @@ function type is the type of the function's return value. in the same order, and either both or neither argument list ends with @|:ellipsis|; argument names are not compared. - The type specifier @|(fun @ @{ (@ @) @}^* - @[:ellipsis @! . @ @])| constructs a function type. The function has - the subtype @. The remaining items in the type-specifier list - are used to construct the argument list. The argument items are a possibly - improper list, beginning with zero or more \emph{explicit arguments}: - two-item @/@ lists. For each such list, an @|argument| - object is constructed with the given name (evaluated) and type. Following - the explicit arguments, there may be + The type specifier + \begin{prog} + (fun @ + @{ (@ @) @}^* + @[:ellipsis @! . @@]) + \end{prog} + constructs a function type. The function has the subtype @. + The remaining items in the type-specifier list are used to construct the + argument list. The argument items are a possibly improper list, beginning + with zero or more \emph{explicit arguments}: two-item + @/@ lists. For each such list, an @|argument| object + is constructed with the given name (evaluated) and type. Following the + explicit arguments, there may be \begin{itemize} \item nothing, in which case the function's argument list consists only of the explicit arguments; @@ -714,14 +756,55 @@ function type is the type of the function's return value. @|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} + {parse-c-type @ + @> @ @ @} +\end{describe} + +\begin{describe}{fun} + {parse-declarator @ @ \&key :kernel :abstractp + \nlret @ @ @} +\end{describe} + + +\subsection{Class types} \label{sec:clang.c-types.class} + +\begin{describe}{cls} + {c-class-type (simple-c-type) \&key :class :tag :qualifiers :name} +\end{describe} + +\begin{describe*} + {\dhead{gf}{c-type-class @ @> @} + \dhead{gf}{setf (c-type-class @) @}} +\end{describe*} + +\begin{describe}{fun}{find-class-type @ @> @} +\end{describe} + +\begin{describe}{fun} + {make-class-type @ \&optional @ @> @} +\end{describe} + +\begin{describe}{fun} + {make-class-type @ \&optional @ @> @} +\end{describe} + +\begin{describe}{fun}{find-sod-class @ @> @} +\end{describe} + +\begin{describe}{fun}{record-sod-class @} +\end{describe} + %%%-------------------------------------------------------------------------- \section{Generating C code} \label{sec:clang.codegen} 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 @@ -790,12 +873,13 @@ Temporary names are represented by objects which implement a simple protocol. \thd{\textbf{Variable}} & \thd{\textbf{Name format}} \\ \hlx{vhv} {}*sod-ap* & sod__ap \\ {}*sod-master-ap* & sod__master_ap \\ - {}*sod-tmp-ap* & sod__tmp_ap \\ \hlx*{vh} + {}*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} @@ -818,12 +902,17 @@ Temporary names are represented by objects which implement a simple protocol. @^*} \end{describe} +\begin{describe}{fun} + {format-banner-comment @ @ \&rest @} +\end{describe} + \begin{table} \begin{tabular}[C]{ll>{\codeface}l} \hlx*{hv} \thd{Class name} & \thd{Arguments} & \thd{Output format} \\ \hlx{vhv} - @|var| & @ @ @ & @ @ @[= @@]; + @|var| & @ @ @|\&optional| @ + & @ @ @[= @@]; \\ \hlx{v} @|set| & @ @ & @ = @; \\ \hlx{v} @|update| & @ @ @ & @ @= @; @@ -833,31 +922,35 @@ Temporary names are represented by objects which implement a simple protocol. @|break| & --- & break; \\ \hlx{v} @|continue| & --- & continue; \\ \hlx{v} @|expr| & @ & @; \\ \hlx{v} - @|call| & @ @ & @(@_1, + @|call| & @ @|\&rest| @ + & @(@_1, $\ldots$, @_n) \\ \hlx{v} - @|va-start| & @ @ & va_start(@, @); - \\ \hlx{v} - @|va-copy| & @ @ & va_copy(@, @); - \\ \hlx{v} - @|va-end| & @ & va_end(@); \\ \hlx{vhv} + @|banner| & @ @|\&rest| @ + & /* @ */ \\ \hlx{vhv} @|block| & @ @ & \{ @[@@] @ \} \\ \hlx{v} - @|if| & @ @ @ & if (@) @ + @|if| & @ @ @|\&optional| @ + & if (@) @ @[else @@] \\ \hlx{v} @|while| & @ @ & while (@) @ \\ \hlx{v} @|do-while| & @ @ & do @ while (@); \\ \hlx{v} - @|function| & @ @ @ & - @_0 @(@_1 @_1, $\ldots$, - @_n @_n @[, \dots@]) - @ \\ \hlx*{vh} + @|function| & + \vtop{\hbox{\strut @ @ @} + \hbox{\strut \quad @|\&optional @|} + \hbox{\strut \quad @|\&rest| @}} & + \vtop{\hbox{\strut @[/* @ */@]} + \hbox{\strut @_0 @(@_1 @_1, $\ldots$, + @_n @_n @[, \dots@])} + \hbox{\strut \quad @}} \\ \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 @ @> @} @@ -876,7 +969,10 @@ Temporary names are represented by objects which implement a simple protocol. \begin{describe}{gf}{emit-decl @ @} \end{describe} -\begin{describe}{gf}{emit-declss @ @} +\begin{describe}{gf}{emit-decls @ @} +\end{describe} + +\begin{describe}{fun}{emit-banner @ @ \&rest @} \end{describe} \begin{describe}{gf}{codegen-push @} @@ -913,6 +1009,10 @@ Temporary names are represented by objects which implement a simple protocol. \begin{describe}{fun}{deliver-expr @ @ @} \end{describe} +\begin{describe}{fun} + {deliver-call @ @ @ \&rest @} +\end{describe} + \begin{describe}{fun}{convert-stmts @ @ @ @} \end{describe}