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