Changeset ed4d7c1

Aug 18, 2021, 6:57:55 PM (3 years ago)
Andrew Beach <ajbeach@…>
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum

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

1 edited


  • doc/theses/andrew_beach_MMath/features.tex

    re3984a68 red4d7c1  
    233233through the object.
     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:
     239vtable(virtual_type_name) table_name;
     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
     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.
     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.
    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).
    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.
    254 Exceptions are defined by the trait system; there are a series of traits, and
     275The syntax for declaring an exception is the same as declaring a structure
     276except the keyword that is swapped out:
     278exception TYPE_NAME {
     279        FIELDS
     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
     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.
     295exception Example {
     296        int data;
     299extern vtable(Example)
     300        example_base_vtable;
     306vtable(Example) example_base_vtable
     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.
     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.