3 .\" The Sod runtime library
5 .\" (c) 2015 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the Sensible Object Design, an object system for C.
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.
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.
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.
27 .\" Highlight using terminal escapes, rather than overstriking.
30 .\" String definitions and font selection.
39 .\" .hP TEXT -- start an indented paragraph with TEXT hanging off to the left
42 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
45 .\"--------------------------------------------------------------------------
46 .TH sod 3 "8 September 2015" "Straylight/Edgeware" "Sensible Object Design"
49 sod \- Sensible Object Design runtime library
51 .\"--------------------------------------------------------------------------
53 .B #include <sod/sod.h>
58 .BI "const " cls " *" obj );
66 .IB cls "__ilayout *" \c
70 .BI "const void *" obj );
74 .BI "const " cls " *" obj );
78 .BI "const " cls " *" obj );
82 .BI "const SodClass *" sub ,
83 .BI "const SodClass *" super );
88 .BI "const void *" obj );
92 .BI "const SodClass *" cls ,
93 .BI "const void *" obj );
100 .\"--------------------------------------------------------------------------
103 The functions and macros defined here generally expect that
104 instances and classes inherit from the standard
107 While the translator can (at some effort) support alternative roots,
108 they will require different run-time support machinery.
111 The following macros are useful in
112 finding one's way around an instance layout structure,
113 given various levels of information about
114 what kind of object one is dealing with,
115 or for computing the tables which are used for
116 this kind of navigation.
118 These macros are mostly intended for use in
119 code generated by the Sod translator.
120 Others may find them useful for special effects,
121 but they can be tricky to understand and use correctly
122 and can't really be recommended for general use.
126 macro returns the signed offset between
127 two members of a structure or union type.
128 Given a structure or union type
139 gives the difference, in bytes,
148 This macro is used internally when generating vtables
149 and is not expected to be very useful elsewhere.
153 macro recovers the instance layout base address
154 from a pointer to one of its instance chains.
155 Specifically, given a class name
159 of the least specific class in one of
164 to the instance storage for the chain containing
166 within an exact instance of
168 (i.e., not an instance of any proper subclass),
173 returns the a pointer to the layout structure containing
175 This macro is used internally in effective method bodies
176 and is not expected to be very useful elsewhere
177 since it's unusual to have such specific knowledge
178 about the dynamic type of an instance.
181 macro (described below) is more suited to general use.
185 macro finds the base address of an instance's layout.
187 .BI "const " cls " *" obj
189 .BI SOD_INSTBASE( obj )
190 returns the base address of the storage allocated to
192 This is useful if you want to free a dynamically allocated instance,
194 This macro needs to look up an offset in
196 vtable to do its work.
200 which is faster but requires
201 precise knowledge of the instance's dynamic class.
204 The following macros and functions
205 query the runtime relationhips between
206 instances and classes.
210 macro returns the class object describing an instance's dynamic class.
212 .BI "const " cls " *" obj
214 .BI SOD_CLASSOF( obj )
221 is typed correctly in the first place)
222 will be a subclass of
224 (If you wanted the class object for
228 .IB cls __class \fR.)
232 function answers whether one class
234 is actually a subclass of another class
239 returns nonzero if and only if
243 This involves a run-time trawl through the class structures:
244 while some effort has been made to make it perform well
245 it's still not very fast.
248 The following macros and functions are used
249 to convert instance pointers of some (static) type
250 into instance pointers of other static types
251 to the same instance.
255 macro performs a `cross-chain upcast'.
259 to an instance of a class of type
263 of the least specific class in one of
265 superclass chains which does not contain
271 returns the address of that chain's storage
272 within the instance layout as a raw
277 is not mentioned explicitly.)
278 This macro is used by the generated
281 which you are encouraged to use instead where possible.
289 perform general conversions
290 (up-, down-, and cross-casts) on instance pointers.
294 .BI "const void *" obj
296 they return an appropriately converted pointer to
300 is indeed an instance of (some subclass of)
302 otherwise they return a null pointer.
312 expects a pointer to a class object instead.
314 This involves a run-time trawl through the class structures:
315 while some effort has been made to make it perform well
316 it's still not very fast.
319 is a superclass of the static type of
321 the automatically defined conversion macros should be used instead,
322 because they're much faster and can't fail.
324 When the target class is known statically,
325 it's slightly more convenient to use the
327 macro rather than the
330 since the class object name is longer and uglier,
331 and the macro returns a pointer of the correct type.
333 .SS Instance lifecycle
334 The following macros and functions
335 manage the standard steps along
336 an instance's lifecycle.
340 macro declares and initializes an instance
341 with automatic storage duration.
351 to be a pointer to an instance of
353 The instance is initialized in the sense that
354 its vtable and class pointers have been set up,
355 and slots for which initializers are defined
356 are set to the appropriate initial values.
357 The instance has automatic storage duration:
358 pointers to it will become invalid when control
359 exits the scope of the declaration.
361 .\"--------------------------------------------------------------------------
366 .\"--------------------------------------------------------------------------
368 Mark Wooding, <mdw@distorted.org.uk>
370 .\"----- That's all, folks --------------------------------------------------