| 1 | %%% -*-latex-*- |
| 2 | %%% |
| 3 | %%% Class layout and method combination protocols |
| 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 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{Class layout and method combination} |
| 27 | |
| 28 | %%%-------------------------------------------------------------------------- |
| 29 | \section{Class layout protocol} \label{sec:layout.instance} |
| 30 | |
| 31 | \begin{describe}{fun}{islots-struct-tag @<class> @> @<string>} |
| 32 | \end{describe} |
| 33 | |
| 34 | \begin{describe}{fun}{ichain-struct-tag @<class> @<chain-head> @> @<string>} |
| 35 | \end{describe} |
| 36 | |
| 37 | \begin{describe}{fun}{ichain-union-tag @<class> @<chain-head> @> @<string>} |
| 38 | \end{describe} |
| 39 | |
| 40 | \begin{describe}{fun}{ilayout-struct-tag @<class> @> @<string>} |
| 41 | \end{describe} |
| 42 | |
| 43 | \begin{describe}{fun}{vtmsgs-struct-tag @<class> @<super> @> @<string>} |
| 44 | \end{describe} |
| 45 | |
| 46 | \begin{describe}{fun}{vtable-union-tag @<class> @<chain-head> @> @<string>} |
| 47 | \end{describe} |
| 48 | |
| 49 | \begin{describe}{fun}{vtable-struct-tag @<class> @<chain-head> @> @<string>} |
| 50 | \end{describe} |
| 51 | |
| 52 | \begin{describe}{fun}{vtable-name @<class> @<chain-head> @> @<string>} |
| 53 | \end{describe} |
| 54 | |
| 55 | \begin{describe}{fun}{message-macro-name @<class> @<entry> @> @<string>} |
| 56 | \end{describe} |
| 57 | |
| 58 | \begin{describe}{cls}{effective-slot () \&key :class :slot :initializer} |
| 59 | \end{describe} |
| 60 | |
| 61 | \begin{describe*} |
| 62 | {\dhead{gf}{effective-slot-class @<slot> @> @<class>} |
| 63 | \dhead{gf}{effective-slot-direct-slot @<slot> @> @<direct-slot>} |
| 64 | \dhead{gf}{effective-slot-initializer @<slot> @> @<init-or-nil>}} |
| 65 | \end{describe*} |
| 66 | |
| 67 | \begin{describe}{gf} |
| 68 | {find-slot-initializer @<class> @<slot> @> @<init-or-nil>} |
| 69 | \end{describe} |
| 70 | |
| 71 | \begin{describe}{gf} |
| 72 | {find-class-initializer @<slot> @<class> @> @<init-or-nil>} |
| 73 | \end{describe} |
| 74 | |
| 75 | \begin{describe}{gf}{find-slot-initargs @<class> @<slot> @> @<list>} |
| 76 | \end{describe} |
| 77 | |
| 78 | \begin{describe}{gf} |
| 79 | {compute-effective-slot @<class> @<slot> @> @<effective-slot>} |
| 80 | \end{describe} |
| 81 | |
| 82 | \begin{describe}{cls} |
| 83 | {sod-class-effective-slot (effective-slot) \\ \ind |
| 84 | \&key :class :slot :initializer-function :prepare-function} |
| 85 | \end{describe} |
| 86 | |
| 87 | \begin{describe*} |
| 88 | {\dhead{gf}{effective-slot-initializer-function @<slot> @> @<function>} |
| 89 | \dhead{gf}{effective-slot-prepare-function @<slot> @> @<function>}} |
| 90 | \end{describe*} |
| 91 | |
| 92 | \begin{describe}{cls}{islots () \&key :class :subclass :slots} |
| 93 | \end{describe} |
| 94 | |
| 95 | \begin{describe*} |
| 96 | {\dhead{gf}{islots-class @<islots> @> @<class>} |
| 97 | \dhead{gf}{islots-subclass @<islots> @> @<class>} |
| 98 | \dhead{gf}{islots-slots @<islots> @> @<list>}} |
| 99 | \end{describe*} |
| 100 | |
| 101 | \begin{describe}{gf}{compute-islots @<class> @<subclass> @> @<islots>} |
| 102 | \end{describe} |
| 103 | |
| 104 | \begin{describe}{gf}{vtable-pointer () \&key :class :chain-head :chain-tail} |
| 105 | \end{describe} |
| 106 | |
| 107 | \begin{describe*} |
| 108 | {\dhead{gf}{vtable-pointer-class @<vtable-pointer> @> @<class>} |
| 109 | \dhead{gf}{vtable-pointer-chain-head @<vtable-pointer> @> @<class>} |
| 110 | \dhead{gf}{vtable-pointer-chain-tail @<vtable-pointer> @> @<class>}} |
| 111 | \end{describe*} |
| 112 | |
| 113 | \begin{describe}{gf}{ichain () \&key :class :chain-head :chain-tail :body} |
| 114 | \end{describe} |
| 115 | |
| 116 | \begin{describe*} |
| 117 | {\dhead{gf}{ichain-class @<ichain> @> @<class>} |
| 118 | \dhead{gf}{ichain-chain-head @<ichain> @> @<class>} |
| 119 | \dhead{gf}{ichain-chain-tail @<ichain> @> @<class>} |
| 120 | \dhead{gf}{ichain-body @<ichain> @> @<list>}} |
| 121 | \end{describe*} |
| 122 | |
| 123 | \begin{describe}{gf}{compute-ichain @<class> @<chain> @> @<ichain>} |
| 124 | \end{describe} |
| 125 | |
| 126 | \begin{describe}{gf}{ilayout () \&key :class :ichains} |
| 127 | \end{describe} |
| 128 | |
| 129 | \begin{describe*} |
| 130 | {\dhead{gf}{ilayout-class @<ilayout> @> @<class>} |
| 131 | \dhead{gf}{ilayout-ichains @<ilayout> @> @<list>}} |
| 132 | \end{describe*} |
| 133 | |
| 134 | \begin{describe}{gf}{sod-class-ilayout <class> @> @<ilayout>} |
| 135 | \end{describe} |
| 136 | |
| 137 | \begin{describe}{gf}{compute-ilayout @<class> @> @<ilayout>} |
| 138 | \end{describe} |
| 139 | |
| 140 | \begin{describe}{cls} |
| 141 | {vtmsgs () \&key :class :subclass :chain-head :chain-tail :entries} |
| 142 | \end{describe} |
| 143 | |
| 144 | \begin{describe*} |
| 145 | {\dhead{gf}{vtmsgs-class @<vtmsgs> @> @<class>} |
| 146 | \dhead{gf}{vtmsgs-subclass @<vtmsgs> @> @<class>} |
| 147 | \dhead{gf}{vtmsgs-chain-head @<vtmsgs> @> @<class>} |
| 148 | \dhead{gf}{vtmsgs-chain-tail @<vtmsgs> @> @<class>} |
| 149 | \dhead{gf}{vtmsgs-entries @<vtmsgs> @> @<list>}} |
| 150 | \end{describe*} |
| 151 | |
| 152 | \begin{describe}{cls} |
| 153 | {class-pointer () \&key :class :chain-head :metaclass :meta-chain-head} |
| 154 | \end{describe} |
| 155 | |
| 156 | \begin{describe*} |
| 157 | {\dhead{gf}{class-pointer-class @<class-pointer> @> @<class>} |
| 158 | \dhead{gf}{class-pointer-chain-head @<class-pointer> @> @<class>} |
| 159 | \dhead{gf}{class-pointer-metaclass @<class-pointer> @> @<class>} |
| 160 | \dhead{gf}{class-pointer-meta-chain-head @<class-pointer> @> @<class>}} |
| 161 | \end{describe*} |
| 162 | |
| 163 | \begin{describe}{fun} |
| 164 | {make-class-pointer @<class> @<chain-head> |
| 165 | @<metaclass> @<meta-chain-head> |
| 166 | @> @<class-pointer>} |
| 167 | \end{describe} |
| 168 | |
| 169 | \begin{describe}{cls}{base-offset () \&key :class :chain-head} |
| 170 | \end{describe} |
| 171 | |
| 172 | \begin{describe*} |
| 173 | {\dhead{gf}{base-offset-class @<base-offset> @> @<class>} |
| 174 | \dhead{gf}{base-offset-chain-head @<base-offset> @> @<class>}} |
| 175 | \end{describe*} |
| 176 | |
| 177 | \begin{describe}{fun} |
| 178 | {make-base-offset @<class> @<chain-head> @> @<base-offset>} |
| 179 | \end{describe} |
| 180 | |
| 181 | \begin{describe}{cls}{chain-offset () \&key :class :chain-head :target-head} |
| 182 | \end{describe} |
| 183 | |
| 184 | \begin{describe*} |
| 185 | {\dhead{gf}{chain-offset-class @<chain-offset> @> @<class>} |
| 186 | \dhead{gf}{chain-offset-chain-head @<chain-offset> @> @<class>} |
| 187 | \dhead{gf}{chain-offset-target-head @<chain-offset> @> @<class>}} |
| 188 | \end{describe*} |
| 189 | |
| 190 | \begin{describe}{fun} |
| 191 | {make-chain-offset @<class> @<chain-head> @<target-head> |
| 192 | @> @<chain-offset>} |
| 193 | \end{describe} |
| 194 | |
| 195 | \begin{describe}{gf}{vtable () \&key :class :chain-head :chain-tail :body} |
| 196 | \end{describe} |
| 197 | |
| 198 | \begin{describe*} |
| 199 | {\dhead{gf}{vtable-class @<vtable> @> @<class>} |
| 200 | \dhead{gf}{vtable-chain-head @<vtable> @> @<class>} |
| 201 | \dhead{gf}{vtable-chain-tail @<vtable> @> @<class>} |
| 202 | \dhead{gf}{vtable-body @<vtable> @> @<list>}} |
| 203 | \end{describe*} |
| 204 | |
| 205 | \begin{describe}{gf} |
| 206 | {compute-vtable-items @<class> @<super> |
| 207 | @<chain-head> @<chain-tail> |
| 208 | @<emit-function>} |
| 209 | \end{describe} |
| 210 | |
| 211 | \begin{describe}{gf}{compute-vtable @<class> @<chain> @> @<vtable>} |
| 212 | \end{describe} |
| 213 | |
| 214 | \begin{describe}{gf}{sod-class-vtables @<class> @> @<list>} |
| 215 | \end{describe} |
| 216 | |
| 217 | \begin{describe}{gf}{compute-vtables @<class> @> @<list>} |
| 218 | \end{describe} |
| 219 | |
| 220 | %%%-------------------------------------------------------------------------- |
| 221 | \section{Method combination} \label{sec:layout.methods} |
| 222 | |
| 223 | \begin{describe}{cls}{effective-method () \&key :message :class :keywords} |
| 224 | \end{describe} |
| 225 | |
| 226 | \begin{describe*} |
| 227 | {\dhead{gf}{effective-method-message @<method> @> @<message>} |
| 228 | \dhead{gf}{effective-method-class @<method> @> @<class>} |
| 229 | \dhead{gf}{effective-method-keywords @<method> @> @<list>}} |
| 230 | \end{describe*} |
| 231 | |
| 232 | \begin{describe}{gf} |
| 233 | {sod-message-applicable-methods @<message> @<class> @> list} |
| 234 | \end{describe} |
| 235 | |
| 236 | \begin{describe}{gf} |
| 237 | {sod-message-effective-method-class @<message> @> @<class>} |
| 238 | \end{describe} |
| 239 | |
| 240 | \begin{describe}{gf}{primary-method-class @<message> @> @<class>} |
| 241 | \end{describe} |
| 242 | |
| 243 | \begin{describe}{gf} |
| 244 | {method-keyword-argument-lists @<method> @<direct-methods> @<state> |
| 245 | @> @<list>} |
| 246 | \end{describe} |
| 247 | |
| 248 | \begin{describe}{gf} |
| 249 | {compute-sod-effective-method @<message> @<class> @> @<method>} |
| 250 | \end{describe} |
| 251 | |
| 252 | \begin{describe}{gf}{sod-class-effective-methods @<class> @> @<list>} |
| 253 | \end{describe} |
| 254 | |
| 255 | \begin{describe}{gf}{compute-effective-methods @<class> @> @<list>} |
| 256 | \end{describe} |
| 257 | |
| 258 | \begin{describe}{cls} |
| 259 | {method-entry () \&key :method :chain-head :chain-tail :role} |
| 260 | \end{describe} |
| 261 | |
| 262 | \begin{describe*} |
| 263 | {\dhead{gf}{method-entry-effective-method @<method-entry> @> @<method>} |
| 264 | \dhead{gf}{method-entry-chain-head @<method-entry> @> @<class>} |
| 265 | \dhead{gf}{method-entry-chain-tail @<method-entry> @> @<class>} |
| 266 | \dhead{gf}{method-entry-role @<method-entry> @> @<role>}} |
| 267 | \end{describe*} |
| 268 | |
| 269 | \begin{describe}{gf} |
| 270 | {make-method-entries @<effective-method> @<chain-head> @<chain-tail> |
| 271 | @> @<list>} |
| 272 | \end{describe} |
| 273 | |
| 274 | |
| 275 | \begin{describe}{gf}{sod-message-argument-tail @<message> @> @<list>} |
| 276 | \end{describe} |
| 277 | |
| 278 | \begin{describe}{gf}{sod-method-function-type @<method> @> @<c-type>} |
| 279 | \end{describe} |
| 280 | |
| 281 | \begin{describe}{gf}{sod-method-next-method-type @<method> @> @<c-type>} |
| 282 | \end{describe} |
| 283 | |
| 284 | \begin{describe}{gf}{sod-method-description @<method> @> @<string>} |
| 285 | \end{describe} |
| 286 | |
| 287 | \begin{describe}{gf}{sod-method-function-name @<method> @> @<string>} |
| 288 | \end{describe} |
| 289 | |
| 290 | \begin{describe}{fun}{varargs-message-p @<message> @> @<generalized-boolean>} |
| 291 | \end{describe} |
| 292 | |
| 293 | \begin{describe}{fun}{keyword-message-p @<message> @> @<generalized-boolean>} |
| 294 | \end{describe} |
| 295 | |
| 296 | \begin{describe}{gf}{method-entry-function-type @<entry> @> @<c-type>} |
| 297 | \end{describe} |
| 298 | |
| 299 | \begin{describe}{gf}{method-entry-slot-name @<entry> @> @<string>} |
| 300 | \end{describe} |
| 301 | |
| 302 | \begin{describe}{gf} |
| 303 | {method-entry-slot-name-by-role @<entry> @<role> @<name> @> @<string>} |
| 304 | \end{describe} |
| 305 | |
| 306 | \begin{describe}{gf} |
| 307 | {effective-method-basic-argument-names @<method> @> @<list>} |
| 308 | \end{describe} |
| 309 | |
| 310 | \begin{describe}{gf} |
| 311 | {effective-method-live-p @<method> @> @<generalized-boolean>} |
| 312 | \end{describe} |
| 313 | |
| 314 | |
| 315 | \begin{describe}{cls} |
| 316 | {method-codegen (codegen) \\ \ind |
| 317 | \&key :vars :insts :temp-index |
| 318 | :message :class :method :target} |
| 319 | \end{describe} |
| 320 | |
| 321 | \begin{describe*} |
| 322 | {\dhead{gf}{codegen-message @<codegen> @> @<message>} |
| 323 | \dhead{gf}{codegen-class @<codegen> @> @<class>} |
| 324 | \dhead{gf}{codegen-method @<codegen> @> @<method>} |
| 325 | \dhead{gf}{codegen-target @<codegen> @> @<target>}} |
| 326 | \end{describe*} |
| 327 | |
| 328 | \begin{describe*} |
| 329 | {\dhead{cls}{convert-to-ilayout-inst (inst)} |
| 330 | \dhead{fun} |
| 331 | {make-convert-to-ilayout-inst @<class> @<chain-head> @<expr>}} |
| 332 | \begin{prog} |
| 333 | SOD_ILAYOUT(@<class>, @<chain-head-nick>, @<expr>) |
| 334 | \end{prog} |
| 335 | \end{describe*} |
| 336 | |
| 337 | |
| 338 | \begin{describe}{gf} |
| 339 | {compute-effective-method-body @<method> @<codegen> @<target>} |
| 340 | \end{describe} |
| 341 | |
| 342 | \begin{describe}{gf}{simple-method-body @<method> @<codegen> @<target>} |
| 343 | \end{describe} |
| 344 | |
| 345 | \begin{describe}{fun} |
| 346 | {invoke-method @<codegen> @<target> @<arguments-tail> @<direct-method>} |
| 347 | \end{describe} |
| 348 | |
| 349 | \begin{describe}{fun}{ensure-ilayout-var @<codegen> @<super>} |
| 350 | \end{describe} |
| 351 | |
| 352 | \begin{describe}{fun}{make-trampoline @<codegen> @<super> @<body-func>} |
| 353 | \end{describe} |
| 354 | |
| 355 | \begin{describe}{gf}{effective-method-function-name @<method> @> @<string>} |
| 356 | \end{describe} |
| 357 | |
| 358 | \begin{describe}{gf} |
| 359 | {method-entry-function-name @<method> @<chain-head> @<role> @> @<string>} |
| 360 | \end{describe} |
| 361 | |
| 362 | \begin{describe}{gf}{compute-method-entry-functions @<method> @> @<list>} |
| 363 | \end{describe} |
| 364 | |
| 365 | \begin{describe}{fun} |
| 366 | {invoke-delegation-chain @<codegen> @<target> @<basic-tail> |
| 367 | @<chain> @<kernel-func>} |
| 368 | \end{describe} |
| 369 | |
| 370 | \begin{describe}{cls} |
| 371 | {basic-message (sod-message) \&key :name :location :class :type} |
| 372 | \end{describe} |
| 373 | |
| 374 | \begin{describe}{cls} |
| 375 | {simple-message (basic-message) \&key :name :location :class :type} |
| 376 | \end{describe} |
| 377 | |
| 378 | \begin{describe}{cls} |
| 379 | {basic-direct-method (sod-method) |
| 380 | \&key :message :location :class :type :body :role} |
| 381 | \end{describe} |
| 382 | |
| 383 | \begin{describe}{gf}{sod-method-role @<method> @> @<role>} |
| 384 | \end{describe} |
| 385 | |
| 386 | \begin{describe}{cls} |
| 387 | {daemon-direct-method (basic-direct-method) \\ \ind |
| 388 | \&key :message :location :class :type :body :role} |
| 389 | \end{describe} |
| 390 | |
| 391 | \begin{describe}{cls} |
| 392 | {delegating-direct-method (basic-direct-method) \\ \ind |
| 393 | \&key :message :location :class :type :body :role} |
| 394 | \end{describe} |
| 395 | |
| 396 | \begin{describe}{cls} |
| 397 | {basic-effective-method (effective-method) \\ \ind |
| 398 | \&key :message :class :around-methods :before-methods :after-methods} |
| 399 | \end{describe} |
| 400 | |
| 401 | \begin{describe*} |
| 402 | {\dhead{gf} |
| 403 | {effective-method-around-methods @<effective-method> @> @<list>} |
| 404 | \dhead{gf} |
| 405 | {effective-method-before-methods @<effective-method> @> @<list>} |
| 406 | \dhead{gf} |
| 407 | {effective-method-after-methods @<effective-method> @> @<list>} |
| 408 | \dhead{gf}{effective-method-functions @<effective-method> @> @<list>}} |
| 409 | \end{describe*} |
| 410 | |
| 411 | \begin{describe}{cls} |
| 412 | {simple-effective-method (basic-effective-method) \\ \ind |
| 413 | \&key :message :class |
| 414 | :around-methods :before-methods :after-methods :primary-methods} |
| 415 | \end{describe} |
| 416 | |
| 417 | \begin{describe}{fun} |
| 418 | {basic-effective-method-body @<codegen> @<target> @<method> @<body>} |
| 419 | \end{describe} |
| 420 | |
| 421 | \begin{describe}{cls} |
| 422 | {standard-message (simple-message) \&key :name :location :class :type} |
| 423 | \end{describe} |
| 424 | |
| 425 | \begin{describe}{cls} |
| 426 | {standard-effective-method (simple-effective-method) \\ \ind |
| 427 | \&key :message :class |
| 428 | :around-methods :before-methods :after-methods :primary-methods} |
| 429 | \end{describe} |
| 430 | |
| 431 | \begin{describe}{cls} |
| 432 | {aggregating-message (simple-message) |
| 433 | \&key :name :location :class :type :combination} |
| 434 | \end{describe} |
| 435 | |
| 436 | \begin{describe}{gf} |
| 437 | {aggregating-message-properties @<message> @<combination> @> @<plist>} |
| 438 | \end{describe} |
| 439 | |
| 440 | \begin{describe}{gf} |
| 441 | {compute-aggregating-message-kernel |
| 442 | \=@<message> @<combination> @<target> \+\\ |
| 443 | @<methods> @<arg-names> \&key} |
| 444 | \end{describe} |
| 445 | |
| 446 | \begin{describe}{gf} |
| 447 | {check-aggregating-message-type @<message> @<combination> @<c-type>} |
| 448 | \end{describe} |
| 449 | |
| 450 | \begin{describe}{cls} |
| 451 | {aggregating-effective-method (simple-effective-method) \\ \ind |
| 452 | \&key :message :class |
| 453 | :around-methods :before-methods :after-methods :primary-methods} |
| 454 | \end{describe} |
| 455 | |
| 456 | \begin{describe}{mac} |
| 457 | {define-aggregating-method-combination @<combination> \\ \ind\ind |
| 458 | ((@<var-name>^*) |
| 459 | @[[ :codegen @<codegen-var> @! |
| 460 | :methods @<methods-var> @]]) \-\\ |
| 461 | @[[ \=:properties (@{ (@{ @<name> @! (@[@<keyword>@] @<name>) @} |
| 462 | @<c-type> |
| 463 | @[@<default> |
| 464 | @[@<suppliedp-var>@]@]) @}^*) @! \+\\ |
| 465 | :return-type @<c-type> @! \\ |
| 466 | :around @<around-func> @! |
| 467 | :first-method @<first-method-func> @! |
| 468 | :method @<method-func> @]]} |
| 469 | \end{describe} |
| 470 | |
| 471 | %%% the method combination story |
| 472 | %% compute-effective-methods --> compute-sod-effective-method |
| 473 | |
| 474 | %% hook-output (basic-effective-method :c) |
| 475 | %% basic-effective-method.functions |
| 476 | %% compute-method-entry-functions |
| 477 | %% compute-effective-method-body |
| 478 | %% |
| 479 | %% compute-effective-method-body (simple-effective-method) |
| 480 | %% basic-effective-method-body |
| 481 | %% simple-method-body (standard-effective-method) |
| 482 | %% simple-method-body (aggregating-effective-method) |
| 483 | %% message-kernel-function |
| 484 | |
| 485 | %%%----- That's all, folks -------------------------------------------------- |
| 486 | |
| 487 | %%% Local variables: |
| 488 | %%% mode: LaTeX |
| 489 | %%% TeX-master: "sod.tex" |
| 490 | %%% TeX-PDF-mode: t |
| 491 | %%% End: |