Changeset e8bad5c8


Ignore:
Timestamp:
Aug 25, 2021, 2:31:27 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
jacob/cs343-translation, master
Children:
cfbab07
Parents:
ba2e8f0
Message:

Andrew MMath: Added implementation notes for the new virtual and exception syntax.

File:
1 edited

Legend:

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

    rba2e8f0 re8bad5c8  
    1414\label{s:VirtualSystem}
    1515% Virtual table rules. Virtual tables, the pointer to them and the cast.
    16 While the \CFA virtual system currently has only one public feature, virtual
    17 cast (see the virtual cast feature \vpageref{p:VirtualCast}),
    18 substantial structure is required to support it,
     16While the \CFA virtual system currently has only one public features, virtual
     17cast and virtual tables,
     18% ??? refs (see the virtual cast feature \vpageref{p:VirtualCast}),
     19substantial structure is required to support them,
    1920and provide features for exception handling and the standard library.
    2021
     
    215216type's alignment, is set using an @alignof@ expression.
    216217
     218Most of these tools are already inside the compiler. Using the is a simple
     219code transformation early on in compilation allows most of that work to be
     220handed off to the existing tools. \autoref{f:VirtualTableTransformation}
     221shows an example transformation, this example shows an exception virtual table.
     222It also shows the transformation on the full declaration,
     223for a forward declaration the @extern@ keyword is preserved and the
     224initializer is not added.
     225
     226\begin{figure}[htb]
     227\begin{cfa}
     228vtable(example_type) example_name;
     229\end{cfa}
     230\transformline
     231% Check mangling.
     232\begin{cfa}
     233const struct example_type_vtable example_name = {
     234        .__cfavir_typeid : &__cfatid_example_type,
     235        .size : sizeof(example_type),
     236        .copy : copy,
     237        .^?{} : ^?{},
     238        .msg : msg,
     239};
     240\end{cfa}
     241\caption{Virtual Table Transformation}
     242\label{f:VirtualTableTransformation}
     243\end{figure}
     244
    217245\subsection{Concurrency Integration}
    218246Coroutines and threads need instances of @CoroutineCancelled@ and
     
    251279\end{figure}
    252280
    253 \begin{figure}
     281\begin{figure}[htb]
    254282\begin{cfa}
    255283void main(Example & this) {
     
    300328
    301329\section{Exceptions}
    302 \todo{The entire exceptions section.}
     330% The implementation of exception types.
     331
     332Creating exceptions can roughly divided into two parts,
     333the exceptions themselves and the virtual system interactions.
     334
     335Creating an exception type is just a matter of preppending the field 
     336with the virtual table pointer to the list of the fields
     337(see \autoref{f:ExceptionTypeTransformation}).
     338
     339\begin{figure}[htb]
     340\begin{cfa}
     341exception new_exception {
     342        // EXISTING FIELDS
     343};
     344\end{cfa}
     345\transformline
     346\begin{cfa}
     347struct new_exception {
     348        struct new_exception_vtable const * virtual_table;
     349        // EXISTING FIELDS
     350};
     351\end{cfa}
     352\caption{Exception Type Transformation}
     353\label{f:ExceptionTypeTransformation}
     354\end{figure}
     355
     356The integration between exceptions and the virtual system is a bit more
     357complex simply because of the nature of the virtual system prototype.
     358The primary issue is that the virtual system has no way to detect when it
     359should generate any of its internal types and data. This is handled by
     360the exception code, which tells the virtual system when to generate
     361its components.
     362
     363All types associated with a virtual type,
     364the types of the virtual table and the type id,
     365are generated when the virtual type (the exception) is first found.
     366The type id (the instance) is generated with the exception if it is
     367a monomorphic type.
     368However if the exception is polymorphic then a different type id has to
     369be generated for every instance. In this case generation is delayed
     370until a virtual table is created.
     371% There are actually some problems with this, which is why it is not used
     372% for monomorphic types.
     373When a virtual table is created and initialized two functions are created
     374to fill in the list of virtual members.
     375The first is a copy function which adapts the exception's copy constructor
     376to work with pointers, avoiding some issues with the current copy constructor
     377interface.
     378Second is the msg function, which returns a C-string with the type's name,
     379including any polymorphic parameters.
    303380
    304381\section{Unwinding}
Note: See TracChangeset for help on using the changeset viewer.