- Timestamp:
- Aug 18, 2021, 6:57:55 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- 1a6a6f2
- Parents:
- e3984a68
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/features.tex
re3984a68 red4d7c1 233 233 through the object. 234 234 235 This means virtual tables are declared and named in \CFA. 236 They are declared as variables, using the type 237 @vtable(VIRTUAL_TYPE)@ and any valid name. For example: 238 \begin{cfa} 239 vtable(virtual_type_name) table_name; 240 \end{cfa} 241 242 Like any variable they may be forward declared with the @extern@ keyword. 243 Forward declaring virtual tables is relatively common. 244 Many virtual types have an ``obvious" implementation that works in most 245 cases. 246 A pattern that has appeared in the early work using virtuals is to 247 implement a virtual table with the the obvious definition and place a forward 248 declaration of it in the header beside the definition of the virtual type. 249 250 Even on the full declaration, no initializer should be used. 251 Initialization is automatic. 252 The type id and special virtual members ``size" and ``align" only depend on 253 the virtual type, which is fixed given the type of the virtual table and 254 so the compiler fills in a fixed value. 255 The other virtual members are resolved, using the best match to the member's 256 name and type, in the same context as the virtual table is declared using 257 \CFA's normal resolution rules. 258 235 259 While much of the virtual infrastructure is created, it is currently only used 236 260 internally for exception handling. The only user-level feature is the virtual … … 247 271 @EXPRESSION@ object, otherwise it returns @0p@ (null pointer). 248 272 249 \section{Exception} 250 % Leaving until later, hopefully it can talk about actual syntax instead 251 % of my many strange macros. Syntax aside I will also have to talk about the 252 % features all exceptions support. 253 254 Exceptions are defined by the trait system; there are a series of traits, and 273 \section{Exceptions} 274 275 The syntax for declaring an exception is the same as declaring a structure 276 except the keyword that is swapped out: 277 \begin{cfa} 278 exception TYPE_NAME { 279 FIELDS 280 }; 281 \end{cfa} 282 283 Fields are filled in the same way as a structure as well. However an extra 284 field is added, this field contains the pointer to the virtual table. 285 It must be explicitly initialised by the user when the exception is 286 constructed. 287 288 Here is an example of declaring an exception type along with a virtual table, 289 assuming the exception has an ``obvious" implementation and a default 290 virtual table makes sense. 291 292 \begin{minipage}[t]{0.4\textwidth} 293 Header: 294 \begin{cfa} 295 exception Example { 296 int data; 297 }; 298 299 extern vtable(Example) 300 example_base_vtable; 301 \end{cfa} 302 \end{minipage} 303 \begin{minipage}[t]{0.6\textwidth} 304 Source: 305 \begin{cfa} 306 vtable(Example) example_base_vtable 307 \end{cfa} 308 \vfil 309 \end{minipage} 310 311 %\subsection{Exception Details} 312 If one is only raising and handling exceptions, that is the only interface 313 that is needed. However it is actually a short hand for a more complex 314 trait based interface. 315 316 The language views exceptions through a series of traits, 255 317 if a type satisfies them, then it can be used as an exception. The following 256 318 is the base trait all exceptions need to match.
Note: See TracChangeset
for help on using the changeset viewer.