Changeset ed4d7c1 for doc/theses


Ignore:
Timestamp:
Aug 18, 2021, 6:57:55 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
1a6a6f2
Parents:
e3984a68
Message:

Andrew MMath: Updated features to include the new exception syntax.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/features.tex

    re3984a68 red4d7c1  
    233233through the object.
    234234
     235This means virtual tables are declared and named in \CFA.
     236They are declared as variables, using the type
     237@vtable(VIRTUAL_TYPE)@ and any valid name. For example:
     238\begin{cfa}
     239vtable(virtual_type_name) table_name;
     240\end{cfa}
     241
     242Like any variable they may be forward declared with the @extern@ keyword.
     243Forward declaring virtual tables is relatively common.
     244Many virtual types have an ``obvious" implementation that works in most
     245cases.
     246A pattern that has appeared in the early work using virtuals is to
     247implement a virtual table with the the obvious definition and place a forward
     248declaration of it in the header beside the definition of the virtual type.
     249
     250Even on the full declaration, no initializer should be used.
     251Initialization is automatic.
     252The type id and special virtual members ``size" and ``align" only depend on
     253the virtual type, which is fixed given the type of the virtual table and
     254so the compiler fills in a fixed value.
     255The other virtual members are resolved, using the best match to the member's
     256name and type, in the same context as the virtual table is declared using
     257\CFA's normal resolution rules.
     258
    235259While much of the virtual infrastructure is created, it is currently only used
    236260internally for exception handling. The only user-level feature is the virtual
     
    247271@EXPRESSION@ object, otherwise it returns @0p@ (null pointer).
    248272
    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
     275The syntax for declaring an exception is the same as declaring a structure
     276except the keyword that is swapped out:
     277\begin{cfa}
     278exception TYPE_NAME {
     279        FIELDS
     280};
     281\end{cfa}
     282
     283Fields are filled in the same way as a structure as well. However an extra
     284field is added, this field contains the pointer to the virtual table.
     285It must be explicitly initialised by the user when the exception is
     286constructed.
     287
     288Here is an example of declaring an exception type along with a virtual table,
     289assuming the exception has an ``obvious" implementation and a default
     290virtual table makes sense.
     291
     292\begin{minipage}[t]{0.4\textwidth}
     293Header:
     294\begin{cfa}
     295exception Example {
     296        int data;
     297};
     298
     299extern vtable(Example)
     300        example_base_vtable;
     301\end{cfa}
     302\end{minipage}
     303\begin{minipage}[t]{0.6\textwidth}
     304Source:
     305\begin{cfa}
     306vtable(Example) example_base_vtable
     307\end{cfa}
     308\vfil
     309\end{minipage}
     310
     311%\subsection{Exception Details}
     312If one is only raising and handling exceptions, that is the only interface
     313that is needed. However it is actually a short hand for a more complex
     314trait based interface.
     315
     316The language views exceptions through a series of traits,
    255317if a type satisfies them, then it can be used as an exception. The following
    256318is the base trait all exceptions need to match.
Note: See TracChangeset for help on using the changeset viewer.