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 );
78 .BI "const " cls " *" obj );
82 .BI "const " cls " *" obj );
87 .BI "const void *" obj );
95 .BI "const SodClass *" sub ,
96 .BI "const SodClass *" super );
100 .BI "const SodClass *" cls ,
101 .BI "const void *" obj );
103 .\"--------------------------------------------------------------------------
106 The functions and macros defined here generally expect that
107 instances and classes inherit from the standard
110 While the translator can (at some effort) support alternative roots,
111 they will require different run-time support machinery.
113 .SS Infrastructure macros
114 These macros are mostly intended for use in code
115 generated by the Sod translator.
116 Others may find them useful for special effects,
117 but they can be tricky to understand and use correctly
118 and can't really be recommended for general use.
122 macro performs a `cross-chain upcast'.
126 to an instance of a class of type
130 of the least specific class in one of
132 superclass chains which does not contain
138 returns the address of that chain's storage
139 within the instance layout as a raw
144 is not mentioned explicitly.)
145 This macro is used by the generated
146 .IB CLASS __CONV_ CLS
148 which you are encouraged to use instead where possible.
152 macro returns the signed offset between
153 two members of a structure or union type.
154 Given a structure or union type
165 gives the difference, in bytes,
174 This macro is used internally when generating vtables
175 and is not expected to be very useful elsewhere.
179 macro recovers the instance layout base address
180 from a pointer to one of its instance chains.
181 Specifically, given a class name
185 of the least specific class in one of
190 to the instance storage for the chain containing
192 within an exact instance of
194 (i.e., not an instance of any proper subclass),
199 returns the a pointer to the layout structure containing
201 This macro is used internally in effective method bodies
202 and is not expected to be very useful elsewhere
203 since it's unusual to have such specific knowledge
204 about the dynamic type of an instance.
207 macro (described below) is more suited to general use.
211 macro accepts one or more arguments
212 and expands to just its first argument,
213 discarding the others.
214 It is only defined if the C implementation
215 advertises support for C99.
216 It is used in the definitions of message convenience macros
217 for messages which accept a variable number of arguments
218 but no required arguments,
219 and is exported because the author has found such a thing useful in
223 The following macros are expected to be useful
224 in Sod method definitions and client code.
228 macro returns the class object describing an instance's dynamic class.
230 .BI "const " cls " *" obj
232 .BI SOD_CLASSOF( obj )
239 is typed correctly in the first place)
240 will be a subclass of
242 (If you wanted the class object for
246 .IB cls __class \fR.)
250 macro finds the base address of an instance's layout.
252 .BI "const " cls " *" obj
254 .BI SOD_INSTBASE( obj )
255 returns the base address of the storage allocated to
257 This is useful if you want to free a dynamically allocated instance,
259 This macro needs to look up an offset in
261 vtable to do its work.
265 which is faster but requires
266 precise knowledge of the instance's dynamic class.
270 macro performs general conversions
271 (up-, down-, and cross-casts) on instance pointers.
275 .BI "const void *" obj
280 returns an appropriately converted pointer to
284 is indeed an instance of (some subclass of)
286 otherwise it returns a null pointer.
287 This macro is a simple wrapper around the
289 function described below,
290 which is useful in the common case that
291 the target class is known statically.
295 macro declares and initializes an instance
296 with automatic storage duration.
306 to be a pointer to an instance of
308 The instance is initialized in the sense that
309 its vtable and class pointers have been set up,
310 and slots for which initializers are defined
311 are set to the appropriate initial values.
312 The instance has automatic storage duration:
313 pointers to it will become invalid when control
314 exits the scope of the declaration.
317 The following functions are provided.
321 function answers whether one class
323 is actually a subclass of another class
328 returns nonzero if and only if
332 This involves a run-time trawl through the class structures:
333 while some effort has been made to make it perform well
334 it's still not very fast.
338 function performs general conversions
339 (up-, down-, and cross-casts) on instance pointers.
340 Given a class pointer
342 and an instance pointer
347 returns an appropriately converted pointer to
351 is an instance of (some subclass of)
353 otherwise it returns null.
354 This involves a run-time trawl through the class structures:
355 while some effort has been made to make it perform well
356 it's still not very fast.
359 is a superclass of the static type of
361 the automatically defined conversion macros should be used instead,
362 because they're much faster and can't fail.
363 When the target class is known statically,
364 it's slightly more convenient to use the
368 .\"--------------------------------------------------------------------------
373 .\"--------------------------------------------------------------------------
375 Mark Wooding, <mdw@distorted.org.uk>
377 .\"----- That's all, folks --------------------------------------------------