Changeset fcf3493


Ignore:
Timestamp:
Jul 30, 2024, 4:07:54 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
2ff76d25
Parents:
dd78dbc
Message:

update on thesis

Location:
doc/theses/jiada_liang_MMath
Files:
3 edited

Legend:

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

    rdd78dbc rfcf3493  
    114114\subsection{Value Conversion}
    115115C has an implicit type conversion from an enumerator to its base type @int@.
    116 Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type. The feature that allows Typed enumeration
    117 seemlyless used
     116Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type, allowing typed enumeration to be seemlyless used as
     117a value of its base type.
    118118\begin{cfa}
    119119char currency = Dollar;
     
    122122\end{cfa}
    123123
    124 During the resolution of expression e with \CFA enumeration type, \CFA adds @value(e)@ as an additional candidate with an extra \newterm{value} cost.
    125 For expression @char currency = Dollar@, the is no defined conversion from Dollar (\CFA enumeration) type to basic type and the conversion cost is @infinite@,
    126 thus the only valid candidate is @value(Dollar)@.
    127 
    128 @Value@ is a new category in \CFA's conversion cost model. It is defined to be a more significant factor than a @unsafe@ but weight less than @poly@.
    129 The resultin g conversion cost is a 8-tuple:
     124% During the resolution of expression e with \CFA enumeration type, \CFA adds @value(e)@ as an additional candidate with an extra \newterm{value} cost.
     125% For expression @char currency = Dollar@, the is no defined conversion from Dollar (\CFA enumeration) type to basic type and the conversion cost is @infinite@,
     126% thus the only valid candidate is @value(Dollar)@.
     127The implicit conversion induces a \newterm{value cost}, which is a new category in \CFA's conversion cost model to disambiguate function overloading over for both \CFA enumeration and its base type.
     128\begin{cfa}
     129void baz( char ch );            $\C{// (1)}$
     130void baz( Currency cu );        $\C{// (2)}$
     131
     132baz( Cent );
     133\end{cfa}
     134While both baz are applicable to \CFA enumeration, using Cent as a char in @candiate (1)@ comes with a @value@ cost,
     135while @candidate (2)@ has @zero@ cost. \CFA always choose a overloaded candidate implemented for a \CFA enumeration itself over a candidate applies on a base type.
     136
     137Value cost is defined to be a more significant factor than an @unsafe@ but weight less than @poly@.
     138With @value@ being an additional category, the current \CFA conversion cost is a 8-tuple:
    130139@@(unsafe, value, poly, safe, sign, vars, specialization, reference)@@.
    131140
     
    137146};
    138147
    139 Month a = Februrary;    // (1), with cost (0, 1, 0, 0, 0, 0, 0, 0)
    140 double a = 5.5;                 // (2), with cost (1, 0, 0, 0, 0, 0, 0, 0)
     148Month a = Februrary;    $\C{// (1), with cost (0, 1, 0, 0, 0, 0, 0, 0)}$
     149double a = 5.5;                 $\C{// (2), with cost (1, 0, 0, 0, 0, 0, 0, 0)}$
    141150
    142151bar(a);
     
    148157forall(T | @CfaEnum(T)@) void bar(T);
    149158
    150 bar(a);                                 // (3), with cost (0, 0, 1, 0, 0, 0, 0, 0)
     159bar(a);                                 $\C{// (3), with cost (0, 0, 1, 0, 0, 0, 0, 0)}$
    151160\end{cfa}
    152161% @Value@ is designed to be less significant than @poly@ to allow function being generic over \CFA enumeration (see ~\ref{c:trait}).
     
    192201\section{Enumeration Inheritance}
    193202
    194 \CFA Plan-9 inheritance may be used with enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C).
     203\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).
     204Inheritance can be nested, and a \CFA enumeration can inline enumerators from more than one \CFA enumeration, forming a tree-like structure.
     205Howver, the uniqueness of enumeration label applies to enumerators from supertypes, meaning an enumeration cannot name enumerator with the same label as its subtype's members, or inherits
     206from multiple enumeration that has overlapping enumerator label. As a consequence, a new type cannot inherits both an enumeration and its supertype, or inherit two enumerations with a
     207common supertype (the diamond problem), since such would unavoidably introduce duplicate enumerator labels.
    195208
    196209\begin{cfa}
     
    200213\end{cfa}
    201214
    202 Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Names@ by containment, and a @Names@ enumeration is a @subtype@ of enumeration @Name2@.
    203 Note, that enumerators must be unique in inheritance but enumerator values may be repeated.
     215% Enumeration @Name2@ inherits all the enumerators and their values from enumeration @Names@ by containment, and a @Names@ enumeration is a @subtype@ of enumeration @Name2@.
     216% Note, that enumerators must be unique in inheritance but enumerator values may be repeated.
     217
     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.
    204220
    205221% The enumeration type for the inheriting type must be the same as the inherited type;
     
    211227\end{cfa}
    212228
    213 Inlined from \CFA enumeration @O@, new enumeration @N@ copies all enumerators from @O@, including those @O@ obtains through inheritance. Enumerators inherited from @O@
    214 keeps same @label@ and @value@, but @position@ may shift to the right if other enumerators or inline enumeration declared in prior of @inline A@.
     229The enumeration type for the inheriting type must be the same as the inherited type.
     230When an enumeration inherits enumerators from another enumeration, it copies the enumerators' @value@ and @label@, even if the @value@ was auto initialized. However, the @position@ as the underlying
     231representation will be the order of the enumerator in new enumeration.
     232% new enumeration @N@ copies all enumerators from @O@, including those @O@ obtains through inheritance. Enumerators inherited from @O@
     233% keeps same @label@ and @value@, but @position@ may shift to the right if other enumerators or inline enumeration declared in prior of @inline A@.
     234% hence the enumeration type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for @Name3@.
     235% When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
     236
    215237\begin{cfa}
    216238enum() Phynchocephalia { Tuatara };
     
    220242Snake, for example, has the position 0 in Squamata, but 1 in Lepidosauromorpha as Tuatara inherited from Phynchocephalia is position 0 in Lepidosauromorpha.
    221243
    222 A subtype enumeration can be casted, or implicitly converted into its supertype, with a safe cost.
     244A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost.
    223245\begin{cfa}
    224246enum Squamata squamata_lizard = Lizard;
  • doc/theses/jiada_liang_MMath/background.tex

    rdd78dbc rfcf3493  
    157157\label{s:Usage}
    158158
    159 C proves an implicit \emph{bidirectional} conversion between an enumeration and its integral type.
     159C proves an implicit \emph{bidirectional} conversion between an enumeration and its integral type, and between two different enumeration.
    160160\begin{clang}
    161161enum Week week = Mon;                           $\C{// week == 0}$
     
    163163int i = Sun;                                            $\C{// implicit conversion to int, i == 13}$
    164164@week = 10000;@                                         $\C{// UNDEFINED! implicit conversion to Week}$
     165
     166enum Season {Spring, Summer, Fall, Winter };
     167@week = Winter;@                                        $\C{// UNDEFINED! implicit conversion to Week}$
    165168\end{clang}
    166169While converting an enumerator to its underlying type is useful, the implicit conversion from the base type to an enumeration type is a common source of error.
  • doc/theses/jiada_liang_MMath/conclusion.tex

    rdd78dbc rfcf3493  
    11\chapter{Conclusion}
     2\label{c:conclusion}
    23
    3 The goal of this thesis is to ...
     4The goal of this thesis is to adapt enumeration in \CFA to be aligned with the analogous features in
     5other languages while being backward-compatiable to C.
     6The presented features are based off on tools and techniques that widely used in
     7other languages but they were adapted to better fix \CFA's feature set. Additionally, the thesis provides
     8an improvement on safety and productivity of C enumeration, including enumerator overloading,
     9name scoping and type checking.
    410
    5 \section{Future Work}
     11To further explores the potential of enumerated types, this thesis presents a new \CFA enumeration
     12that is independent on C enumeration. The \CFA enumeration aims to solve the data harmonization problem
     13and have natural support to \CFA generic type, along with some new features that fit with \CFA's
     14programming pattern, such as enumerator conctrol structures.
     15
     16The \CFA project's test suite has been expanded to test the enumerations with respect to its
     17implicit conversions, inheritance, interaction with the polymorphic types, and the features
     18built on top of enumeration traits.
     19
     20The enumerated type is an attempt to adapt classic data types into \CFA unique type system. It brings
     21valuable new feature to \CFA in its own right, but also serve as a motivation to adapt other data types
     22in \CFA.
     23
     24% \section{Future Work}
     25
Note: See TracChangeset for help on using the changeset viewer.