X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/84b9d17a506658db9f5100820aad88342502e641..944bf9362ff51217b1617f85126d26e821b8aa91:/doc/clang.tex diff --git a/doc/clang.tex b/doc/clang.tex index 6d256ec..aebc94d 100644 --- a/doc/clang.tex +++ b/doc/clang.tex @@ -68,11 +68,11 @@ specified to return interned objects: programs may rely on receiving the same not specified, clients may still not rely on receiving fresh objects. A convenient S-expression notation is provided by the -\descref{c-type}[macro]{mac}. Use of this macro is merely an abbreviation +\descref{mac}{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 \descref{defctype}{mac}, -\descref{c-type-alias}{mac} and \descref{define-c-type-syntax}{mac}. +can be extended in order to support new classes: see \descref{mac}{defctype}, +\descref{mac}{c-type-alias} and \descref{mac}{define-c-type-syntax}. The descriptions of each of the various classes include descriptions of the initargs which may be passed to @|make-instance| when constructing a new @@ -83,14 +83,17 @@ 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 \descref{print-c-type}[function]{gf} prints a C type value using +\item The \descref{gf}{print-c-type}[function] 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 +\item The \descref{gf}{pprint-c-type}[function] 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. +\begin{describe}{fun}{c-name-case @ @> @} +\end{describe} + \subsection{The C type root class} \label{sec:clang.c-types.root} @@ -169,12 +172,12 @@ type specifier. Type specifiers fit into two syntactic categories. \begin{describe}{gf}{expand-c-type-spec @ @> @
} Returns the Lisp form that @|(c-type @)| would expand into. - If @ is a list, then \descref{expand-c-type-form}{fun} is + If @ is a list, then \descref{gf}{expand-c-type-form} is invoked. \end{describe} \begin{describe}{gf}{expand-c-type-form @ @ @> @} - Returns the Lisp form that @|(c-type (@ . @)| would expand + Returns the Lisp form that @|(c-type (@ . @))| would expand into. \end{describe} @@ -208,12 +211,12 @@ argument lists for methods. This is done by @|c-type-equal-p|. The generic function @|c-type-equal-p| uses the @|and| method combination. - \begin{describe}{meth}{c-type-equal-p @_1 @_2} + \begin{describe}{meth}{t,t}{c-type-equal-p @_1 @_2} A default primary method for @|c-type-equal-p| is defined. It simply returns @|nil|. This way, methods can specialize on both arguments without fear that a call will fail because no methods are applicable. \end{describe} - \begin{describe}{ar-meth}{c-type-equal-p @_1 @_2} + \begin{describe}{ar-meth}{}{c-type-equal-p @_1 @_2} A default around-method for @|c-type-equal-p| is defined. It returns true if @_1 and @_2 are @|eql|; otherwise it delegates to the primary methods. Since several common kinds of C types are interned, @@ -258,19 +261,19 @@ 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 - \descref{maybe-in-parens}[macro]{mac}. + \descref{mac}{maybe-in-parens}[macro]. 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 \descref{c-type-space}[function]{fun}. + trailing space. See also the \descref{fun}{c-type-space}[function]. Every concrete subclass of @|c-type| is expected to provide a primary method on this function. There is no default primary method. - \begin{describe}{ar-meth}{pprint-c-type @ @ @} + \begin{describe}{ar-meth}{}{pprint-c-type @ @ @} A default around method is defined on @|pprint-c-type| which `canonifies' non-function @ arguments. In particular: \begin{itemize} @@ -318,18 +321,18 @@ is shown in \xref{tab:clang.ctypes.qual}. \begin{table} \begin{tabular}[C]{*2{>{\codeface}l}l} \hlx*{hv} - \thd{\textbf{C name}} & \thd{\textbf{Lisp name}} \\ \hlx{vhv} - _Atomic & :atomic \\ - const & :const \\ - restrict & :restrict \\ - volatile & :volatile \\ \hlx*{vh} + \thd{C name} & \thd{Lisp name} \\ \hlx{vhv} + _Atomic & :atomic \\ + const & :const \\ + restrict & :restrict \\ + volatile & :volatile \\ \hlx*{vh} \end{tabular} \caption{C and Lisp qualifier names} \label{tab:clang.ctypes.qual} \end{table} The default behaviour, on output, is to convert keywords to lowercase and hope for the best: special cases can be dealt with by adding appropriate -methods to \descref{c-qualifier-keyword}{gf}. +methods to \descref{gf}{c-qualifier-keyword}. \begin{describe}{cls}{qualifiable-c-type (c-type) \&key :qualifiers} The class @|qualifiable-c-type| describes C types which can bear @@ -347,12 +350,16 @@ methods to \descref{c-qualifier-keyword}{gf}. The class @|qualifiable-c-type| is abstract. \end{describe} +\begin{describe}{fun} + {canonify-qualifiers @ @> @} +\end{describe} + \begin{describe}{gf}{c-type-qualifiers @ @> @} Returns the qualifiers of the @|qualifiable-c-type| instance @ as an immutable list. \end{describe} -\begin{describe}{fun}{qualify-type @ @ @> @} +\begin{describe}{fun}{qualify-c-type @ @ @> @} The argument @ must be an instance of @|qualifiable-c-type|, currently bearing no qualifiers, and @ a list of qualifier keywords. The result is a C type object like @ except that it @@ -375,7 +382,8 @@ methods to \descref{c-qualifier-keyword}{gf}. methods exist for qualifier keywords which need special handling, such as @|:atomic|; they are not listed here explicitly. - \begin{describe}{meth}{c-qualifier-keyword @ @> @} + \begin{describe}{meth}{keyword} + {c-qualifier-keyword @ @> @} Returns the @'s print-name, in lower case. This is sufficient for the standard qualifiers @|:const|, @|:restrict|, and @|:volatile|. \end{describe} @@ -437,7 +445,7 @@ complicated objects. Returns the Lisp form that @ expands to within @|(c-type (specs @ @))|. - If @ is a list, then \descref{expand-c-storage-specifier-form} is + If @ is a list, then \descref{gf}{expand-c-storage-specifier-form} is invoked. \end{describe} @@ -500,6 +508,16 @@ In Sod, the leaf types are Two simple type objects are equal if and only if they have @|string=| names and matching qualifiers. + \def\x#1{\desclabel{const}{c-type-#1}} + \x{bool} \x{char} \x{wchar-t} \x{signed-char} \x{unsigned-char} \x{short} + \x{unsigned-short} \x{int} \x{unsigned} \x{long} \x{unsigned-long} + \x{long-long} \x{unsigned-long-long} \x{size-t} \x{ptrdiff-t} \x{float} + \x{double} \x{long-double} \x{float-imaginary} \x{double-imaginary} + \x{long-double-imaginary} \x{float-complex} \x{double-complex} + \x{long-double-complex} \x{va-list} \x{void} + \crossproduct\x{{{int}{uint}}{{}{-least}{-fast}}{{8}{16}{32}{64}}{{-t}}} + \crossproduct\x{{{int}{uint}}{{ptr}{max}}{{-t}}} + A number of symbolic type specifiers for builtin types are predefined as shown in \xref{tab:codegen.c-types.simple}. These are all defined as if by @|define-simple-c-type|, so can be used to construct qualified types. @@ -534,6 +552,18 @@ In Sod, the leaf types are @|ullong| \\ \hlx{v} @|size_t| & @|size-t| \\ \hlx{} @|ptrdiff_t| & @|ptrdiff-t| \\ \hlx{v} + @|int$n$_t| & @|int$n$-t| + (for $n \in \{ @|8|, @|16|, @|32|, @|64| \}$) + \\ \hlx{} + @|uint$n$_t| & @|uint$n$-t| \\ \hlx{} + @|int_least$n$_t| & @|int_least$n$-t| \\ \hlx{} + @|uint_least$n$_t| & @|uint_least$n$-t| \\ \hlx{} + @|int_fast$n$_t| & @|int_fast$n$-t| \\ \hlx{} + @|uint_fast$n$_t| & @|uint_fast$n$-t| \\ \hlx{v} + @|intptr_t| & @|intptr-t| \\ \hlx{} + @|uintptr_t| & @|uintptr-t| \\ \hlx{} + @|intmax_t| & @|intmax-t| \\ \hlx{} + @|uintmax_t| & @|uintmax-t| \\ \hlx{v} @|float| & @|float| \\ \hlx{} @|double| & @|double| \\ \hlx{} @|long double| & @|long-double| \\ \hlx{v} @@ -578,7 +608,7 @@ In Sod, the leaf types are evaluated). Each of the @s is associated with the resulting type for retrieval - by \descref{find-simple-c-type}{fun}. Furthermore, a variable + by \descref{fun}{find-simple-c-type}. Furthermore, a variable @|c-type-@| is defined, for the first @ only, and initialized with the newly constructed C type object. @@ -589,7 +619,7 @@ In Sod, the leaf types are \begin{describe}{fun} {find-simple-c-type @ @> @{ @ @! @|nil| @}} If @ is the name of a simple C type, as established by the - \descref{define-simple-c-type}[macro]{mac}, then return the corresponding + \descref{mac}{define-simple-c-type}[macro], then return the corresponding @|simple-c-type| object; otherwise, return @|nil|. \end{describe} @@ -609,6 +639,14 @@ In Sod, the leaf types are structs and unions. \end{boxy} +\begin{describe}{gf}{c-type-tag @ @> @} +\end{describe} + +\begin{describe}{fun} + {make-c-tagged-type @ @ \&optional @ + @> @} +\end{describe} + \begin{describe}{gf}{c-tagged-type-kind @ @> @} Returns a keyword classifying the tagged @: one of @|:enum|, @|:struct| or @|:union|. User-defined subclasses of @|tagged-c-type| @@ -635,6 +673,7 @@ In Sod, the leaf types are interned) enumerated type with the given @ and @s (all evaluated). \end{describe} + \begin{describe}{fun} {make-enum-type @ \&optional @ @> @} Return the (unique interned) C type object for the enumerated C type whose @@ -650,6 +689,7 @@ In Sod, the leaf types are interned) structured type with the given @ and @s (all evaluated). \end{describe} + \begin{describe}{fun} {make-struct-type @ \&optional @ @> @} Return the (unique interned) C type object for the structured C type whose @@ -819,8 +859,8 @@ function type is the type of the function's return value. argument name. A @ may be supplied. If the argument is used in a - keyword-argument list (e.g., in a \descref{c-keyword-function-type} - [object]{cls}), and the @ value is provided and non-nil, then its + keyword-argument list (e.g., in a \descref{cls}{c-keyword-function-type} + [object]), and the @ value is provided and non-nil, then its (unescaped) printed representation is used to provide a default value if the keyword argument is not supplied by the caller. \end{describe} @@ -844,11 +884,13 @@ function type is the type of the function's return value. including file from defining such names as macros. This generic function is used to convert names into a safe form. - \begin{describe}{meth}{commentify-argument-name (@ null) @> nil} + \begin{describe}{meth}{null} + {commentify-argument-name (@ null) @> nil} Returns nil: if the argument name is already omitted, it's safe for use in a header file. \end{describe} - \begin{describe}{meth}{commentify-argument-name (@ t) @> @} + \begin{describe}{meth}{t} + {commentify-argument-name (@ t) @> @} Returns the print form of @ wrapped in a C comment, as @`/*@*/'. \end{describe} @@ -907,7 +949,7 @@ function type is the type of the function's return value. arguments; or \item a possibly-improper list tail, beginning with an atom either as a list item or as the final list cdr, indicating that the entire list tail - is Lisp expression which is to be evaluated to compute the remaining + is a Lisp expression which is to be evaluated to compute the remaining arguments. \end{itemize} A tail expression may return a list of @|argument| objects, optionally @@ -951,9 +993,9 @@ function type is the type of the function's return value. Keyword functions are never considered to be the same as ordinary functions. Two keyword function types are considered to be the same if - their return types are the same, and their positional argument lists consist of - arguments with the same type, in the same order: the keyword arguments - accepted by the functions is not significant. + their return types are the same, and their positional argument lists + consist of arguments with the same type, in the same order: the keyword + arguments accepted by the functions is not significant. Keyword functions are constructed using an extended version of the @|fun| specifier used for ordinary C function types. The extended syntax is as @@ -970,7 +1012,7 @@ function type is the type of the function's return value. these circumstances obtains, then the specifier constructs an ordinary function type.) - See the description of \descref{c-function-type}{cls} for how a trailing + See the description of \descref{cls}{c-function-type} for how a trailing @ is handled. The list of @s and @s describes the positional @@ -984,7 +1026,7 @@ function type is the type of the function's return value. accepting the @. If the @ list contains a @|:keys| marker, then a - \descref{c-keyword-function-type}[object]{cls} is returned: those arguments + \descref{cls}{c-keyword-function-type}[object] is returned: those arguments preceding the @|:keys| marker form the positional argument list, and those following the marker form the list of keyword arguments. \end{describe} @@ -998,7 +1040,12 @@ function type is the type of the function's return value. \begin{describe}{gf} {c-function-arguments @ @> @} - Return the arguments list of the @. + Return the (non-keyword) argument list of the @. +\end{describe} + +\begin{describe}{gf} + {c-function-keywords @ @> @} + Return the keyword-argument list of the @. \end{describe} \begin{describe}{fun} @@ -1013,7 +1060,7 @@ function type is the type of the function's return value. \begin{describe}{fun}{reify-variable-argument-tail @ @> @} If the @ list contains an @|:ellipsis| marker, then replace it with a @|va_list|. The name for the new argument, if any, is taken from - the \descref{*sod-ap*}[variable]{var}. The new list is returned; the + the \descref{var}{*sod-ap*}[variable]. The new list is returned; the original list is not modified, but may share structure with the new list. \end{describe} @@ -1026,7 +1073,7 @@ function type is the type of the function's return value. The @ parameter is a list consisting of a number of @|(@ . @)| pairs: in each pair, @ is either nil or a function designator, and @ is a list of - \descref{argument}{cls} objects. + \descref{cls}{argument} objects. The resulting list contains exactly one argument for each distinct argument name appearing in the input @; this argument will contain the @@ -1040,7 +1087,7 @@ function type is the type of the function's return value. arguments and is expected to return two values: \begin{itemize} \item a file location @ or other object acceptable to - \descref{file-location}{gf}, to be used as the location of the main + \descref{gf}{file-location}, to be used as the location of the main error; and \item an object @, whose printed representation should be a noun phrase describing the object for which the argument lists are being @@ -1053,7 +1100,7 @@ function type is the type of the function's return value. for the @ lists containing the conflicting argument objects are called, in an arbitrary order, with a single argument which is the offending @|argument| object; the function is expected to issue information - messages (see \descref{info}{fun}) to give more detail for diagnosing the + messages (see \descref{fun}{info}) to give more detail for diagnosing the conflict. If a @ is nil, then nothing happens; this is considered poor practice. \end{describe} @@ -1069,7 +1116,7 @@ function type is the type of the function's return value. arguments, if any, will be printed by @. The @ function is a standard kernel-printing function - following the \descref{pprint-c-type}[protocol]{gf}. + following the \descref{gf}{pprint-c-type}[protocol]. The @ function is given a single argument, which is the @ to print on. It should not print the surrounding parentheses. @@ -1083,7 +1130,7 @@ function type is the type of the function's return value. \begin{describe}{fun}{pprint-argument-list @ @ @> @} Print an argument list to @. - The @ is a list of \descref{argument}[objects]{cls}, optionally + The @ is a list of \descref{cls}{argument}[objects], optionally containing an @|:ellipsis| marker. The function returns true if any arguments were actually printed. \end{describe} @@ -1120,10 +1167,6 @@ function type is the type of the function's return value. {make-class-type @ \&optional @ @> @} \end{describe} -\begin{describe}{fun} - {make-class-type @ \&optional @ @> @} -\end{describe} - \begin{describe}{fun}{find-sod-class @ @> @} \end{describe} @@ -1158,8 +1201,7 @@ Temporary names are represented by objects which implement a simple protocol. \begin{describe*} {\dhead{gf}{var-in-use-p @ @> @} - \dhead[setf var-in-use-p] - {gf}{setf (var-in-use-p @) @}} + \dhead{gf}{setf (var-in-use-p @) @}} \end{describe*} \subsubsection{Temporary name objects} @@ -1169,17 +1211,20 @@ Temporary names are represented by objects which implement a simple protocol. subclasses, but is also usable on its own. \end{describe} -\begin{describe}{meth} +\begin{describe}{gf}{temp-tag @ @> @} +\end{describe} + +\begin{describe}{meth}{temporary-name} {commentify-argument-name (@ temporary-name) @> nil} \end{describe} \begin{table} \begin{tabular}[C]{*2{>{\codeface}l}} \hlx*{hv} - \thd{\textbf{Class}} & \thd{\textbf{Name format}} \\ \hlx{vhv} - temporary-name & @ \\ - temporary-argument & sod__a@ \\ - temporary-function & sod__f@ \\ - temporary-variable & sod__v@ \\ \hlx*{vh} + \thd{Class} & \thd{Name format} \\ \hlx{vhv} + temporary-name & @ \\ + temporary-argument & sod__a@ \\ + temporary-function & sod__f@ \\ + temporary-variable & sod__v@ \\ \hlx*{vh} \end{tabular} \caption{Temporary name formats} \label{tab:codegen.codegen.temps-format} @@ -1201,11 +1246,13 @@ Temporary names are represented by objects which implement a simple protocol. \subsubsection{Well-known `temporary' names} \begin{table} + \def\x#1{\desclabel{var}{#1}} + \x{*sod-ap*} \x{*sod-master-ap*} \x{*null-pointer*} \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 \\ - {}*null-pointer* & NULL \\ \hlx*{vh} + \thd{Variable} & \thd{Name format} \\ \hlx{vhv} + {}*sod-ap* & sod__ap \\ + {}*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} @@ -1241,8 +1288,8 @@ Temporary names are represented by objects which implement a simple protocol. \begin{table} \begin{tabular}[C]{ll>{\codeface}l} \hlx*{hv} \thd{Class name} & - \thd{Arguments} & - \thd{Output format} \\ \hlx{vhv} + \thd{Arguments} & + \thd{Output format}\\ \hlx{vhv} @|var| & @ @ @|\&optional| @ & @ @ @[= @@]; \\ \hlx{v} @@ -1286,6 +1333,33 @@ Temporary names are represented by objects which implement a simple protocol. \label{tab:codegen.codegen.insts} \end{table} +\begin{describe*} + {\dhead*{cls}{@-inst (inst) \&key \dots} + \dhead*{fn}{make-@-inst \dots} + \dhead*{gf}{inst-@ @ @> @}} + \def\instclass#1#2#3{% + #1{cls}{#3-inst}[#2]% + #1{fun}{make-#3-inst}[#2]% + } + \def\instslot#1#2#3{#1{gf}{inst-#3}[#2]} + \def\makelabels#1#2{% + \def\x{\instclass{#1}{#2}} + \x{var} \x{set} \x{update} \x{cond} \x{return} \x{break} \x{continue} + \x{expr} \x{call} \x{banner} \x{block} \x{if} \x{for} \x{while} + \x{do-while} \x{function} + \def\x{\instslot{#1}{#2}} + \x{name} \x{type} \x{init} \x{var} \x{expr} \x{op} \x{cond} \x{conseq} + \x{alt} \x{func} \x{args} \x{control} \x{decls} \x{body} \x{update} + \x{banner} \x{banner-args} + } + \makelabels{\desclabel}{|(} + + Sod provides a number of built-in instruction types generated by + \descref{mac}{definst}: see \xref{tab:codegen.codegen.insts}. + + \makelabels{\descindex}{|)} +\end{describe*} + \subsection{Code generation} \label{sec:clang.codegen.codegen} @@ -1361,8 +1435,11 @@ Temporary names are represented by objects which implement a simple protocol. \begin{describe}{cls}{c-fragment () \&key :location :text} \end{describe} -\begin{describe}{gf}{c-fragment-text @ @> @} -\end{describe} +\begin{describe*} + {\dhead{gf}{c-fragment-text @ @> @} + \dhead{meth}{c-fragment} + {file-location (@ c-fragment) @> @}} +\end{describe*} \begin{describe}{fun} {scan-c-fragment @ @