Changeset e8bad5c8

Aug 25, 2021, 2:31:27 PM (2 years ago)
Andrew Beach <ajbeach@…>
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum

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

1 edited


  • doc/theses/andrew_beach_MMath/implement.tex

    rba2e8f0 re8bad5c8  
    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.
    215216type's alignment, is set using an @alignof@ expression.
     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.
     228vtable(example_type) example_name;
     231% Check mangling.
     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,
     241\caption{Virtual Table Transformation}
    217245\subsection{Concurrency Integration}
    218246Coroutines and threads need instances of @CoroutineCancelled@ and
    253 \begin{figure}
    255283void main(Example & this) {
    302 \todo{The entire exceptions section.}
     330% The implementation of exception types.
     332Creating exceptions can roughly divided into two parts,
     333the exceptions themselves and the virtual system interactions.
     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}).
     341exception new_exception {
     342        // EXISTING FIELDS
     347struct new_exception {
     348        struct new_exception_vtable const * virtual_table;
     349        // EXISTING FIELDS
     352\caption{Exception Type Transformation}
     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.
     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
     378Second is the msg function, which returns a C-string with the type's name,
     379including any polymorphic parameters.
Note: See TracChangeset for help on using the changeset viewer.