Ignore:
Timestamp:
Aug 4, 2024, 12:23:00 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
7ab24fef
Parents:
a57ad8a (diff), 065de93 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
doc/theses/jiada_liang_MMath
Files:
3 edited

Legend:

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

    ra57ad8a r748877f  
    202202
    203203\CFA Plan-9 inheritance may be used with \CFA enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C).
     204Containment is norminative: an enumeration inherits all enumerators from another enumeration by declaring an @inline statement@ in its enumerator lists.
     205\begin{cfa}
     206enum( char * ) Names { /* as above */ };
     207enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
     208enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
     209\end{cfa}
     210In the preceding example, @Names2@ is defined with five enumerators, three of which are from @Name@ through containment, and two are self-declared.
     211@Names3@ inherits all five members from @Names2@ and declare two additional enumerators.
     212
     213Enumeration inheritance forms a subset relationship. Specifically, the inheritance relationship for the example above is:
     214\begin{cfa}
     215Names $\(\subset\)$ Names2 $\(\subset\)$ Names3 $\C{// enum type of Names}$
     216\end{cfa}
     217
    204218Inheritance can be nested, and a \CFA enumeration can inline enumerators from more than one \CFA enumeration, forming a tree-like hierarchy.
    205219However, the uniqueness of enumeration name applies to enumerators, including those from supertypes, meaning an enumeration cannot name enumerator with the same label as its subtype's members, or inherits
     
    207221common supertype (the diamond problem), since such would unavoidably introduce duplicate enumerator labels.
    208222
    209 \begin{cfa}
    210 enum( char * ) Names { /* as above */ };
    211 enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
    212 enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
    213 \end{cfa}
    214223
    215224% Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Names@ by containment, and a @Names@ enumeration is a @subtype@ of enumeration @Name2@.
    216225% Note, that enumerators must be unique in inheritance but enumerator values may be repeated.
    217226
    218 @Names2@ is defined with five enumerators, three of which are from @Name@ through containment, and two are self-declared.
    219 @Names3@ inherits all five members from @Names2@ and declare two additional enumerators.
     227
    220228
    221229% The enumeration type for the inheriting type must be the same as the inherited type;
    222230% hence the enumeration type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for @Name3@.
    223231% When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
    224 Specifically, the inheritance relationship for @Names@ is:
    225 \begin{cfa}
    226 Names $\(\subset\)$ Names2 $\(\subset\)$ Names3 $\C{// enum type of Names}$
    227 \end{cfa}
     232
    228233
    229234% The enumeration base for the subtype must be the same as the super type.
  • doc/theses/jiada_liang_MMath/background.tex

    ra57ad8a r748877f  
    232232While C provides a true enumeration, it is restricted, has unsafe semantics, and does not provide useful/advanced enumeration features found in other programming languages.
    233233
     234\section{\CFA Polymorphism}
     235
     236\subsection{Function Overloading}
     237Function overloading is programming languages feature wherein functions may share the same name, but with different function signatures. In both C++ and \CFA, function names can be overloaded
     238with different entities as long as they are different in terms of the number and type of parameters.
    234239
    235240\section{\CFA}
     
    387392The assertion on @T@ restricts the range of types that can be manipulated by @bar@ to only those that have an implementation of @foo@ with the matching signature, allowing @bar@'s call to @foo@ in its body.
    388393
     394\subsection{Trait}
     395A @forall@ clause can asserts on multiple types and with multiple asserting functions. A common practice in \CFA is to group
     396the asserting functions in to a named \newterm{trait}.
    389397
    390398\subsection{Trait}
     
    464472
    465473In the next iteration of \CFA, Schluntz and Aaron~\cite{Moss18} expanded conversion cost to a 7-tuple with 4 additional categories, @(unsafe, poly, safe, sign, vars, specialization, reference)@, with the following interpretations:
    466 \begin{enumerate}
    467 \item @unsafe@ from Bilson
    468 \item @poly@
    469 \item @safe@
    470 \item @sign@ is the number of sign/unsigned variable conversions
    471 \item @vars@ is the number of polymorphic type variables
    472 \item @specialization@ is a negative value of the number of type assertions
    473 \item @reference@ is the number of reference-to-rvalue conversions
    474 \end{enumerate}
     474\begin{itemize}
     475\item \textit{Unsafe}
     476\item \textit{Poly}
     477\item \textit{Safe}
     478\item \textit{Sign} is the number of sign/unsign variable conversion.
     479\item \textit{Vars} is the number of polymorphics type variable.
     480\item \textit{Specialization} is negative value of the number of type assertion.
     481\item \textit{Reference} is number of reference-to-rvalue conversion.
     482\end{itemize}
    475483The extended conversion-cost model looks for candidates that are more specific and less generic.
    476484@vars@ disambiguates @forall( T, V ) foo( T, V )@ and @forall( T ) void foo( T, T )@, where the extra type parameter @V@ makes is more generic.
     
    483491\CFA defines two special cost values: @zero@ and @infinite@.
    484492A conversion cost is @zero@ when argument and parameter has an exact match, and a conversion cost is @infinite@ when there is no defined conversion between two types.
    485 For example, the conversion cost from @int@ to a @struct S@ is @infinite@.
     493For example, the conversion cost from @int@ to a @struct S@ is @infinite@.
     494
     495In \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.
     496Cast cost exists as an independent matrix for conversion that cannot happen implcitly, while being possible with an explicit cast. These conversions are often defined to have
     497infinite conversion cost and non-infinite cast cost.
  • doc/theses/jiada_liang_MMath/planet.cfa

    ra57ad8a r748877f  
    3333        double earthMass = earthWeight / surfaceGravity( EARTH );
    3434
    35         Planet p = fromInt( prng( __count_e__( Planet ) ) ); // select a random orbiting body
     35        Planet p = fromInt( prng( countof( Planet ) ) ); // select a random orbiting body
    3636//      Planet p = fromInt( prng( 9 ) ); // select a random orbiting body
    3737        choose( p ) {
    3838          case MERCURY, VENUS, EARTH, MARS:
    39                 sout | labelE( p ) | "is a rocky planet";
     39                sout | label( p ) | "is a rocky planet";
    4040          case JUPITER, SATURN, URANUS, NEPTUNE:
    41                 sout | labelE( p ) | "is a gas-giant planet";
     41                sout | label( p ) | "is a gas-giant planet";
    4242          default:
    43                 sout | labelE( p ) | "is not a planet";
     43                sout | label( p ) | "is not a planet";
    4444        }
    4545
    4646
    47         for ( p; enum Planet ) {
     47        for ( p; Planet ) {
    4848                sout | "Your weight on "
    49                  | (p == MOON ? "the" : "") | labelE(p)
     49                 | (p == MOON ? "the" : "") | label(p)
    5050                         | "is" | wd( 1,1, surfaceWeight( p, earthMass ) ) | "kg";
    5151        }
Note: See TracChangeset for help on using the changeset viewer.