| 1 | %%% -*-latex-*- |
| 2 | %%% |
| 3 | %%% Output machinery |
| 4 | %%% |
| 5 | %%% (c) 2015 Straylight/Edgeware |
| 6 | %%% |
| 7 | |
| 8 | %%%----- Licensing notice --------------------------------------------------- |
| 9 | %%% |
| 10 | %%% This file is part of the Sensible Object Design, an object system for C. |
| 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 | |
| 26 | \chapter{The output system} \label{ch:output} |
| 27 | |
| 28 | This chapter deals with actually generating output files. It will be of |
| 29 | interest to programmers introducing new layout object classes, or new kinds |
| 30 | of output files. An understanding of the material in |
| 31 | \xref{sec:structures.layout} will prove valuable. |
| 32 | |
| 33 | %%%-------------------------------------------------------------------------- |
| 34 | \section{Output sequencing} \label{sec:output.sequencer} |
| 35 | |
| 36 | C compilers are picky about the order in which things are presented to them |
| 37 | in their input; but information about the structure of our classes is |
| 38 | scattered among a variety of different layout objects. It's not the case |
| 39 | that a layout object only contributes to a single localized portion of the |
| 40 | output: for example, a @|vtmsgs| layout object is responsible for declaring |
| 41 | both the appropriate @|struct $C$__vtmsgs_$a$| structure in the header file, |
| 42 | populated with method entry pointers, but also declaring its member in the |
| 43 | enclosing @|struct $C$__vt_$i$| structure. |
| 44 | |
| 45 | One approach would be to have the various layout objects just know how to |
| 46 | call each other in the right order so as to have everything come out |
| 47 | properly. That would make extending the translator, e.g., to add new kinds |
| 48 | of layout objects, rather difficult. And it doesn't let users insert custom |
| 49 | C fragments in flexible ways. |
| 50 | |
| 51 | Instead, there's a clear separation between which things need to be output, |
| 52 | and the order in which they're produced. |
| 53 | |
| 54 | Ordering is handled by a \emph{sequencer} object. A sequencer doesn't know |
| 55 | anything particular about output: its job is simply to do things in a |
| 56 | particular order. It's described here because Sod only uses it for output |
| 57 | scheduling. |
| 58 | |
| 59 | A sequencer maintains a collection of named \emph{items}, each of which has a |
| 60 | name and a list of functions associated with it. A name can be any Lisp |
| 61 | object. Names are compared using @|equal|, so lists can be used to construct |
| 62 | a hierarchical namespace. |
| 63 | |
| 64 | The sequencer also maintains a collection of \emph{constraints}, which take |
| 65 | the form of lists of item names. A constraint of the form @|($N_1$, $N_2$, |
| 66 | $\ldots$, $N_k$)| requires that the item named $N_1$ must be scheduled before |
| 67 | the item named $N_2$, and so on, all of which must be scheduled before the |
| 68 | item named $N_k$. Items with these names do not need to exist or be known to |
| 69 | the sequencer. An item name may appear in any number of constraints, all of |
| 70 | which apply. |
| 71 | |
| 72 | It might be that a collection of constraints is impossible to satisfy: for |
| 73 | example, the set |
| 74 | \begin{center} \codeface |
| 75 | (alice bob) \qquad (bob carol) \qquad (carol alice) |
| 76 | \end{center} |
| 77 | can't be satisfied, since the first constraint requires that @|alice| |
| 78 | precedes @|bob|, but the third says that @|alice| must come after @|carol|, |
| 79 | and the second that @|carol| comes after @|bob|: it's not possible that |
| 80 | @|alice| comes before @|bob| and after @|bob|. In this case, the sequencer |
| 81 | fails and signals an error of type @|inconsistent-merge-error|. |
| 82 | |
| 83 | It is possible, but tedious, to explicitly order an entire collection of |
| 84 | items by adding constraints. In the absence of explicit constraints to order |
| 85 | them, items are ordered according to the order in which constraints naming |
| 86 | them were first added to the sequencer. Items not named in any constraint |
| 87 | are not processed at all. |
| 88 | |
| 89 | For example, suppose we have the following constraints. |
| 90 | \begin{center} \codeface |
| 91 | (perl java) \qquad |
| 92 | (lisp java) \qquad |
| 93 | (python icon) \qquad |
| 94 | (icon perl) |
| 95 | \end{center} |
| 96 | The constraints give us that $@|python| < @|icon| < @|perl| < @|java|$, and |
| 97 | also $@|lisp| < @|java|$. In this case, @|lisp| precedes @|python| because |
| 98 | @|lisp| is mentioned in the second constraint while @|python| isn't mentioned |
| 99 | until the third. So the final processing order is |
| 100 | \begin{center} |
| 101 | @|lisp|, \quad |
| 102 | @|python|, \quad |
| 103 | @|icon|, \quad |
| 104 | @|perl|, \quad |
| 105 | @|java| |
| 106 | \end{center} |
| 107 | |
| 108 | |
| 109 | \begin{describe}{cls}{sequencer-item} |
| 110 | An object of class @|sequencer-item| represents a sequencer item. |
| 111 | Sequencer items maintain a \emph{name} and a list of \emph{functions}. |
| 112 | Names are compared using @|equal|. |
| 113 | |
| 114 | The functions are maintained in \emph{reverse order}, because it's |
| 115 | convenient to be able to add new functions using @|push|. |
| 116 | \end{describe} |
| 117 | |
| 118 | \begin{describe}{fun}{sequencer-item-p @<object> @> @<generalized-boolean>} |
| 119 | Return non-nil if and only if @<object> is a @|sequencer-item|. |
| 120 | \end{describe} |
| 121 | |
| 122 | \begin{describe}{fun} |
| 123 | {make-sequencer-item @<name> \&optional @<functions> @> @<item>} |
| 124 | Create and return a new sequencer item with the given @<name> and list of |
| 125 | @<functions>; the list of functions defaults to nil if omitted. |
| 126 | \end{describe} |
| 127 | |
| 128 | \begin{describe*} |
| 129 | {\dhead{fun}{sequencer-item-name @<item> @> @<name>} |
| 130 | \dhead{fun}{sequencer-item-functions @<item> @> @<list>} |
| 131 | \dhead{fun}{setf (sequencer-item-functions @<item>) @<list>}} |
| 132 | These functions read or modify the state of a sequencer @<item>, as |
| 133 | originally established by @|make-sequencer-item|. |
| 134 | |
| 135 | It is an error to modify an item's list of functions during a call to |
| 136 | @|invoke-sequencer-items| on the item's owning sequencer. |
| 137 | \end{describe*} |
| 138 | |
| 139 | \begin{describe}{cls}{sequencer () \&key :constraints} |
| 140 | \end{describe} |
| 141 | |
| 142 | \begin{describe*} |
| 143 | {\dhead{fun}{sequencer-constraints @<sequencer> @> @<list>} |
| 144 | \dhead{fun}{setf (sequencer-constraints @<sequencer>) @<list>} |
| 145 | \dhead{fun}{sequencer-table @<sequencer> @> @<hash-table>}} |
| 146 | \end{describe*} |
| 147 | |
| 148 | \begin{describe}{fun}{ensure-sequencer-item @<sequencer> @<name> @> @<item>} |
| 149 | \end{describe} |
| 150 | |
| 151 | \begin{describe}{fun}{add-sequencer-constraint @<sequencer> @<constraint>} |
| 152 | \end{describe} |
| 153 | |
| 154 | \begin{describe}{fun} |
| 155 | {add-sequencer-item-function @<sequencer> @<name> @<function>} |
| 156 | \end{describe} |
| 157 | |
| 158 | \begin{describe}{fun} |
| 159 | {invoke-sequencer-items @<sequencer> \&rest @<arguments>} |
| 160 | \end{describe} |
| 161 | |
| 162 | \begin{describe}{gf}{hook-output @<object> @<reason> @<sequencer>} |
| 163 | \begin{describe}{meth}{t,t} |
| 164 | {hook-output (@<object> t) (@<reason> t) @<sequencer>} |
| 165 | \end{describe} |
| 166 | \end{describe} |
| 167 | |
| 168 | \begin{describe}{mac} |
| 169 | {sequence-output (@<stream-var> @<sequencer>) \\ \ind |
| 170 | @[ :constraint (@<item-name>^*) @] \\ |
| 171 | @{ (@<item-name> @<form>^*) @}^*} |
| 172 | \end{describe} |
| 173 | |
| 174 | %%%-------------------------------------------------------------------------- |
| 175 | \section{Output structure} \label{output.structure} |
| 176 | |
| 177 | The structures of the header and implementation files produced by the |
| 178 | translator are detailed in tables~\ref{tab:output.structure.header} |
| 179 | and~\ref{tab:output.structure.impl}, respectively. |
| 180 | |
| 181 | The following notes may be helpful. |
| 182 | \begin{itemize} |
| 183 | \item The `specializers' shown in the tables identify the method of the |
| 184 | @|hook-output| function responsible for producing the corresponding |
| 185 | `contents'. Subclasses can extend or override the listed methods (with |
| 186 | appropriate care). |
| 187 | \item A row showing an `item' but no `specializers' indicate that the |
| 188 | translator does not prodice output for that item. It may be present for |
| 189 | ordering purposes, or as a place for user output. |
| 190 | \item A row showing `specializers' but (apparently) no `contents' indicates |
| 191 | that a blank line is emitted at that point. |
| 192 | \end{itemize} |
| 193 | |
| 194 | \begingroup |
| 195 | \LTleft=-\leftindent plus 1fil minus 1fil |
| 196 | \LTright=0pt plus 1fil minus 1fil |
| 197 | \small |
| 198 | \def\banner#1{\hbox to\hsize{/*@-@-@-@-@- #1 |
| 199 | \rlap{@-}\leaders\hbox{@-}\hfil\llap{@-}*/}} |
| 200 | \def\fmtspecs#1, #2 {@|#1|, @|(eql #2)|} |
| 201 | \def\slotlabel#1#2{\leavevmode\hbox to30mm{\kern#1em/* #2\hfil= */}} |
| 202 | |
| 203 | \clearpage |
| 204 | \begin{longtable}{>{\codeface}p{41mm}>{\fmtspecs}l>{\codeface}p{65mm}} |
| 205 | \caption{Header file output structure} |
| 206 | \label{tab:output.structure.header} \\ \hlx{hv} |
| 207 | \thd{Sequencer item} & \thd{@|hook-output| specializers} |
| 208 | & \thd{Output} \\ \hlx{vhv} |
| 209 | \endfirsthead |
| 210 | \caption[]{Header file output structure \emph{(cont.)}} \\ \hlx{hv} |
| 211 | \thd{Sequencer item} & \thd{@|hook-output| specializers} |
| 212 | & \thd{Contents} \\ \hlx{vhv} |
| 213 | \endhead |
| 214 | \hlx{vh} |
| 215 | \endfoot |
| 216 | x & sod-class-effective-slot, 'class & x \kill |
| 217 | % |
| 218 | :prologue & module, :h |
| 219 | & \begin{nprog} |
| 220 | /\=* @-*@- mode: c; indent-tabs-mode: nil @-*@- \\ |
| 221 | \>* \\ |
| 222 | \>* Header file generated by SOD for @<module> \\ |
| 223 | \>*/ \\ |
| 224 | \end{nprog} \\ \hlx{v/} |
| 225 | (:guard :start) & module, :h |
| 226 | & \begin{nprog} |
| 227 | \#ifndef @<MODULE>{}_H \\ |
| 228 | \#define @<MODULE>{}_H \\+ |
| 229 | \#ifdef __cplusplus \\ \ind |
| 230 | extern "C" \{ \-\\ |
| 231 | \#endif \\ |
| 232 | \end{nprog} \\ \hlx{v/} |
| 233 | % |
| 234 | (:typedefs :start) & module, :h |
| 235 | & \begin{nprog} \banner{Forward type declarations} \\ \end{nprog} |
| 236 | \\*\hlx{v} |
| 237 | :typedefs & sod-class, :h |
| 238 | & typedef struct @<class>{}__ichain_@<cls> @<class>; \\*\hlx{v} |
| 239 | (:typedefs :end) & module, :h \\ \hlx{v/} |
| 240 | % |
| 241 | (:includes :start) & module, :h |
| 242 | & \begin{nprog} \banner{External header files} \\ \end{nprog} |
| 243 | \\*\hlx{v} |
| 244 | :includes \\*\hlx{v} |
| 245 | :early-decls & sod-class, :h |
| 246 | & SOD__VARARGS_MACRO_PREAMBLE \\*\hlx{v} |
| 247 | (:includes :end) & module, :h \\*\hlx{v} |
| 248 | % |
| 249 | (:early-user :start) \\* |
| 250 | :early \\* |
| 251 | (:early-user :end) \\ \hlx{v/} |
| 252 | % |
| 253 | (:classes :start) \\*\hlx{v} |
| 254 | % |
| 255 | (@<class> :banner) & sod-class, :h |
| 256 | & \begin{nprog} \banner{Class @<class>} \\ \end{nprog} \\*\hlx{v} |
| 257 | % |
| 258 | (@<class> :islots :start) & sod-class, :h |
| 259 | & \begin{nprog} |
| 260 | /* Instance slots. */ \\ |
| 261 | struct @<class>{}__islots \{ |
| 262 | \end{nprog} \\*\hlx{v} |
| 263 | (@<class> :islots :slots) & sod-slot, 'islots |
| 264 | & \quad @<type> @<slot-name>; \\*\hlx{v} |
| 265 | (@<class> :islots :end) & sod-class, :h |
| 266 | & \begin{nprog} \}; \\ \end{nprog} \\ \hlx{v/} |
| 267 | % |
| 268 | (@<class> :vtmsgs :start) \\* |
| 269 | (@<class> :vtmsgs @<super> :start) & vtmsgs, 'vtmsgs |
| 270 | & \begin{nprog} |
| 271 | /* Messages protocol from class @<super>. */ \\* |
| 272 | struct @<class>{}__vtmsgs_@<s> \{ |
| 273 | \end{nprog} \\*\hlx{v} |
| 274 | (@<class> :vtmsgs @<super> :slots) & method-entry, 'vtmsgs |
| 275 | & \quad @<type> (*msg)(@<class> *, \dots); \\*\hlx{v} |
| 276 | (@<class> :vtmsgs @<super> :end) & vtmsgs, 'vtmsgs |
| 277 | & \begin{nprog} \}; \\ \end{nprog} \\* |
| 278 | (@<class> :vtmsgs :end) \\ \hlx{v/} |
| 279 | % |
| 280 | (@<class> :vtables :start) \\* |
| 281 | \begin{nprog} |
| 282 | (@<class> \=:vtable \\ |
| 283 | \>@<chain-head> :start) |
| 284 | \end{nprog} & vtable, :h |
| 285 | & \begin{nprog} |
| 286 | /* Vtable structure. */ \\* |
| 287 | struct @<class>{}__vt_@<h> \{ |
| 288 | \end{nprog} \\*\hlx{v} |
| 289 | \begin{nprog} |
| 290 | (@<class> \=:vtable \\ |
| 291 | \>@<chain-head> :slots) |
| 292 | \end{nprog} & class-pointer, :h |
| 293 | & \quad const @<meta> *_class; \\* |
| 294 | \begin{nprog} |
| 295 | (@<class> \=:vtable \\ |
| 296 | \>@<chain-head> :slots) |
| 297 | \end{nprog} & class-pointer, :h |
| 298 | & \quad const @<meta> *_cls_@<n>; \\* |
| 299 | \begin{nprog} |
| 300 | (@<class> \=:vtable \\ |
| 301 | \>@<chain-head> :slots) |
| 302 | \end{nprog} & base-offset, :h |
| 303 | & \quad size_t _base; \\* |
| 304 | \begin{nprog} |
| 305 | (@<class> \=:vtable \\ |
| 306 | \>@<chain-head> :slots) |
| 307 | \end{nprog} & chain-offset, :h |
| 308 | & \quad ptrdiff_t _off_@<h>; \\* |
| 309 | \begin{nprog} |
| 310 | (@<class> \=:vtable \\ |
| 311 | \>@<chain-head> :slots) |
| 312 | \end{nprog} & vmsgs, :h |
| 313 | & \quad struct @<class>{}__vtmsgs_@<s> @<s>; \\*\hlx{v} |
| 314 | \begin{nprog} |
| 315 | (@<class> \=:vtable \\ |
| 316 | \>@<chain-head> :end) |
| 317 | \end{nprog} & vtable, :h |
| 318 | & \begin{nprog} |
| 319 | \}; \\+ |
| 320 | /* Union of equivalent superclass vtables. */ \\ |
| 321 | union @<class>{}__vtu_@<h> \{ \\ \ind |
| 322 | struct @<super>{}__vt_@<h> @<s>; \\ |
| 323 | \quad $\vdots$ \-\\ |
| 324 | \}; \\ |
| 325 | \end{nprog} \\* |
| 326 | (@<class> :vtables :end) \\ |
| 327 | % |
| 328 | (@<class> :vtable-externs) & sod-class, :h |
| 329 | & /* Vtable structures. */ \\* |
| 330 | (@<class> :vtable-externs) & vtable, :h |
| 331 | & extern const union @<class>{}__vtu_@<h> @<class>{}__vtable_@<h>; |
| 332 | \\* |
| 333 | (@<class> :vtable-externs-after) & sod-class, :h \\ \hlx{v/} |
| 334 | % |
| 335 | (@<class> :methods :start) & sod-class, :h |
| 336 | & /* Direct methods. */ \\* |
| 337 | (@<class> :methods :defs) & sod-method, :h |
| 338 | & \begin{nprog} |
| 339 | struct @<class>{}__@<role>{}_suppliedp_@<s>{}__@<msg> \{ \\ \ind |
| 340 | unsigned @<arg>: 1; \\ |
| 341 | \quad $\vdots$ \-\\ |
| 342 | \}; \\ |
| 343 | \end{nprog} \\*\hlx{v} |
| 344 | (@<class> :methods) & sod-method, :h |
| 345 | & struct @<class>{}__@<role>{}_method_@<s>{}__@<msg>(\dots); |
| 346 | \\*\hlx{v} |
| 347 | (@<class> :methods :end) & sod-class, :h \\ \hlx{v/} |
| 348 | % |
| 349 | (@<class> :ichains :start) \\* |
| 350 | \begin{nprog} |
| 351 | (@<class> \=:ichains \\ |
| 352 | \>@<chain-head> :start) |
| 353 | \end{nprog} & ichain, :h |
| 354 | & \begin{nprog} |
| 355 | /* Instance chain structure. */ \\ |
| 356 | struct @<class>{}__ichain_@<h> \{ |
| 357 | \end{nprog} \\*\hlx{v} |
| 358 | \begin{nprog} |
| 359 | (@<class> \=:ichains \\ |
| 360 | \>@<chain-head> :slots) |
| 361 | \end{nprog} & vtable-pointer, :h |
| 362 | & \quad const struct @<class>{}__vt_@<h> *_vt; \\* |
| 363 | \begin{nprog} |
| 364 | (@<class> \=:ichains \\ |
| 365 | \>@<chain-head> :slots) |
| 366 | \end{nprog} & islots, :h |
| 367 | & \quad struct @<class>{}__islots @<c>; \\*\hlx{v} |
| 368 | \begin{nprog} |
| 369 | (@<class> \=:ichains \\ |
| 370 | \>@<chain-head> :end) |
| 371 | \end{nprog} & vtable, :h |
| 372 | & \begin{nprog} |
| 373 | \}; \\+ |
| 374 | /* Union of equivalent superclass chains. */ \\ |
| 375 | union @<class>{}__ichainu_@<h> \{ \\ \ind |
| 376 | struct @<super>{}__ichain_@<h> @<s>; \\ |
| 377 | \quad $\vdots$ \-\\ |
| 378 | \}; \\ |
| 379 | \end{nprog} \\* |
| 380 | (@<class> :ichains :end) \\ \hlx{v/} |
| 381 | % |
| 382 | (@<class> :ilayout :start) & ilayout, :h |
| 383 | & \begin{nprog} |
| 384 | /* Instance layout. */ \\ |
| 385 | struct @<class>{}__ilayout \{ |
| 386 | \end{nprog} \\*\hlx{v} |
| 387 | (@<class> :ilayout :slots) & ichain, 'ilayout |
| 388 | & \quad union @<class>{}__ichainu_@<h>; \\*\hlx{v} |
| 389 | (@<class> :ilayout :end) & ilayout, :h |
| 390 | & \begin{nprog} \}; \\ \end{nprog} \\ \hlx{v/} |
| 391 | % |
| 392 | (@<class> :conversions) & sod-class, :h |
| 393 | & \begin{nprog} |
| 394 | /* Conversion macros. */ \\ |
| 395 | \#define @<CLASS>{}__CONV_@<S>(_obj) \dots \\ |
| 396 | \quad $\vdots$ \\ |
| 397 | \end{nprog} \\ \hlx{v/} |
| 398 | % |
| 399 | (@<class> :message-macros) & sod-class, :h |
| 400 | & \begin{nprog} |
| 401 | /* Message invocation macros. */ \\ |
| 402 | \#define @<class>{}_@<msg>(me, \dots) \dots \\ |
| 403 | \quad $\vdots$ \\ |
| 404 | \end{nprog} \\ \hlx{v/} |
| 405 | % |
| 406 | (@<class> :object) & sod-class, :h |
| 407 | & \begin{nprog} |
| 408 | /* The class object. */ \\ |
| 409 | extern const struct @<meta>{}__ilayout @<class>{}__classobj; \\ |
| 410 | \#define @<class>{}__class (\&\dots) \\ |
| 411 | \#define @<class>{}__cls_@<n> (\&\dots) \\ |
| 412 | \quad $\vdots$ \\ |
| 413 | \end{nprog} \\*\hlx{v} |
| 414 | % |
| 415 | (:classes :end) \\ \hlx{v/} |
| 416 | % |
| 417 | (:user :start) \\* |
| 418 | :user \\* |
| 419 | (:user :end) \\ \hlx{v/} |
| 420 | % |
| 421 | (:guard :end) & module, :h |
| 422 | & \begin{nprog} |
| 423 | \banner{That's all, folks} \\+ |
| 424 | \#ifdef __cplusplus \\ \ind |
| 425 | \} \-\\ |
| 426 | \#endif \\+ |
| 427 | \#endif |
| 428 | \end{nprog} \\*\hlx{v} |
| 429 | % |
| 430 | :epilogue \\ |
| 431 | \end{longtable} |
| 432 | |
| 433 | \clearpage |
| 434 | \begin{longtable}{>{\codeface}p{41mm}>{\fmtspecs}l>{\codeface}p{65mm}} |
| 435 | \caption{Implementation file output structure} |
| 436 | \label{tab:output.structure.impl} \\ \hlx{hv} |
| 437 | \thd{Sequencer item} & \thd{@|hook-output| specializers} |
| 438 | & \thd{Contents} \\ \hlx{vhv} |
| 439 | \endfirsthead |
| 440 | \caption[]{Implementation file output structure \emph{(cont.)}} |
| 441 | \\ \hlx{hv} |
| 442 | \thd{Sequencer item} & \thd{@|hook-output| specializers} |
| 443 | & \thd{Contents} \\ \hlx{vhv} |
| 444 | \endhead |
| 445 | \hlx{vh} |
| 446 | \endfoot |
| 447 | % |
| 448 | :prologue & module, :c |
| 449 | & \begin{nprog} |
| 450 | /\=* @-*@- mode: c; indent-tabs-mode: nil @-*@- \\ |
| 451 | \>* \\ |
| 452 | \>* Implementation file generated by SOD for @<module> \\ |
| 453 | \>*/ \\ |
| 454 | \end{nprog} \\ \hlx{v/} |
| 455 | % |
| 456 | (:includes :start) & module, :c |
| 457 | & \begin{nprog} |
| 458 | \banner{External header files} \\ |
| 459 | \end{nprog} \\*\hlx{v} |
| 460 | :includes \\*\hlx{v} |
| 461 | (:includes :end) & module, :c \\*\hlx{v} |
| 462 | % |
| 463 | (:early-user :start) \\* |
| 464 | :early \\* |
| 465 | (:early-user :end) \\ \hlx{v/} |
| 466 | % |
| 467 | (:classes :start) \\*\hlx{v} |
| 468 | % |
| 469 | (@<class> :banner) & sod-class, :c |
| 470 | & \begin{nprog} \banner{Class @<class>} \\ \end{nprog} \\*\hlx{v} |
| 471 | % |
| 472 | (@<class> :direct-methods :start) \\*\hlx{v} |
| 473 | \begin{nprog} |
| 474 | (@<class> \=:direct-method \\ |
| 475 | \>@<method> :banner) |
| 476 | \end{nprog} & sod-method, :c |
| 477 | & /* Direct @<role> method on `@<s>.@<msg>' defined by @<class>. */ |
| 478 | \\*\hlx{v} |
| 479 | \begin{nprog} |
| 480 | (@<class> \=:direct-method \\ |
| 481 | \>@<method> :start) |
| 482 | \end{nprog} & delegating-direct-method, :c |
| 483 | & \#define CALL_NEXT_METHOD (next_method(\dots)) \\*\hlx{v} |
| 484 | \begin{nprog} |
| 485 | (@<class> \=:direct-method \\ |
| 486 | \>@<method> :body) |
| 487 | \end{nprog} & sod-method, :c |
| 488 | & \begin{nprog} |
| 489 | @<type> @<class>{}__@<role>{}_method_@<s>{}__@<msg>(\dots) \\ |
| 490 | \{ \\ \ind |
| 491 | $\vdots$ \-\\ |
| 492 | \} |
| 493 | \end{nprog} \\*\hlx{v} |
| 494 | \begin{nprog} |
| 495 | (@<class> \=:direct-method \\ |
| 496 | \>@<method> :end) |
| 497 | \end{nprog} & delegating-direct-method, :c |
| 498 | & \#undef CALL_NEXT_METHOD \\* |
| 499 | \begin{nprog} |
| 500 | (@<class> \=:direct-method \\ |
| 501 | \>@<method> :end) |
| 502 | \end{nprog} & sod-method, :c \\*\hlx{v} |
| 503 | (@<class> :direct-methods :end) \\ \hlx{v/} |
| 504 | % |
| 505 | (@<class> :effective-methods) & basic-effective-method, :c |
| 506 | & \begin{nprog} |
| 507 | /\=* Keyword argument structure for `@<s>.@<msg>' defined \\ |
| 508 | \>* on class @<class>. \\ |
| 509 | \>*/ \\ |
| 510 | struct @<class>{}__keywords_@<s>{}__@<msg> \{ \\ \ind |
| 511 | unsigned @<arg>{}__suppliedp: 1; \\ |
| 512 | \quad $\vdots$ \\ |
| 513 | @<type> @<arg>; \\ |
| 514 | \quad $\vdots$ \-\\ |
| 515 | \}; \\+ |
| 516 | @<effective-method-functions> \\ |
| 517 | \end{nprog} \\ \hlx{v/} |
| 518 | % |
| 519 | (@<class> :vtables :start) \\*\hlx{v} |
| 520 | (@<class> :vtable @<chain-head> :start) & vtable, :c |
| 521 | & \begin{nprog} |
| 522 | /* Vtable for @<chain-head> chain. */ \\ |
| 523 | const union @<class>{}__vtu_@<h> @<class>{}__vtable_@<h> = \{ |
| 524 | \end{nprog} \\*\hlx{v} |
| 525 | \begin{nprog} |
| 526 | (@<class> \=:vtable @<chain-head> \\ |
| 527 | \>:class-pointer @<meta>) |
| 528 | \end{nprog} & class-pointer, :c |
| 529 | & \slotlabel{1}{_class} \&@<cls>{}__classobj.@<n>.@<n>, \\* |
| 530 | \begin{nprog} |
| 531 | (@<class> \=:vtable @<chain-head> \\ |
| 532 | \>:class-pointer @<meta>) |
| 533 | \end{nprog} & class-pointer, :c |
| 534 | & \slotlabel{1}{_cls_@<n>} \&@<cls>{}__classobj.@<n>.@<n>, \\* |
| 535 | \begin{nprog} |
| 536 | (@<class> \=:vtable @<chain-head> \\ |
| 537 | \>:base-offset) |
| 538 | \end{nprog} & base-offset, :c |
| 539 | & \slotlabel{1}{_base} offsetof(\dots), \\* |
| 540 | \begin{nprog} |
| 541 | (@<class> \=:vtable @<chain-head> \\ |
| 542 | \>:chain-offset @<target-chain>) |
| 543 | \end{nprog} & chain-offset, :c |
| 544 | & \slotlabel{1}{_off_@<i>} SOD_OFFSETDIFF(\dots), \\* |
| 545 | \begin{nprog} |
| 546 | (@<class> \=:vtable @<chain-head> \\ |
| 547 | \>:vtmsgs @<super> :start) |
| 548 | \end{nprog} & vtmsgs, :c |
| 549 | & \quad \{ /* Method entries for @<super> messags. */ \\* |
| 550 | \begin{nprog} |
| 551 | (@<class> \=:vtable @<chain-head> \\ |
| 552 | \>:vtmsgs @<super> :slots) |
| 553 | \end{nprog} & method-entry, :c |
| 554 | & \slotlabel{2}{@<mentry>} @<mentry-func>, \\ |
| 555 | \begin{nprog} |
| 556 | (@<class> \=:vtable @<chain-head> \\ |
| 557 | \>:vtmsgs @<super> :end) |
| 558 | \end{nprog} & vtmsgs, :c |
| 559 | & \quad \}, \\* |
| 560 | (@<class> :vtable @<chain-head> :end) & vtable, :c |
| 561 | & \}; \\*\hlx{v} |
| 562 | (@<class> :vtables :end) \\ \hlx{v/} |
| 563 | % |
| 564 | (@<class> :object :prepare) & sod-class-effective-slot, 'class |
| 565 | & @<definitions> \\*\hlx{v} |
| 566 | % |
| 567 | (@<class> :object :start) & sod-class, :c |
| 568 | & \begin{nprog} |
| 569 | /* The class object. */ \\ |
| 570 | const struct @<meta>{}__ilayout @<class>{}__classobj = \{ |
| 571 | \end{nprog} \\*\hlx{v} |
| 572 | % |
| 573 | \begin{nprog} |
| 574 | (@<class> \=:object \\ |
| 575 | \>@<meta-head> :ichain :start) |
| 576 | \end{nprog} & ichain, 'class |
| 577 | & \quad \{ \{ /* @<n> ichain */ \\* |
| 578 | \begin{nprog} |
| 579 | (@<class> \=:object \\ |
| 580 | \>@<meta-head> :ichain :start) |
| 581 | \end{nprog} & vtable-pointer, 'class |
| 582 | & \slotlabel{3}{_vt} \&@<meta>{}__vtable_@<n>.@<m>, \\* |
| 583 | \begin{nprog} |
| 584 | (@<class> \=:object \\ |
| 585 | \>@<meta> :slots :start) |
| 586 | \end{nprog} & islots, 'class |
| 587 | & \quad\quad\quad \{ /* Class @<meta> */ \\* |
| 588 | \begin{nprog} |
| 589 | (@<class> \=:object \\ |
| 590 | \>@<meta> :slots) |
| 591 | \end{nprog} & effective-slot, 'class |
| 592 | & \slotlabel{4}{@<slot>} @<value> \\* |
| 593 | \begin{nprog} |
| 594 | (@<class> \=:object \\ |
| 595 | \>@<meta> :slots :end) |
| 596 | \end{nprog} & islots, 'class |
| 597 | & \quad\quad\quad \} \\* |
| 598 | \begin{nprog} |
| 599 | (@<class> \=:object \\ |
| 600 | \>@<meta-head> :ichain :end) |
| 601 | \end{nprog} & ichain, 'class |
| 602 | & \quad \} \}, \\* |
| 603 | (@<class> :object :end) & sod-class, :c |
| 604 | & \}; \\*\hlx{v} |
| 605 | % |
| 606 | (:classes :end) \\ \hlx{v/} |
| 607 | % |
| 608 | (:user :start) \\* |
| 609 | :user \\* |
| 610 | (:user :end) \\ \hlx{v/} |
| 611 | % |
| 612 | :epilogue & module, :c |
| 613 | & \banner{That's all, folks} \\ |
| 614 | \end{longtable} |
| 615 | \endgroup |
| 616 | |
| 617 | %%%-------------------------------------------------------------------------- |
| 618 | \section{Module output} \label{output.module} |
| 619 | |
| 620 | \subsection{Producing output} |
| 621 | |
| 622 | \begin{describe}{gf} |
| 623 | {module-output-file @<module> @<output-type> @<output-dir> |
| 624 | @> @<pathname>} |
| 625 | \begin{describe*} |
| 626 | {\dhead{meth}{module,symbol} |
| 627 | {module-output-file \=(@<module> module) \\ |
| 628 | \>(@<output-type> symbol) \\ |
| 629 | \>@<output-dir> |
| 630 | \nlret @<pathname>} |
| 631 | \dhead{meth}{module,pathname} |
| 632 | {module-output-file \=(@<module> module) \\ |
| 633 | \>(@<output-type> pathname) \\ |
| 634 | \>@<output-dir> |
| 635 | \nlret @<pathname>}} |
| 636 | \end{describe*} |
| 637 | \end{describe} |
| 638 | |
| 639 | \begin{describe}{gf}{write-dependency-file @<module> @<reason> @<output-dir>} |
| 640 | \end{describe} |
| 641 | |
| 642 | \begin{describe}{fun}{output-module @<module> @<reason> @<stream>} |
| 643 | \end{describe} |
| 644 | |
| 645 | |
| 646 | \subsection{Managing output types} \label{output.module.manage} |
| 647 | |
| 648 | \begin{describe}{fun}{declare-output-type @<reason> @<pathname>} |
| 649 | \end{describe} |
| 650 | |
| 651 | \begin{describe}{fun}{output-type-pathname @<reason> @> @<pathname>} |
| 652 | \end{describe} |
| 653 | |
| 654 | |
| 655 | \subsection{Utilities} \label{output.module.utilities} |
| 656 | |
| 657 | \begin{describe}{fun}{banner @<title> @<output> \&key :blank-line-p} |
| 658 | \end{describe} |
| 659 | |
| 660 | \begin{describe}{fun}{guard-name @<filename> @> @<string>} |
| 661 | \end{describe} |
| 662 | |
| 663 | \begin{describe}{fun} |
| 664 | {one-off-output @<token> @<sequencer> @<item-name> @<function>} |
| 665 | \end{describe} |
| 666 | |
| 667 | %%%-------------------------------------------------------------------------- |
| 668 | \section{Class output} \label{output.class} |
| 669 | |
| 670 | \begin{describe}{var}{*instance-class*} |
| 671 | \end{describe} |
| 672 | |
| 673 | \begin{describe}{gf}{emit-class-typedef @<class> @<stream>} |
| 674 | \end{describe} |
| 675 | |
| 676 | \begin{describe}{gf}{emit-class-object-decl @<class> @<stream>} |
| 677 | \end{describe} |
| 678 | |
| 679 | \begin{describe}{gf}{emit-class-conversion-macro @<class> @<super> @<stream>} |
| 680 | \end{describe} |
| 681 | |
| 682 | \begin{describe*} |
| 683 | {\dhead{gf}{emit-message-macro @<class> @<entry> @<stream>} |
| 684 | \dhead{gf}{emit-message-macro-defn |
| 685 | \=@<class> @<entry> @<varargsp> @<me> \\ |
| 686 | \>@<in-names> @<out-names> @<stream>}} |
| 687 | \end{describe*} |
| 688 | |
| 689 | %%%----- That's all, folks -------------------------------------------------- |
| 690 | |
| 691 | %%% Local variables: |
| 692 | %%% mode: LaTeX |
| 693 | %%% TeX-master: "sod.tex" |
| 694 | %%% TeX-PDF-mode: t |
| 695 | %%% End: |