Changeset 3b10778 for doc/theses


Ignore:
Timestamp:
Aug 7, 2024, 9:12:14 AM (9 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
4e09af2
Parents:
f6bbc92
Message:

small proofreading updates

Location:
doc/theses/jiada_liang_MMath
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    rf6bbc92 r3b10778  
    202202An enumeration's type can be another enumeration.
    203203\begin{cfa}
    204 enum( char ) Letter { A = 'A', ... };
    205 enum( @Letter@ ) Greek { Alph = A, Beta = B, ... }; // alphabet intersection
    206 
    207 void foo(Letter l);
    208 foo(Beta);                      $\C{// foo(value(Beta))}$
    209 \end{cfa}
    210 Enumeration @Greek@ may have more or less enumerators than @Letter@, but the enum values \emph{must} be of a member of @Letter@.
    211 Therefore, the set of @Greek@ enum value in a subset of the value set of type @Letter@.
    212 @Letter@ is type compatible with enumeration @Letter@ thanks to \CFA inserts value conversion whenever @Letter@ be used
    213 in place of @Greek@. On the other hand, @Letter@ enums are not type compatible with enumeration @Greek@.
    214 As a result, @Greek@ becomes a logical subtype of @Letter@.
    215 
    216 Subset defines an implicit subtyping relationship between two \CFA enumerations. \CFA also has
    217 containment inheritance for \CFA enumerations where subtyping is explicitly structured.
     204enum( char ) Letter { A = 'A', ..., Z = 'Z' };
     205enum( @Letter@ ) Greek { Alph = @A@, Beta = @B@, Gamma = @G@, ..., Zeta = @Z@ }; // alphabet intersection
     206\end{cfa}
     207Enumeration @Greek@ may have more or less enumerators than @Letter@, but its enumerator values \emph{must} be from @Letter@.
     208Therefore, the set of @Greek@ enumerator values in a subset of the @Letter@ enumerator values.
     209@Letter@ is type compatible with enumeration @Letter@ because value conversions are inserted whenever @Letter@ is used in place of @Greek@.
     210\begin{cfa}
     211Letter l = A;                                           $\C{// allowed}$
     212Greek g = Alph;                                         $\C{// allowed}$
     213l = Alph;                                                       $\C{// allowed, conversion to base type}$
     214g = A;                                                          $\C{// {\color{red}disallowed}}$
     215void foo( Letter );
     216foo( Beta );                                            $\C{// allowed, conversion to base type}$
     217void bar( Greek );
     218bar( A );                                                       $\C{// {\color{red}disallowed}}$
     219\end{cfa}
     220Hence, @Letter@ enumerators are not type compatible with the @Greek@ enumeration but the reverse is true.
     221
    218222
    219223\section{Inheritance}
     
    223227Containment is nominative: an enumeration inherits all enumerators from another enumeration by declaring an @inline statement@ in its enumerator lists.
    224228\begin{cfa}
    225 enum( char * ) Names { /* $\see{\VRef[Figure]{f:EumeratorTyping}}$ */ };
     229enum( char * ) Names { /* $\see{\VRef[Figure]{f:EumeratorTyping}}$ */  };
    226230enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
    227231enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
     
    244248However, the position of the underlying representation is the order of the enumerator in the new enumeration.
    245249\begin{cfa}
    246 enum() E1 { B };                                                                $\C{// B}$                                             
    247 enum() E2 { C, D };                                                             $\C{// C D}$
    248 enum() E3 { inline E1, inline E2, E };                  $\C{// {\color{red}[\(_{E1}\)} B {\color{red}]} {\color{red}[\(_{E2}\)} C D {\color{red}]} E}$
    249 enum() E4 { A, inline E3, F};                                   $\C{// A {\color{blue}[\(_{E3}\)} {\color{red}[\(_{E1}\)} B {\color{red}]} {\color{red}[\(_{E2}\)} C D {\color{red}]} E {\color{blue}]} F }$
    250 \end{cfa}
    251 In the example above, @B@ has the position 0 in @E1@ and @E3@, but it at the position 1 in @E4@ as @A@ taking the 0 in @E4@.
    252 @C@ is at the position 0 in @E2@, 1 in @E3@ and 2 in E4. @D@ is at the position 1 in @E2@, 2 in @E3@ and 3 in @E4@.
    253 
    254 A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost. Such conversion is an @enumeration conversion@.
     250enum() E1 { B };                                                                        $\C{// B}$                                             
     251enum() E2 { C, D };                                             $\C{// C D}$
     252enum() E3 { inline E1, inline E2, E };  $\C{// {\color{red}[\(_{E1}\)} B {\color{red}]} {\color{red}[\(_{E2}\)} C D {\color{red}]} E}$
     253enum() E4 { A, inline E3, F};                   $\C{// A {\color{blue}[\(_{E3}\)} {\color{red}[\(_{E1}\)} B {\color{red}]} {\color{red}[\(_{E2}\)} C D {\color{red}]} E {\color{blue}]} F}$
     254\end{cfa}
     255In the example, @B@ is at position 0 in @E1@ and @E3@, but position 1 in @E4@ as @A@ takes position 0 in @E4@.
     256@C@ is at position 0 in @E2@, 1 in @E3@, and 2 in @E4@.
     257@D@ is at position 1 in @E2@, 2 in @E3@, and 3 in @E4@.
     258
     259A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost, called \newterm{enumeration conversion}.
    255260\begin{cfa}
    256261enum E2 e2 = C;
    257262posn( e2 );                     $\C[1.75in]{// 0}$
    258263enum E3 e3 = e2;
    259 posn( e2 );                     $\C{// 1}$
     264posn( e2 );                     $\C{// 1 cost}$
    260265void foo( E3 e );
    261266foo( e2 );
    262 posn( (E3)e2 );         $\C{// 1}$
     267posn( (E3)e2 );         $\C{// 1 cost}$
    263268E3 e31 = B;
    264 posn( e31 );            $\C{// 0}\CRT$
     269posn( e31 );            $\C{// 0 cost}\CRT$
    265270\end{cfa}
    266271The last expression is unambiguous.
    267 While both @E2.B@ and @E3.B@ are valid candidate, @E2.B@ has an associated safe cost and \CFA selects the zero cost candidate @E3.B@.
     272While both @E2.B@ and @E3.B@ are valid candidates, @E2.B@ has an associated safe cost, so \CFA selects the zero cost candidate.
    268273
    269274For the given function prototypes, the following calls are valid.
     
    287292Note, the validity of calls is the same for call-by-reference as for call-by-value, and @const@ restrictions are the same as for other types.
    288293
     294
    289295\subsection{Offset Calculation}
     296
    290297As discussed in \VRef{s:OpaqueEnum}, \CFA chooses position as a representation of a \CFA enumeration variable.
    291 Because enumerators has different @position@ between subtype and supertype, \CFA might need to manipulate the representation whenever a cast or
    292 implicit conversion involves two \CFA enums. \CFA determine how a position is going to change with an @offset calculation@ function, reflects to
    293 enumerator as an arithmetic expression. Casting an enumeration of subtype to a supertype, the position can be unchanged or increase. The change
    294 of position is an @offset@. 
     298When a cast or implicit conversion moves an enumeration from subtype to supertype, the position can be unchanged or increase.
     299\CFA determines the position offset with an \newterm{offset calculation} function.
    295300
    296301\begin{figure}
     
    301306pair<bool, int> calculateEnumOffset(CFAEnum src, CFAEnum dst) {
    302307        int offset = 0;
    303         if (src == dst) return make_pair(true, 0);
    304         for (auto v : dst.members) {
    305                 if (holds_alternative<Enumerator>(v)) {
     308        if ( src == dst ) return make_pair(true, 0);
     309        for ( auto v : dst.members ) {
     310                if ( holds_alternative<Enumerator>(v) ) {
    306311                        offset++;
    307312                } else {
    308313                        auto m = get<CFAEnum>(v);
    309                         if (m == src) return make_pair(true, offset);
    310                         auto dist = calculateEnumOffset(src, m);
    311                         if (dist.first) {
    312                                 return make_pair(true, offset + dist.second);
     314                        if ( m == src ) @return@ make_pair( true, offset );
     315                        auto dist = calculateEnumOffset( src, m );
     316                        if ( dist.first ) {
     317                                @return@ make_pair( true, offset + dist.second );
    313318                        } else {
    314319                                offset += dist.second;
     
    316321                }
    317322        }
    318         return make_pair(false, offset);
     323        @return@ make_pair( false, offset );
    319324}
    320325\end{cfa}
     
    323328\end{figure}
    324329
    325 Figure~\ref{s:OffsetSubtypeSuperType} shows a minimum of @offset calculation@, written in \CC. CFAEnum represents \CFA enumeration
    326 which has a vector of variants of Enumerator or CFAEnum. Two CFAEnums are differentiable by their unquie name.
    327 The algorithm takes two CFAEnums as parameters @src@ and @dst@, with @src@ being type of expression the conversion applies on,
    328 and @dst@ being type that the expression cast into. The algorithm returns a pair of value: when @src@ is convertible to @dst@ (@src@ is a subtype of @dst@),
    329 it returns boolean true and the offset. Otherwise, it returns false and the size of @src@ (total number of enumerators in @src@). The offset between a type and itself is defined
    330 as 0.
    331 
    332 The algorithm iterates over members in @dst@ to find @src@. If a member is an enumerator of @dst@, the positions of all subsequent members
    333 increment by one. If the current member is @dst@, the function returns true indicating "found" and the accumulated offset. Otherwise, the algorithm recurse
    334 into the current CFAEnum @m@ and find out if the @src@ is convertible to @m@. The @src@ being convertible to the current member @m@ means @src@
    335 is a "subtype of subtype" of @dst@. The offset between @src@ and @dst@ is the sum of the offset of @m@ in @dst@ and the offset of
    336 @src@ in @m@. If @src@ is not a subtype of @m@, the loop continue but with offset shifted by the size of @m@. The procedure reaches the end
    337 of the loop proves @src@ is not convertible to @dst@. It returns size of @src@ in case it is in a recurse innvocation and size is needed for offset update.
     330Figure~\ref{s:OffsetSubtypeSuperType} shows an outline of the offset calculation in \CC.
     331Structure @CFAEnum@ represents the \CFA enumeration with a vector of variants of @CFAEnum@ or @Enumerator@.
     332The algorithm takes two @CFAEnums@ parameters, @src@ and @dst@, with @src@ being the type of expression the conversion applies to, and @dst@ being the type the expression is cast to.
     333The algorithm iterates over the members in @dst@ to find @src@.
     334If a member is an enumerator of @dst@, the positions of all subsequent members is increment by one.
     335If the current member is @dst@, the function returns true indicating \emph{found} and the accumulated offset.
     336Otherwise, the algorithm recurses into the current @CFAEnum@ @m@ to check if its @src@ is convertible to @m@.
     337If @src@ is convertible to the current member @m@, this means @src@ is a subtype-of-subtype of @dst@.
     338The offset between @src@ and @dst@ is the sum of the offset of @m@ in @dst@ and the offset of @src@ in @m@.
     339If @src@ is not a subtype of @m@, the loop continues but with the offset shifted by the size of @m@.
     340If the loop ends, than @src@ is not convertible to @dst@, and false is returned.
     341
    338342
    339343\section{Control Structures}
  • doc/theses/jiada_liang_MMath/background.tex

    rf6bbc92 r3b10778  
    486486For example, the conversion cost from @int@ to a @struct S@ is @infinite@.
    487487
    488 In \CFA, the meaning of a C style cast is determined by its @Cast Cost@. For most cast expression resolution, a cast cost is equal to a conversion cost.
    489 Cast cost exists as an independent matrix for conversion that cannot happen implicitly, while being possible with an explicit cast. These conversions are often defined to have
    490 infinite conversion cost and non-infinite cast cost.
     488In \CFA, the meaning of a C-style cast is determined by its @Cast Cost@.
     489For most cast-expression resolution, a cast cost is equal to a conversion cost.
     490Cast cost exists as an independent matrix for conversion that cannot happen implicitly, while being possible with an explicit cast.
     491These conversions are often defined to have infinite conversion cost and non-infinite cast cost.
  • doc/theses/jiada_liang_MMath/intro.tex

    rf6bbc92 r3b10778  
    307307generalization: Support all language types for enumerators with associated values providing enumeration constants for any type.
    308308\item
    309 inheritance: Implement subtyping and containment inheritance for enumerations.
     309reuse: Implement subset and containment inheritance for enumerations.
    310310\item
    311311control flow: Extend control-flow structures making it safer and easier to enumerate over an enumeration.
Note: See TracChangeset for help on using the changeset viewer.