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