Changeset c21f5a9 for doc/theses/andrew_beach_MMath/implement.tex
- Timestamp:
- May 20, 2021, 10:53:21 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 090a7c5
- Parents:
- 77f1265
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/implement.tex
r77f1265 rc21f5a9 71 71 72 72 \begin{cfa} 73 struct /* type name */{74 /* parent type name */const * parent;73 struct TYPE_ID_TYPE { 74 PARENT_ID_TYPE const * parent; 75 75 }; 76 76 77 __attribute__(( section(".gnu.linkonce./* instance name */")))78 /* type name */ const /* instance name */= {79 & /* parent instance name */,77 __attribute__((cfa_linkonce)) 78 TYPE_ID_TYPE const TYPE_ID_NAME = { 79 &PARENT_ID_NAME, 80 80 }; 81 81 \end{cfa} 82 83 \subsubsection{cfa\_linkonce Attribute} 84 Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}. 85 This attribute can be put on an object or function definition 86 (any global declaration with a name and a type). 87 This allows you to define that object or function multiple times. 88 All definitions should have the link-once attribute on them and all should 89 be identical. 90 91 The simplist way to use it is to put a definition in a header where the 92 forward declaration would usually go. 93 This is how it is used for type-id instances. There was is no unique location 94 associated with a type except for the type definition which is in a header. 95 This allows the unique type-id object to be generated there. 96 97 Internally @cfa_linkonce@ removes all @section@ attributes 98 from the declaration (as well as itself) and replaces them with 99 @section(".gnu.linkonce.NAME")@ where \texttt{NAME} is replaced by the 100 mangled name of the object. 101 The prefix \texttt{.gnu.linkonce} in section names is recognized by the 102 linker. If two of these sections with the same name, including everything 103 that comes after the special prefix, then only one will be used and the other 104 will be discarded. 82 105 83 106 \subsection{Virtual Table} … … 124 147 underlying object, access any of the virtual members and pass the object to 125 148 any of the method-like virtual members. 126 \todo{Introduce method-like virtual members.}127 149 128 150 When a virtual table is declared the user decides where to declare it and its … … 144 166 the instance is created as well. The definition of the virtual table is created 145 167 at the definition of the main function. 146 \todo{Add an example with code snipits.} 168 169 \begin{figure} 170 \begin{cfa} 171 coroutine Example { 172 // fields 173 } 174 \end{cfa} 175 176 \begin{cfa} 177 __attribute__((cfa_linkonce)) 178 struct __cfatid_struct_CoroutineCancelled(Example) 179 __cfatid_CoroutineCancelled = { 180 &EXCEPTION_TYPE_ID, 181 }; 182 extern CoroutineCancelled_vtable _default_vtable_object_declaration; 183 extern CoroutineCancelled_vtable & _default_vtable; 184 \end{cfa} 185 186 \begin{cfa} 187 void main(Example & this) { 188 // body 189 } 190 \end{cfa} 191 192 \begin{cfa} 193 CoroutineCancelled_vtable _default_vtable_object_declaration = { 194 __cfatid_CoroutineCancelled, 195 // Virtual member initialization. 196 }; 197 198 CoroutineCancelled_vtable & _default_vtable = 199 &_default_vtable_object_declaration; 200 \end{cfa} 201 \caption{Concurrency Transformations} 202 \label{f:ConcurrencyTransformations} 203 \end{figure} 204 \todo{Improve Concurrency Transformations figure.} 147 205 148 206 \subsection{Virtual Cast} … … 155 213 \begin{cfa} 156 214 void * __cfa__virtual_cast( 157 struct __cfa__parent_vtable const * parent, 158 struct __cfa__parent_vtable const * const * child ); 159 \end{cfa} 160 \todo{Get rid of \_\_cfa\_\_parent\_vtable in the standard library and then 161 the document.} 215 struct __cfavir_type_td parent, 216 struct __cfavir_type_id const * child ); 217 \end{cfa} 162 218 The type id of target type of the virtual cast is passed in as @parent@ and 163 219 the cast target is passed in as @child@. … … 572 628 the LSDA. 573 629 Using this pattern, \CFA implements destructors with the cleanup attribute. 574 \todo{Add an example of the conversion from try statement to functions.} 630 631 \begin{figure} 632 \begin{cfa} 633 try { 634 // TRY BLOCK 635 } catch (Exception1 * name1 ; check(name1)) { 636 // CATCH BLOCK 1 637 } catch (Exception2 * name2) { 638 // CATCH BLOCK 2 639 } 640 \end{cfa} 641 642 \begin{cfa} 643 void try(void) { 644 // TRY BLOCK 645 } 646 int match(exception_t * __exception_inst) { 647 { 648 Exception1 * name1; 649 if (name1 = (virtual Exception1 *)__exception_inst && check(name1)) { 650 return 1; 651 } 652 } 653 { 654 Exception2 * name2; 655 if (name2 = (virtual Exception2 *)__exception_inst) { 656 return 2; 657 } 658 } 659 return 0; 660 } 661 void catch(exception_t * __exception_inst, int __handler_index) { 662 switch (__handler_index) { 663 case 1: 664 { 665 Exception1 * name1 = (virtual Exception1 *)__exception_inst; 666 // CATCH BLOCK 1 667 } 668 return; 669 case 2: 670 { 671 Exception2 * name2 = (virtual Exception2 *)__exception_inst; 672 // CATCH BLOCK 2 673 } 674 return; 675 } 676 } 677 { 678 __cfaehm_try_terminate(try, catch, match); 679 } 680 \end{cfa} 681 682 \caption{Termination Transformation} 683 \label{f:TerminationTransformation} 684 \todo*{Improve (compress?) Termination Transformations.} 685 \end{figure} 575 686 576 687 \section{Resumption} … … 606 717 the next clause the function returns false as no handler could be found. 607 718 608 \todo{Diagram showing a try statement being converted into resumption handlers.} 719 \begin{figure} 720 \begin{cfa} 721 try { 722 // TRY BLOCK 723 } catchResume (Exception1 * name1 ; check(name1)) { 724 // CATCH BLOCK 1 725 } catchResume (Exception2 * name2) { 726 // CATCH BLOCK 2 727 } 728 \end{cfa} 729 730 \begin{cfa} 731 bool handle(exception_t * __exception_inst) { 732 { 733 Exception1 * name1; 734 if (name1 = (virtual Exception1 *)__exception_inst && check(name1)) { 735 // CATCH BLOCK 1 736 return 1; 737 } 738 } 739 { 740 Exception2 * name2; 741 if (name2 = (virtual Exception2 *)__exception_inst) { 742 // CATCH BLOCK 2 743 return 2; 744 } 745 } 746 return false; 747 } 748 struct __try_resume_node __resume_node 749 __attribute__((cleanup( __cfaehm_try_resume_cleanup ))); 750 __cfaehm_try_resume_setup( &__resume_node, handler ); 751 \end{cfa} 752 753 \caption{Resumption Transformation} 754 \label{f:ResumptionTransformation} 755 \todo*{Improve (compress?) Resumption Transformations.} 756 \end{figure} 609 757 610 758 % Recursive Resumption Stuff: … … 625 773 stack -- the first one points over all the checked handlers -- and the ordering 626 774 is maintained. 627 \todo{Add a diagram for resumption marking.} 775 776 \begin{figure} 777 \begin{minipage}[l][][b]{0,2\textwidth} 778 \begin{verbatim} 779 780 781 X <- 782 | 783 V 784 X 785 | 786 V 787 X 788 \end{verbatim} 789 Initial State 790 \end{minipage} 791 \begin{minipage}[l][][b]{0,2\textwidth} 792 \begin{verbatim} 793 794 795 X 796 | 797 V 798 X <- 799 | 800 V 801 X 802 \end{verbatim} 803 Handler Found 804 \end{minipage} 805 \begin{minipage}[l][][b]{0,2\textwidth} 806 \begin{verbatim} 807 X <- 808 / 809 / X 810 | | 811 \ V 812 X 813 | 814 V 815 X 816 \end{verbatim} 817 Try Block Added 818 \end{minipage} 819 \begin{minipage}[l][][b]{0,2\textwidth} 820 \begin{verbatim} 821 822 823 X <- 824 | 825 V 826 X 827 | 828 V 829 X 830 \end{verbatim} 831 Handler Done 832 \end{minipage} 833 \caption{Resumption Marking} 834 \label{f:ResumptionMarking} 835 \todo*{Convert Resumption Marking into a line figure.} 836 \end{figure} 628 837 629 838 \label{p:zero-cost}
Note: See TracChangeset
for help on using the changeset viewer.