chiark / gitweb /
a6c9db2452375dce0c57cfccb78b8c8f5c39793d
[sod] / lib / sod-structs.3
1 .\" -*-nroff-*-
2 .\"
3 .\" Description of the main Sod data structures
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 Library General Public License as
14 .\" published by the Free Software Foundation; either version 2 of the
15 .\" License, or (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 Library General Public License for more details.
21 .\"
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with SOD; if not, write to the Free
24 .\" Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 .\" MA 02111-1307, USA.
26 .
27 .\" Highlight using terminal escapes, rather than overstriking.
28 .\"\X'tty: sgr 1'
29 .
30 .\" String definitions and font selection.
31 .ie t \{\
32 .  ds o \(bu
33 .  if \n(.g .fam P
34 .\}
35 .el \{\
36 .  ds o o
37 .\}
38 .
39 .\" .hP TEXT -- start an indented paragraph with TEXT hanging off to the left
40 .de hP
41 .IP
42 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
43 ..
44 .
45 .\"--------------------------------------------------------------------------
46 .TH sod-structs 3 "8 September 2015" "Straylight/Edgeware" "Sensible Object Design"
47 .
48 .SH NAME
49 sod-structs \- main Sod data structures
50 .
51 .\"--------------------------------------------------------------------------
52 .SH SYNOPSIS
53 .nf
54 .ft B
55 #include <sod/sod.h>
56
57 typedef struct SodObject__ichain_obj SodObject;
58 typedef struct SodClass__ichain_obj SodClass;
59
60 struct sod_instance {
61 \h'2n'const struct sod_vtable *_vt;
62 };
63
64 struct sod_vtable {
65 \h'2n'const SodClass *_class;
66 \h'2n'size_t _base;
67 };
68
69 struct SodObject__vt_obj {
70 \h'2n'const SodClass *_class;
71 \h'2n'size_t _base;
72 };
73
74 struct SodObject__ilayout {
75 \h'2n'union {
76 \h'4n'struct SodObject__ichain_obj {
77 \h'6n'const struct SodObject__vt_obj *_vt;
78 \h'4n'};
79 \h'2n'} obj;
80 };
81
82 extern const struct SodClass__ilayout SodObject__classobj;
83 #define SodObject__class (&SodObject__classobj.obj.cls)
84
85 struct SodClass__vt_obj {
86 \h'2n'const SodClass *_class;
87 \h'2n'size_t _base;
88 };
89
90 struct SodObject__ilayout {
91 \h'2n'union {
92 \h'4n'struct SodClass__ichain_obj {
93 \h'6n'const struct SodClass__vt_obj *_vt;
94 \h'6n'struct SodClass__islots {
95 \h'8n'const char *name;
96 \h'8n'const char *nick;
97 \h'8n'size_t initsz;
98 \h'8n'void *(*imprint)(void *\fIp\fB);
99 \h'8n'void *(*init)(void *\fIp\fB);
100 \h'8n'size_t n_supers;
101 \h'8n'const SodClass *const *supers;
102 \h'8n'size_t n_cpl;
103 \h'8n'const SodClass *const *cpl;
104 \h'8n'const SodClass *link;
105 \h'8n'const SodClass *head;
106 \h'8n'size_t level;
107 \h'8n'size_t n_chains;
108 \h'8n'const struct sod_chain *chains;
109 \h'8n'size_t off_islots;
110 \h'8n'size_t islotsz;
111 \h'6n'} cls;
112 \h'4n'};
113 \h'4n'SodObject obj;
114 \h'2n'} obj;
115 };
116
117 struct sod_chain {
118 \h'2n'size_t n_classes;
119 \h'2n'const SodClass *const *classes;
120 \h'2n'size_t off_ichain;
121 \h'2n'const struct sod_vtable *vt;
122 \h'2n'size_t ichainsz;
123 };
124
125 extern const struct SodClass__ilayout SodClass__classobj;
126 #define SodClass__class (&SodClass__classobj.obj.cls)
127 .fi
128 .ft P
129 .
130 .\"--------------------------------------------------------------------------
131 .SH DESCRIPTION
132 .
133 This page describes the structure and layout
134 of standard Sod objects, classes and associated metadata.
135 Note that Sod's object system is very flexible
136 and it's possible for an extension
137 to define a new root class
138 which works very differently from the standard
139 .B SodObject
140 described here.
141 .
142 .\"--------------------------------------------------------------------------
143 .SH COMMON INSTANCE STRUCTURE
144 .
145 As described below,
146 a pointer to an instance actually points to an
147 .I "instance chain"
148 structure within the instances overall layout structure.
149 .PP
150 Instance chains contain slots and vtable pointers,
151 as described below.
152 All instances have the basic structure of a
153 .BR "struct sod_instance" ,
154 which has the following members.
155 .TP
156 .B "const struct sod_vtable *_vt"
157 A pointer to a
158 .IR vtable ,
159 which has the basic structure of a
160 .BR "struct sod_vtable" ,
161 described below.
162 .PP
163 A vtable contains static metadata needed
164 for efficient conversions and
165 message dispatch,
166 and pointers to the instance's class.
167 Each chain points to a different vtable
168 All vtables have the basic structure of a
169 .BR "struct sod_vtable" ,
170 which has the following members.
171 .TP
172 .B "const SodClass *_class"
173 A pointer to the instance's class object.
174 .TP
175 .B "size_t _base;"
176 The offset of this chain structure
177 above the start of the overall instance layout, in bytes.
178 Subtracting
179 .B _base
180 from the instance chain pointer
181 finds the layout base address.
182 .
183 .\"--------------------------------------------------------------------------
184 .SH BUILT-IN ROOT OBJECTS
185 .
186 This section describes the built-in classes
187 .B SodObject
188 and
189 .BR SodClass ,
190 which are the standard roots of the inheritance and metaclass graphs
191 respectively.
192 Specifically,
193 .B SodObject
194 has no direct superclasses,
195 and
196 .B SodClass
197 is its own metaclass.
198 It is not possible to define root classes in module files
199 because of circularities:
200 .B SodObject
201 has
202 .B SodClass
203 as its metaclass,
204 and
205 .B SodClass
206 is a subclass of
207 .BR SodObject .
208 Extensions can define additional root classes,
209 but this is tricky,
210 and not really to be recommended.
211 .
212 .SS The SodObject class
213 The
214 .B SodObject
215 class defines no slots or messages.
216 Because
217 .B SodObject
218 has no direct superclasses,
219 there is only one chain,
220 and no inherited slots or messages,
221 so the single chain contains only a vtable pointer.
222 .PP
223 Since there are no messages,
224 and
225 .B SodClass
226 also has only one chain,
227 the vtable contains only the standard class pointer and offset-to-base
228 members.
229 In an actual instance of
230 .B SodObject
231 (why would you want one?)
232 the class pointer contains the address of
233 .B SodObject__class
234 and the offset is zero.
235 .
236 .SS The SodClass class
237 The
238 .B SodClass
239 class defines no messages,
240 but there are a number of slots.
241 Its only direct superclass is
242 .B SodObject
243 and so (like its superclass) its vtable is trivial.
244 .PP
245 The slots defined are as follows.
246 .TP
247 .B const char *name;
248 A pointer to the class's name.
249 .TP
250 .B const char *nick;
251 A pointer to the class's nickname.
252 .TP
253 .B size_t initsz;
254 The size in bytes required to store an instance of the class.
255 .TP
256 .BI "void *(*imprint)(void *" p );
257 A pointer to a function:
258 given a pointer
259 .I p
260 to at least
261 .I initsz
262 bytes of appropriately aligned memory,
263 `imprint' this memory it so that it becomes a minimally functional
264 instance of the class:
265 all of the vtable and class pointers are properly initialized,
266 but the slots are left untouched.
267 The function returns its argument
268 .IR p .
269 .TP
270 .BI "void *(*init)(void *" p );
271 A pointer to a function:
272 given a pointer
273 .I p
274 to at least
275 .I initsz
276 bytes of appropriately aligned memory,
277 initialize an instance of the class in it:
278 all of the vtable and class pointers are initialized,
279 as are slots for which initializers are defined.
280 Other slots are left untouched.
281 The function returns its argument
282 .IR p .
283 .TP
284 .B size_t n_supers;
285 The number of direct superclasses.
286 (This is zero exactly in the case of
287 .BR SodObject .)
288 .TP
289 .B const SodClass *const *supers;
290 A pointer to an array of
291 .I n_supers
292 pointers to class objects
293 listing the class's direct superclasses,
294 in the order in which they were listed in the class definition.
295 If
296 .I n_supers
297 is zero,
298 then this pointer is null.
299 .TP
300 .B size_t n_cpl;
301 The number of superclasses in the class's class precedence list.
302 .TP
303 .B const SodClass *const *cpl;
304 A pointer to an array of pointers to class objects
305 listing all of the class's superclasses,
306 from most- to least-specific,
307 starting with the class itself,
308 so
309 .IB c ->cls.cpl[0]
310 =
311 .I c
312 for all class objects
313 .IR c .
314 .TP
315 .B const SodClass *link;
316 If the class is a chain head, then this is a null pointer;
317 otherwise it points to the class's distinguished link superclass
318 (which might or might not be a direct superclass).
319 .TP
320 .B const SodClass *head;
321 A pointer to the least-specific class in this class's chain;
322 so
323 .IB c ->cls.head->cls.link
324 is always null,
325 and either
326 .IB c ->cls.link
327 is null
328 (in which case
329 .IB c ->cls.head
330 =
331 .IR c )
332 or
333 .IB c ->cls.head
334 =
335 .IB c ->cls.link->cls.head \fR.
336 .TP
337 .B size_t level;
338 The number of less specific superclasses in this class's chain.
339 If
340 .IB c ->cls.link
341 is null then
342 .IB c ->cls.level
343 is zero;
344 otherwise
345 .IB c ->cls.level
346 =
347 .IB c ->cls.link->cls.level
348 + 1.
349 .TP
350 .B size_t n_chains;
351 The number of chains formed by the class's superclasses.
352 .TP
353 .B const struct sod_chain *chains;
354 A pointer to an array of
355 .B struct sod_chain
356 structures (see below) describing the class's superclass chains,
357 in decreasing order of specificity of their most specific classes.
358 It is always the case that
359 .IB c ->cls.chains[0].classes[ c ->cls.level]
360 =
361 .IR c .
362 .TP
363 .B size_t off_islots;
364 The offset of the class's
365 .B islots
366 structure relative to its containing
367 .B ichain
368 structure.
369 The class doesn't define any slots if and only if this is zero.
370 (The offset can't be zero because the vtable pointer is at offset zero.)
371 .TP
372 .B size_t islotsz;
373 The size required to store the class's direct slots,
374 i.e., the size of its
375 .B islots
376 structure.
377 The class doesn't define any slots if and only if this is zero.
378 .PP
379 The
380 .B struct sod_chain
381 structure describes an individual chain of superclasses.
382 It has the following members.
383 .TP
384 .B size_t n_classes;
385 The number of classes in the chain.
386 This is always at least one.
387 .TP
388 .B const SodClass *const *classes;
389 A pointer to an array of class pointers
390 listing the classes in the chain from least- to most-specific.
391 So
392 .IB classes [ i ]->cls.head
393 =
394 .IB classes [0]
395 for all
396 0 \(<=
397 .I i
398 <
399 .IR n_classes ,
400 .IB classes [0]->cls.link
401 is always null,
402 and
403 .IB classes [ i ]->cls.link
404 =
405 .IB classes [ "i\fR \- 1" ]
406 if
407 1 \(<=
408 .I i
409 <
410 .IR n_classes .
411 .TP
412 .B size_t off_ichain;
413 The size of the
414 .B ichain
415 structure for this chain.
416 .TP
417 .B const struct sod_vtable *vt;
418 The vtable for this chain.
419 (It is possible, therefore, to duplicate the behaviour of the
420 .I imprint
421 function by walking the chain structure.
422 The
423 .I imprint
424 function is much faster, though.)
425 .TP
426 .B size_t ichainsz;
427 The size of the
428 .B ichain
429 structure for this chain.
430 .
431 .\"--------------------------------------------------------------------------
432 .SH CLASS AND VTABLE LAYOUT
433 .
434 The layout algorithms for Sod instances and vtables are nontrivial.
435 They are defined here in full detail,
436 since they're effectively fixed by Sod's ABI compatibility guarantees,
437 so they might as well be documented for the sake of interoperating
438 programs.
439 .PP
440 Unfortunately, the descriptions are rather complicated,
441 and, for the most part not necessary to a working understanding of Sod.
442 The skeleton structure definitions shown should be more than enough
443 for readers attempting to make sense of the generated headers and tables.
444 .PP
445 In the description that follows,
446 uppercase letters vary over class names,
447 while the corresponding lowercase letters indicate the class nicknames.
448 Throughout, we consider a class
449 .I C
450 (therefore with nickname
451 .IR c ).
452 .
453 .SS Generic instance structure
454 The entire state of an instance of
455 .I C
456 is contained in a single structure of type
457 .B struct
458 .IB C __ilayout \fR.
459 .IP
460 .nf
461 .ft B
462 struct \fIC\fB__ilayout {
463 \h'2n'union \fIC\fB__ichainu_\fIh\fB {
464 \h'4n'struct \fIC\fB__ichain_\fIh\fB {
465 \h'6n'const struct \fIC\fB__vt_\fIh\fB *_vt;
466 \h'6n'struct \fIH\fB__islots \fIh\fB;
467 \h'6n'\fR...\fB
468 \h'6n'struct \fIC\fB__islots {
469 \h'8n'\fItype\fB \fIslota\fB;
470 \h'8n'\fR...\fB
471 \h'6n'} \fIc\fB;
472 \h'4n'} \fIc\fB;
473 \h'4n'\fR...\fB
474 \h'4n'struct \fIH\fB__ichain_\fIh\fB \fIh\fB;
475 \h'2n'} \fIh\fB;
476 \h'2n'union \fIB\fB__ichainu_\fIi\fB \fIi\fB;
477 \h'2n'\fR...\fB
478 };
479
480 typedef struct \fIC\fB__ichain_\fIh\fB \fIC\fB;
481 .ft P
482 .fi
483 .PP
484 The set of superclasses of
485 .IR C ,
486 including itself,
487 can be partitioned into chains
488 by following their distinguished superclass links.
489 (Formally, the chains are the equivalence classes determined by
490 the reflexive, symmetric, transitive closure of
491 the `links to' relation.)
492 Chains are identified by naming their least specific classes;
493 the least specific class in a chain is called the
494 .IR "chain head" .
495 Suppose that the chain head of the chain containing
496 .I C
497 itself is named
498 .I H
499 (though keep in mind that it's possible that
500 .I H
501 is in fact
502 .I C
503 itself.)
504 .PP
505 The
506 .B ilayout
507 structure contains one member for each of
508 .IR C 's
509 superclass chains.
510 The first such member is
511 .IP
512 .B
513 .B union
514 .IB C __ichainu_ h 
515 .IB h ;
516 .PP
517 described below;
518 this is followed by members
519 .IP
520 .B union
521 .IB B __ichainu_ i 
522 .IB i ;
523 .PP
524 for each other chain,
525 where
526 .I I
527 is the head
528 and
529 .I B
530 the tail (most-specific) class of the chain.
531 The members are in decreasing order
532 of the specificity of the chains' most-specific classes.
533 (Note that all but the first of these unions
534 has already been defined as part of
535 the definition of the corresponding
536 .IR B .)
537 .PP
538 The
539 .B ichainu
540 union contains a member for each class in the chain.
541 The first is
542 .IP
543 .B struct
544 .IB C __ichain_ h 
545 .IB c ;
546 .PP
547 and this is followed by corresponding members
548 .IP
549 .B struct
550 .IB A __ichain_ h 
551 .IB a ;
552 .PP
553 for each of
554 .IR C 's
555 superclasses
556 .IR A
557 in the same chain in some (unimportant) order.
558 A `pointer to
559 .IR C '
560 is always assumed
561 (and, indeed, defined in C's type system)
562 to be a pointer to the
563 .B struct
564 .IB C __ichain_ h \fR.
565 .PP
566 The
567 .B ichain
568 structure contains (in order), a pointer
569 .IP
570 .B const
571 .B struct
572 .IB C __vt_ h
573 .B *_vt;
574 .PP
575 followed by a structure
576 .IP
577 .B struct
578 .IB A __islots
579 .IB a ;
580 .PP
581 for each superclass
582 .I A
583 of
584 .IR C
585 in the same chain which defines slots,
586 from least- to most-specific;
587 if
588 .I C
589 defines any slots,
590 then the last member is
591 .IP
592 .B struct
593 .IB C __islots 
594 .IB c ;
595 .PP
596 Finally, the
597 .B islots
598 structure simply contains one member for each slot defined by
599 .I C
600 in the order they appear in the class definition.
601 .
602 .SS Generic vtable structure
603 As described above,
604 each
605 .B ichain
606 structure of an instance's storage
607 has a vtable pointer
608 .IP
609 .B const
610 .B struct
611 .IB C __vt_ h
612 .B *_vt;
613 .PP
614 In general,
615 the vtables for the different chains
616 will have
617 .I different
618 structures.
619 .PP
620 The instance layout split neatly into disjoint chains.
621 This is necessary because
622 each
623 .B ichain
624 must have as a prefix the
625 .B ichain
626 for each superclass in the same chain,
627 and each slot must be stored in exactly one place.
628 The layout of vtables doesn't have this second requirement:
629 it doesn't matter that there are
630 multiple method entry pointers
631 for the same effective method
632 as long as they all work correctly.
633 Indeed, it's essential that they do,
634 because each chain's method entry function
635 will need to apply a different offset to the receiver pointer
636 before invoking the effective method.
637 .PP
638 A vtable for a class
639 .I C
640 with chain head
641 .I H
642 has the following general structure.
643 .IP
644 .nf
645 .ft B
646 union \fIC\fB__vtu_\fIh\fB {
647 \h'2n'struct \fIC\fB__vt_\fIh\fB {
648 \h'4n'const \fIP\fB *_class;
649 \h'4n'size_t _base;
650 \h'4n'\fR...\fB
651 \h'4n'const \fIQ\fB *_cls_\fIj\fB;
652 \h'4n'\fR...\fB
653 \h'4n'ptrdiff_t _off_\fIi\fB;
654 \h'4n'\fR...\fB
655 \h'4n'struct \fIC\fB__vtmsgs_\fIa\fB {
656 \h'6n'\fItype\fB (*\fImsg\fB)(\fIC\fB *, \fR...\fB);
657 \h'6n'\fR...\fB
658 \h'4n'} \fIa\fB;
659 \h'4n'\fR...\fB
660 \h'2n'} \fIc\fB;
661 };
662
663 extern const union \fIC\fB__vtu_\fIh\fB \fIC\fB__vtable_\fIh\fB;
664 .ft P
665 .fi
666 .PP
667 The outer layer is a
668 .B union
669 .IB C __vtu_ h
670 containing a member
671 .IP
672 .B struct
673 .IB A __vt_ h
674 .IB a ;
675 .PP
676 for each of
677 .IR C 's
678 superclasses
679 .I A
680 in the same chain,
681 with
682 .I C
683 itself listed first.
684 This is mostly an irrelevant detail,
685 whose purpose is to defend against malicious compilers:
686 pointers are always to one of the inner
687 .B vt
688 structures.
689 It's important only because it's the outer
690 .B vtu
691 union which is exported by name.
692 Specifically, for each chain of
693 .IR C 's
694 superclasses
695 there is an external object
696 .IP
697 .B const union
698 .IB A __vtu_ i
699 .IB C __vtable_ i ;
700 .PP
701 where
702 .I A
703 and
704 .I I
705 are respectively the most and least specific classes in the chain.
706 .PP
707 The first member in the
708 .B vt
709 structure is the
710 .I root class pointer
711 .IP
712 .B const
713 .IR P
714 .B *_class;
715 .PP
716 Among the superclasses of
717 .I C
718 there must be exactly one class
719 .I O
720 which itself has no direct superclasses;
721 this is the
722 .I root superclass
723 of
724 .IR C .
725 (This is a rule enforced by the Sod translator.)
726 The metaclass
727 .I R
728 of
729 .I O
730 is then the
731 .I root metaclass
732 of
733 .IR C .
734 The
735 .B _class
736 member points to the
737 .B ichain
738 structure of most specific superclass
739 .I P
740 of
741 .I M
742 in the same chain as
743 .IR R .
744 .PP
745 This is followed by the
746 .I base offset
747 .IP
748 .B size_t
749 .B _base;
750 .PP
751 which is simply the offset of the
752 .B ichain
753 structure from the instance base.
754 .PP
755 The rest of the vtable structure is populated
756 by walking the superclass chain containing
757 .I C
758 as follows.
759 For each such superclass
760 .IR B ,
761 in increasing order of specificity,
762 walk the class precedence list of
763 .IR B ,
764 again starting with its least-specific superclass.
765 (This complex procedure guarantees that
766 the vtable structure for a class is a prefix of
767 the vtable structure for any of its subclasses in the same chain.)
768 .PP
769 So, let
770 .I A
771 be some superclass of
772 .I C
773 which has been encountered during this traversal.
774 .hP \*o
775 Let
776 .I N
777 be the metaclass of
778 .IR A .
779 Examine the superclass chains of
780 .I N
781 in order of decreasing specificity of their most-specific classes.
782 Let
783 .I J
784 be the chain head of such a chain,
785 and let
786 .I Q
787 be the most specific superclass of
788 .I M
789 in the same chain as
790 .IR J .
791 Then, if there is currently no class pointer of type
792 .IR Q ,
793 then add a member
794 .RS
795 .IP
796 .B const
797 .I Q
798 .BI *_cls_ j ;
799 .PP
800 to the vtable
801 pointing to the appropriate
802 .B islots
803 structure within
804 .IR M 's
805 class object.
806 .RE
807 .hP \*o
808 Examine the superclass chains of
809 .I A
810 in order of decreasing specificity of their most-specific classes.
811 Let
812 .I I
813 be the chain head of such a chain.
814 If there is currently no member
815 .BI _off_ i
816 then add a member
817 .RS
818 .IP
819 .B ptrdiff_t
820 .BI _off_ i ;
821 .PP
822 to the vtable,
823 containing the (signed) offset from the
824 .B ichain
825 structure of the chain headed by
826 .I h
827 to that of the chain headed by
828 .I i
829 within the instance's layout.
830 .RE
831 .hP \*o
832 If class
833 .I A
834 defines any messages,
835 and there is currently no member
836 .IR a ,
837 then add a member
838 .RS
839 .IP
840 .B struct
841 .IB C __vtmsgs_ a
842 .IB a ;
843 .PP
844 to the vtable.
845 See below.
846 .RE
847 .PP
848 Finally, the
849 .B vtmsgs
850 structures contain pointers to the effective method entry functions
851 for the messages defined by a superclass.
852 There may be more than one method entry for a message,
853 but all of the entry pointers for a message appear together,
854 and entry pointers for separate messages appear
855 in the order in which the messages are defined.
856 If the receiver class has no applicable primary method for a message
857 then it's usual for the method entry pointer to be null
858 (though, as with a lot of things in Sod,
859 extensions may do something different).
860 .PP
861 For a standard message which takes a fixed number of arguments,
862 defined as
863 .IP
864 .I tr
865 .IB m ( \c
866 .I t1
867 .IB a1 , 
868 .RB ... ,
869 .I tn
870 .IB an );
871 .PP
872 there is always a `main' entry point,
873 .IP
874 .I tr
875 .BI (* m )( \c
876 .I C
877 .BI * me ,
878 .I t1
879 .IB a1 , 
880 .RB ... ,
881 .I tn
882 .IB an );
883 .PP
884 For a standard message which takes a variable number of arguments,
885 defined as
886 .IP
887 .I tr
888 .IB m ( \c
889 .I t1
890 .IB a1 , 
891 .RB ... ,
892 .I tn
893 .IB an , 
894 .B ...);
895 .PP
896 two entry points are defined:
897 the usual `main' entry point
898 which accepts a variable number of
899 arguments,
900 and a `valist' entry point
901 which accepts an argument of type
902 .B va_list
903 in place of the variable portion of the argument list.
904 .IP
905 .I tr
906 .BI (* m )( \c
907 .I C
908 .BI * me ,
909 .I t1
910 .IB a1 , 
911 .RB ... ,
912 .I tn
913 .IB an ,
914 .B ...);
915 .br
916 .I tr
917 .BI (* m __v)( \c
918 .I C
919 .BI * me ,
920 .I t1
921 .IB a1 , 
922 .RB ... ,
923 .I tn
924 .IB an ,
925 .B va_list
926 .IB sod__ap );
927 .
928 .SS Additional definitions
929 In addition to the instance and vtable structures described above,
930 the following definitions are made for each class
931 .IR C .
932 .PP
933 For each message
934 .I m
935 directly defined by
936 .I C
937 there is a macro definition
938 .IP
939 .B #define
940 .IB C _ m ( me ,
941 .RB ... )
942 .IB me ->_vt-> c . m ( me ,
943 .RB ... )
944 .PP
945 which makes sending the message
946 .I m
947 to an instance of (any subclass of)
948 .I C
949 somewhat less ugly.
950 If
951 .I m
952 takes a variable number of arguments,
953 the macro is more complicated
954 and is only available in compilers advertising C99 support,
955 but the effect is the same.
956 For each variable-argument message,
957 there is also an additional macro
958 for calling the `valist' entry point.
959 .IP
960 .B #define
961 .IB C _ m __v( me ,
962 .RB ...,
963 .IB sod__ap )
964 .if !t \{\
965 \e
966 .br
967 \h'4m'\c
968 .\}
969 .IB me ->_vt-> c . m __v( me ,
970 .RB ...,
971 .IB sod__ap )
972 .PP
973 For each proper superclass
974 .I A
975 of
976 .IR C ,
977 there is a macro defined
978 .IP
979 .I A
980 .BI * C __CONV_ a ( C
981 .BI * _obj );
982 .PP
983 (named in
984 .IR "upper case" )
985 which converts a (static-type) pointer to
986 .I C
987 to a pointer to the same actual instance,
988 but statically typed as a pointer to
989 .IR A .
990 This is most useful when
991 .I A
992 is not in the same chain as
993 .I C
994 since in-chain upcasts are both trivial and rarely needed,
995 but the full set is defined for the sake of completeness.
996 .PP
997 Finally, the class object is defined as
998 .IP
999 .B extern const struct
1000 .IB R __ilayout
1001 .IB C __classobj;
1002 .br
1003 .B #define
1004 .IB C __class
1005 .BI (& C __classobj. j . r )
1006 .PP
1007 The exported symbol
1008 .IB C __classobj
1009 contains the entire class instance.
1010 This is usually rather unwieldy.
1011 The macro
1012 .IB C __class
1013 is usable as a pointer of type
1014 .B const
1015 .I R
1016 .BR * ,
1017 where
1018 .I R
1019 is the root metaclass of
1020 .IR C ,
1021 i.e., the metaclass of the least specific superclass of
1022 .IR C ;
1023 usually this is
1024 .BR "const SodClass *" .
1025 .
1026 .\"--------------------------------------------------------------------------
1027 .SH SEE ALSO
1028 .BR sod (3).
1029 .
1030 .\"--------------------------------------------------------------------------
1031 .SH AUTHOR
1032 Mark Wooding, <mdw@distorted.org.uk>
1033 .
1034 .\"----- That's all, folks --------------------------------------------------