doc/structures.tex: Remove spurious line breaks in the source.
[sod] / doc / structures.tex
1 %%% -*-latex-*-
2 %%%
3 %%% In-depth exploration of the generated structures
4 %%%
5 %%% (c) 2015 Straylight/Edgeware
6 %%%
7
8 %%%----- Licensing notice ---------------------------------------------------
9 %%%
10 %%% This file is part of the Simple Object Definition system.
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{Object structures} \label{ch:structures}
27
28 This chapter describes the structure and layout of standard Sod objects,
29 classes and associated metadata. Note that Sod's object system is very
30 flexible and it's possible for an extension to define a new root class which
31 works very differently from the standard @|SodObject| described here.
32
33 The concrete types described in \xref{sec:structures.common} and
34 \ref{sec:structures.root} are declared by the header file @|<sod/sod.h>|.
35 The definitions described in \xref{sec:structures.layout} are defined in the
36 header file generated by the containing module.
37
38 %%%--------------------------------------------------------------------------
39 \section{Common instance structure} \label{sec:structures.common}
40
41 As described below, a pointer to an instance actually points to an
42 \emph{instance chain} structure within the instances overall layout
43 structure.
44
45 Instance chains contain slots and vtable pointers, as described below. All
46 instances have the basic structure of a @|struct sod_instance|.
47
48 \begin{describe}[struct sod_instance]{type}
49 {struct sod_instance \{ \\ \ind
50 const struct sod_vtable *_vt; \-\\
51 \};}
52
53 The basic structure of all instances. Members are as follows.
54 \begin{description} \let\makelabel\code
55 \item[_vt] A pointer to a \emph{vtable}, which has the basic structure of a
56 @|struct sod_vtable|, described below.
57 \end{description}
58 \end{describe}
59
60 \begin{describe}[struct sod_vtable]{type}
61 {struct sod_vtable \{ \\ \ind
62 const SodClass *_class; \\
63 size_t _base; \-\\
64 \};}
65
66 A vtable contains static metadata needed for efficient conversions and
67 message dispatch, and pointers to the instance's class. Each chain points
68 to a different vtable. All vtables have the basic structure of a @|struct
69 sod_vtable|, which has the following members.
70 \begin{description} \let\makelabel\code
71 \item[_class] A pointer to the instance's class object.
72 \item[_base] The offset of this chain structure above the start of the
73 overall instance layout, in bytes. Subtracting @|_base| from the
74 instance chain pointer finds the layout base address.
75 \end{description}
76 \end{describe}
77
78 %%%--------------------------------------------------------------------------
79 \section{Built-in root objects} \label{sec:structures.root}
80
81 This section describes the built-in classes @|SodObject| and @|SodClass|,
82 which are the standard roots of the inheritance and metaclass graphs
83 respectively. Specifically, @|SodObject| has no direct superclasses, and
84 @|SodClass| is its own metaclass. It is not possible to define root classes
85 in module files because of circularities: @|SodObject| has @|SodClass| as its
86 metaclass, and @|SodClass| is a subclass of @|SodObject|. Extensions can
87 define additional root classes, but this is tricky, and not really to be
88 recommended.
89
90
91 \subsection{The SodObject class} \label{sec:structures.root.sodobject}
92
93 \begin{figure}[tbp]
94 \begin{tabular}{p{10pt}p{10pt}}
95 \begin{nprog}
96 struct SodObject__ilayout \{ \\ \ind
97 union \{ \\ \ind
98 struct SodObject__ichain_obj \{ \\ \ind
99 const struct SodObject__vt_obj *_vt; \-\\
100 \} obj; \-\\
101 \} obj; \-\\
102 \};
103 \end{nprog}
104 &
105 \begin{nprog}
106 struct SodObject__vt_obj \{ \\ \ind
107 const SodClass *_class; \\
108 size_t _base; \\
109 struct SodObject__vtmsgs_obj \{ \\ \ind
110 void (*init)(SodObject *me, ...); \\
111 void (*init__v)(SodObject *me, va_list); \\
112 int (*teardown)(SodObject *me); \-\\
113 \} obj; \-\\
114 \};
115 \end{nprog} \\
116 \end{tabular}
117 \caption{Instance and vtable layout of @|SodObject|}
118 \label{fig:structures.root.sodobject}
119 \end{figure}
120
121 \begin{describe}[SodObject]{cls}
122 {[nick = obj, metaclass = SodClass,
123 lisp_metaclass = sod_class] \\
124 class SodObject \{ \\ \ind
125 void init(?);
126 \}}
127
128 The @|SodObject| class defines no slots. Because @|SodObject| has no
129 direct superclasses, there is only one chain, and no inherited slots or
130 messages, so the single chain contains only a vtable pointer.
131
132 Since @|SodClass| also has only one chain, the vtable contains only the
133 standard class pointer and offset-to-base members. In a direct instance of
134 @|SodObject| (why would you want one?) the class pointer contains the
135 address of @|SodObject__class| and the offset is zero.
136
137 The instance and vtable layout of @|SodObject| is shown in
138 \xref{fig:structures.root.sodobject}.
139
140 The following messages are defined.
141
142 \begin{describe}[obj.init]{msg}{void init(?);}
143 Initialize a newly allocated instance.
144
145 This message uses a custom method combination which works like the
146 standard method combination except that default behaviour specific to the
147 receiver's direct class is invoked if no primary or around method
148 overrides. This default behaviour may be invoked multiple times if some
149 method calls on its @|next_method| function more than once.
150
151 This default behaviour is to initialize the instance's slots using the
152 defined slot initializers, and execute the initialization fragments.
153 Each slot is initialized using the most specific applicable initializer,
154 if any. Slots without an initializer are left uninitialized.
155
156 Slots are initialized and initialization fragments executed together, a
157 superclass at a time: first, the superclass's slots are initialized (if
158 any); then the superclass's initialization fragments (if any) are
159 executed, starting with the least specific superclass first. Slots and
160 initialization fragments defined by the same class are processed in the
161 order in which they appear in the class definition.
162
163 There are no standard keyword arguments; methods on subclasses are free
164 to introduce their own in the usual way.
165
166 It is usual to provide complex initialization behaviour as @|after|
167 methods. This ensures that slots have been initialized as necessary
168 before the method executes.
169
170 For more details on instance construction, see
171 \xref{sec:concepts.lifecycle.birth}.
172 \end{describe}
173
174 \begin{describe}[obj.teardown]{msg}{int teardown();}
175 Teardown an instance which is no longer required.
176
177 The message returns an integer flag. A zero value means that the
178 instance is safe to deallocate. A nonzero value means that the instance
179 should not be deallocated, and that it is safe for the caller to simply
180 forget about it. This simple protocol may be used, for example, to
181 implement a reference-counting system.
182
183 This message uses a custom method combination which works like the
184 standard method combination except that default behaviour is invoked if
185 no primary or around method overrides.
186
187 This default behaviour is to execute each superclass's teardown
188 fragments, most specific first, and then return zero to indicate that the
189 object is ready for deallocation. Teardown fragments defined by the same
190 class are processed in the order in which they appear in the class
191 definition.
192
193 It is usual to provide complex teardown behaviour as @|before| methods.
194 Logic to decide whether to allow deallocation is usually implemented as
195 @|around| methods.
196 \end{describe}
197 \end{describe}
198
199
200 \subsection{The SodClass class} \label{sec:structures.root.sodclass}
201
202 \begin{describe}[SodClass]{cls}
203 {[nick = cls, link = SodObject] \\
204 class SodClass : SodObject \{ \\ \ind
205 const char *name; \\
206 const char *nick; \\
207 size_t initsz; \\
208 size_t align; \\
209 void *(*imprint)(void *@<p>); \\
210 size_t n_supers; \\
211 const SodClass *const *supers; \\
212 size_t n_cpl; \\
213 const SodClass *const *cpl; \\
214 const SodClass *link; \\
215 const SodClass *head; \\
216 size_t level; \\
217 size_t n_chains; \\
218 const struct sod_chain *chains; \\
219 size_t off_islots; \\
220 size_t islotsz; \-\\
221 \}}
222
223 The @|SodClass| class defines no additional messages , but there are a
224 number of slots. Its only direct superclass is @|SodObject| and so (like
225 its superclass) its vtable is simple.
226
227 The slots defined are as follows.
228 \begin{description} \let\makelabel\code
229
230 \item[name] A pointer to the class's name.
231
232 \item[nick] A pointer to the class's nickname.
233
234 \item[initsz] The size in bytes required to store an instance of the class.
235
236 \item[align] A sufficient alignment for the class's instance storage.
237
238 \item[imprint] A pointer to a function: given a pointer @<p> to at least
239 @<initsz> bytes of appropriately aligned memory, `imprint' this memory it
240 so that it becomes a minimally functional instance of the class: all of
241 the vtable and class pointers are properly initialized, but the slots are
242 left untouched. The function returns its argument @<p>.
243
244 \item[n_supers] The number of direct superclasses. (This is zero exactly
245 in the case of @|SodObject|.)
246
247 \item[supers] A pointer to an array of @<n_supers> pointers to class
248 objects listing the class's direct superclasses, in the order in which
249 they were listed in the class definition. If @<n_supers> is zero, then
250 this pointer is null.
251
252 \item[n_cpl] The number of superclasses in the class's class precedence
253 list.
254
255 \item[cpl] A pointer to an array of pointers to class objects listing all
256 of the class's superclasses, from most- to least-specific, starting with
257 the class itself, so $@|$c$@->cls.cpl[0]| = c$ for all class objects
258 $c$.
259
260 \item[link] If the class is a chain head, then this is a null pointer;
261 otherwise it points to the class's distinguished link superclass (which
262 might or might not be a direct superclass).
263
264 \item[head] A pointer to the least-specific class in this class's chain; so
265 @|$c$@->cls.head@->cls.link| is always null, and either @|$c$@->cls.link|
266 is null (in which case $@|$c$@->cls.head| = c$) or $@|$c$@->cls.head| =
267 @|$c$@->cls.link@->cls.head|$.
268
269 \item[level] The number of less specific superclasses in this class's
270 chain. If @|$c$@->cls.link| is null then @|$c$@->cls.level| is zero;
271 otherwise $@|$c$@->cls.level| = @|$c$@->cls.link@->cls.level| + 1$.
272
273 \item[n_chains] The number of chains formed by the class's superclasses.
274
275 \item[chains] A pointer to an array of @|struct sod_chain| structures (see
276 below) describing the class's superclass chains, in decreasing order of
277 specificity of their most specific classes. It is always the case that
278 $@|$c$@->cls.chains[0].classes[$c$@->cls.level]| = c$.
279
280 \item[off_islots] The offset of the class's @|islots| structure relative to
281 its containing @|ichain| structure. The class doesn't define any slots
282 if and only if this is zero. (The offset can't be zero because the
283 vtable pointer is at offset zero.)
284
285 \item[islotsz] The size required to store the class's direct slots, i.e.,
286 the size of its @|islots| structure. The class doesn't define any slots
287 if and only if this is zero.
288
289 \end{description}
290 \end{describe}
291
292 \begin{describe}[struct sod_chain]{type}
293 {struct sod_chain \{ \\ \ind
294 size_t n_classes; \\
295 const SodClass *const *classes; \\
296 size_t off_ichain; \\
297 const struct sod_vtable *vt; \\
298 size_t ichainsz; \-\\
299 \};}
300
301 The @|struct sod_chain| structure describes an individual chain of
302 superclasses. It has the following members.
303 \begin{description} \let\makelabel\code
304
305 \item[n_classes] The number of classes in the chain. This is always at
306 least one.
307
308 \item[classes] A pointer to an array of class pointers listing the classes
309 in the chain from least- to most-specific. So
310 $@|@<classes>[$i$]@->cls.head| = @|@<classes>[0]|$ for all $0 \le i <
311 @<n_classes>$, @|@<classes>[0]@->cls.link| is always null, and
312 $@|@<classes>[$i$]@->cls.link| = @|@<classes>[$i - 1$]|$ if $1 \le i <
313 @<n_classes>$.
314
315 \item[off_ichain] The size of the @|ichain| structure for this chain.
316
317 \item[vt] The vtable for this chain. (It is possible, therefore, to
318 partially duplicate the behaviour of the @<imprint> function by walking
319 the chain structure.\footnote{%
320 There isn't enough information readily available to fill in the class
321 pointers correctly.} %
322 The @<imprint> function is much faster, though.)
323
324 \item[ichainsz] The size of the @|ichain| structure for this chain.
325
326 \end{description}
327 \end{describe}
328
329 %%%--------------------------------------------------------------------------
330 \section{Class and vtable layout} \label{sec:structures.layout}
331
332 The layout algorithms for Sod instances and vtables are nontrivial. They are
333 defined here in full detail, since they're effectively fixed by Sod's ABI
334 compatibility guarantees, so they might as well be documented for the sake of
335 interoperating programs.
336
337 Unfortunately, the descriptions are rather complicated, and, for the most
338 part not necessary to a working understanding of Sod. The skeleton structure
339 definitions shown should be more than enough for readers attempting to make
340 sense of the generated headers and tables.
341
342 In the description that follows, uppercase letters vary over class names,
343 while the corresponding lowercase letters indicate the class nicknames.
344 Throughout, we consider a class $C$ (therefore with nickname $c$).
345
346
347 \subsection{Generic instance structure}
348 \label{sec:structures.layout.instance}
349
350 The entire state of an instance of $C$ is contained in a single structure of
351 type @|struct $C$__ilayout|.
352
353 \begin{prog}
354 struct $C$__ilayout \{ \\ \ind
355 union $C$__ichainu_$h$ \{ \\ \ind
356 struct $C$__ichain_$h$ \{ \\ \ind
357 const struct $C$__vt_$h$ *_vt; \\
358 struct $H$__islots $h$; \\
359 \quad$\vdots$ \\
360 struct $C$__islots \{ \\ \ind
361 @<type>_1 @<slot>_1; \\
362 \quad$\vdots$ \\
363 @<type>_n @<slot>_n; \-\\
364 \} $c$; \-\\
365 \} $c$; \\
366 struct $H$__ichain_$h$ $h$; \\
367 \quad$\vdots$ \-\\
368 \} $h$; \\
369 union $B$__ichainu_$i$ $i$; \\
370 \quad$\vdots$ \-\\
371 \}; \\+
372
373 typedef struct $C$__ichain_$h$ $C$;
374 \end{prog}
375
376 The set of superclasses of $C$, including itself, can be partitioned into
377 chains by following their distinguished superclass links. (Formally, the
378 chains are the equivalence classes determined by the reflexive, symmetric,
379 transitive closure of the `links to' relation.) Chains are identified by
380 naming their least specific classes; the least specific class in a chain is
381 called the \emph{chain head}. Suppose that the chain head of the chain
382 containing $C$ itself is named $H$ (though keep in mind that it's possible
383 that $H$ is in fact $C$ itself.)
384
385 \subsubsection{The ilayout structure}
386 The @|ilayout| structure contains one member for each of $C$'s superclass
387 chains. The first such member is
388 \begin{prog}
389 union $C$__ichainu_$h$ $h$;
390 \end{prog}
391 described below; this is followed by members
392 \begin{prog}
393 union $B$__ichainu_$i$ $i$;
394 \end{prog}
395 for each other chain, where $I$ is the head and $B$ the tail (most-specific)
396 class of the chain. The members are in decreasing order of the specificity
397 of the chains' most-specific classes. (Note that all but the first of these
398 unions has already been defined as part of the definition of the
399 corresponding $B$.)
400
401 \subsubsection{The ichainu union}
402 The @|ichainu| union contains a member for each class in the chain. The
403 first is
404 \begin{prog}
405 struct $C$__ichain_$h$ $c$;
406 \end{prog}
407 and this is followed by corresponding members
408 \begin{prog}
409 struct $A$__ichain_$h$ $a$;
410 \end{prog}
411 for each of $C$'s superclasses $A$ in the same chain in some (unimportant)
412 order.
413
414 \subsubsection{The ichain structure}
415 The @|ichain| structure contains (in order), a pointer
416 \begin{prog}
417 const struct $C$__vt_$h$ *_vt;
418 \end{prog}
419 followed by a structure
420 \begin{prog}
421 struct $A$__islots $a$;
422 \end{prog}
423 for each superclass $A$ of $C$ in the same chain which defines slots, from
424 least- to most-specific; if $C$ defines any slots, then the last member is
425 \begin{prog}
426 struct $C$__islots $c$;
427 \end{prog}
428 A `pointer to $C$' is always assumed (and, indeed, defined in C's
429 type system) to be a pointer to the @|struct $C$__ichain_$h$|.
430
431 \subsubsection{The islots structure}
432 Finally, the @|islots| structure simply contains one member for each slot
433 defined by $C$ in the order they appear in the class definition.
434
435
436 \subsection{Generic vtable structure} \label{sec:structures.layout.vtable}
437
438 As described above, each @|ichain| structure of an instance's storage has a
439 vtable pointer
440 \begin{prog}
441 const struct $C$__vt_$h$ *_vt;
442 \end{prog}
443 In general, the vtables for the different chains will have \emph{different}
444 structures.
445
446 The instance layout split neatly into disjoint chains. This is necessary
447 because each @|ichain| must have as a prefix the @|ichain| for each
448 superclass in the same chain, and each slot must be stored in exactly one
449 place. The layout of vtables doesn't have this second requirement: it
450 doesn't matter that there are multiple method entry pointers for the same
451 effective method as long as they all work correctly. Indeed, it's essential
452 that they do, because each chain's method entry function will need to apply a
453 different offset to the receiver pointer before invoking the effective
454 method.
455
456 A vtable for a class $C$ with chain head $H$ has the following general
457 structure.
458 \begin{prog}
459 union $C$__vtu_$h$ \{ \\ \ind
460 struct $C$__vt_$h$ \{ \\ \ind
461 const $P$ *_class; \\
462 size_t _base; \\
463 \quad$\vdots$ \\
464 const $Q$ *_cls_$j$; \\
465 \quad$\vdots$ \\
466 ptrdiff_t _off_$i$; \\
467 \quad$\vdots$ \\
468 struct $C$__vtmsgs_$a$ \{ \\ \ind
469 @<type> (*@<msg>)($C$ *, $\dots$); \\
470 \quad$\vdots$ \-\\
471 \} $a$; \\
472 \quad$\vdots$ \-\\
473 \} $c$; \-\\
474 \}; \\+
475
476 extern const union $C$__vtu_$h$ $C$__vtable_$h$;
477 \end{prog}
478
479 In the following, let $M$ be the metaclass of $C$.
480
481 \subsubsection{The vtu union}
482 The outer layer is a @|union $C$__vtu_$h$| containing a member
483 \begin{prog}
484 struct $A$__vt_$h$ $a$;
485 \end{prog}
486 for each of $C$'s superclasses $A$ in the same chain, with $C$ itself listed
487 first.
488
489 This is mostly an irrelevant detail, whose purpose is to defend against
490 malicious compilers: pointers are always to one of the inner @|vt|
491 structures. It's important only because it's the outer @|vtu| union which is
492 exported by name. Specifically, for each chain of $C$'s superclasses there is
493 an external object
494 \begin{prog}
495 const union $A$__vtu_$i$ $C$__vtable_$i$;
496 \end{prog}
497 where $A$ and $I$ are respectively the most and least specific classes in the
498 chain.
499
500 \subsubsection{The vt structure}
501 The first member in the @|vt| structure is the \emph{root class pointer}
502 \begin{prog}
503 const $P$ *_class;
504 \end{prog}
505 Among the superclasses of $C$ there must be exactly one class $O$ which
506 itself has no direct superclasses; this is the \emph{root superclass} of $C$.
507 (This is a rule enforced by the Sod translator.) The metaclass $R$ of $O$ is
508 then the \emph{root metaclass} of $C$. The @|_class| member points to the
509 @|ichain| structure of most specific superclass $P$ of $M$ in the same chain
510 as $R$.
511
512 This is followed by the \emph{base offset}
513 \begin{prog}
514 size_t _base;
515 \end{prog}
516 which is simply the offset of the @|ichain| structure from the instance base.
517
518 The rest of the vtable structure is populated by walking the superclass chain
519 containing $C$ as follows. For each such superclass $B$, in increasing order
520 of specificity, walk the class precedence list of $B$, again starting with
521 its least-specific superclass. (This complex procedure guarantees that the
522 vtable structure for a class is a prefix of the vtable structure for any of
523 its subclasses in the same chain.)
524
525 So, let $A$ be some superclass of $C$ which has been encountered during this
526 traversal.
527
528 \begin{itemize}
529
530 \item Let $N$ be the metaclass of $A$. Examine the superclass chains of $N$
531 in order of decreasing specificity of their most-specific classes. Let $J$
532 be the chain head of such a chain, and let $Q$ be the most specific
533 superclass of $M$ in the same chain as $J$. Then, if there is currently no
534 class pointer of type $Q$, then add a member
535 \begin{prog}
536 const $Q$ *_cls_$j$;
537 \end{prog}
538 to the vtable pointing to the appropriate @|islots| structure within $M$'s
539 class object.
540
541 \item Examine the superclass chains of $A$ in order of decreasing specificity
542 of their most-specific classes. Let $I$ be the chain head of such a chain.
543 If there is currently no member @|_off_$i$| then add a member
544 \begin{prog}
545 ptrdiff_t _off_$i$;
546 \end{prog}
547 to the vtable, containing the (signed) offset from the @|ichain| structure
548 of the chain headed by $h$ to that of the chain headed by $i$ within the
549 instance's layout.
550
551 \item If class $A$ defines any messages, and there is currently no member
552 $a$, then add a member
553 \begin{prog}
554 struct $C$__vtmsgs_$a$ $a$;
555 \end{prog}
556 to the vtable. See below.
557
558 \end{itemize}
559
560 \subsubsection{The vtmsgs structure}
561 Finally, the @|vtmsgs| structures contain pointers to the effective method
562 entry functions for the messages defined by a superclass. There may be more
563 than one method entry for a message, but all of the entry pointers for a
564 message appear together, and entry pointers for separate messages appear in
565 the order in which the messages are defined. If the receiver class has no
566 applicable primary method for a message then it's usual for the method entry
567 pointer to be null (though, as with a lot of things in Sod, extensions may do
568 something different).
569
570 For a standard message which takes a fixed number of arguments, defined as
571 \begin{prog}
572 @<type>_0 $m$(@<type>_1 @<arg>_1, $\ldots$, @<type>_n @<arg>_n);
573 \end{prog}
574 there is always a `main' entry point,
575 \begin{prog}
576 @<type>_0 $m$($C$ *me, @<type>_1 @<arg>_1, $\ldots$, @<type>_n @<arg>_n);
577 \end{prog}
578
579 For a standard message which takes a variable number of arguments,
580 defined as
581 \begin{prog}
582 @<type>_0 $m$(@<type>_1 @<arg>_1, $\ldots$, @<type>_n @<arg>_n, \dots);
583 \end{prog}
584 or a standard message which takes keyword arguments, defined as
585 \begin{prog}
586 @<type>_0 $m$(\=@<type>_1 @<arg>_1,
587 $\ldots$,
588 @<type>_n @<arg>_n? \+\\
589 @<type>_{n+1} @<kw>_{n+1} @[= @<dflt>_{n+1}@],
590 $\ldots$,
591 @<type>_m @<kw>_m @[= @<dflt>_m@]);
592 \end{prog}
593 two entry points are defined: the usual `main' entry point which accepts a
594 variable number of arguments, and a `valist' entry point which accepts an
595 argument of type @|va_list| in place of the variable portion of the argument
596 list or keywords.
597 \begin{prog}
598 @<type>_0 $m$($C$ *me, @<type>_1 @<arg>_1, $\ldots$,
599 @<type>_n @<arg>_n, \dots); \\
600 @<type>_0 $m$__v($C$ *me, @<type>_1 @<arg>_1, $\ldots$,
601 @<type>_n @<arg>_n, va_list sod__ap);
602 \end{prog}
603
604
605 \subsection{Additional definitions} \label{sec:structures.layout.additional}
606
607 In addition to the instance and vtable structures described above, the
608 following definitions are made for each class $C$.
609
610 For each message $m$ directly defined by $C$ there is a macro definition
611 \begin{prog}
612 \#define $C$_$m$(@<me>, $\ldots$) @<me>@->_vt@->$c$.$m$(@<me>, $\ldots$)
613 \end{prog}
614 which makes sending the message $m$ to an instance of (any subclass of) $C$
615 somewhat less ugly.
616
617 If $m$ takes a variable number of arguments, or keyword arguments, the macro
618 is more complicated and is only available in compilers advertising C99
619 support, but the effect is the same. For each variable-argument message,
620 there is also an additional macro for calling the `valist' entry point.
621 \begin{prog}
622 \#define $C$_$m$__v(@<me>, $\ldots$, @<sod__ap>)
623 @<me>@->_vt@->$c$.$m$__v(@<me>, $\ldots$, @<sod__ap>)
624 \end{prog}
625
626 For each proper superclass $A$ of $C$, there is a macro defined
627 \begin{prog}
628 $A$ *$C$__CONV_$a$($C$ *_obj);
629 \end{prog}
630 (named in \emph{upper case}) which converts a (static-type) pointer to $C$ to
631 a pointer to the same actual instance, but statically typed as a pointer to
632 $A$. This is most useful when $A$ is not in the same chain as $C$ since
633 in-chain upcasts are both trivial and rarely needed, but the full set is
634 defined for the sake of completeness.
635
636 Finally, the class object is defined as
637 \begin{prog}
638 extern const struct $R$__ilayout $C$__classobj; \\
639 \#define $C$__class (\&$C$__classobj.$j$.$r$)
640 \end{prog}
641 The exported symbol @|$C$__classobj| contains the entire class instance.
642 This is usually rather unwieldy. The macro @|$C$__class| is usable as a
643 pointer of type @|const $R$~*|, where $R$ is the root metaclass of $C$, i.e.,
644 the metaclass of the least specific superclass of $C$; usually this is
645 @|const SodClass~*|.
646
647 %%%----- That's all, folks --------------------------------------------------
648
649 %%% Local variables:
650 %%% mode: LaTeX
651 %%% TeX-master: "sod.tex"
652 %%% TeX-PDF-mode: t
653 %%% End: