Changeset fcf3493 for doc/theses/jiada_liang_MMath
- Timestamp:
- Jul 30, 2024, 4:07:54 PM (5 months ago)
- Branches:
- master
- Children:
- 2ff76d25
- Parents:
- dd78dbc
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rdd78dbc rfcf3493 114 114 \subsection{Value Conversion} 115 115 C 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 enumeration117 seemlyless used116 Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type, allowing typed enumeration to be seemlyless used as 117 a value of its base type. 118 118 \begin{cfa} 119 119 char currency = Dollar; … … 122 122 \end{cfa} 123 123 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)@. 127 The 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} 129 void baz( char ch ); $\C{// (1)}$ 130 void baz( Currency cu ); $\C{// (2)}$ 131 132 baz( Cent ); 133 \end{cfa} 134 While both baz are applicable to \CFA enumeration, using Cent as a char in @candiate (1)@ comes with a @value@ cost, 135 while @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 137 Value cost is defined to be a more significant factor than an @unsafe@ but weight less than @poly@. 138 With @value@ being an additional category, the current \CFA conversion cost is a 8-tuple: 130 139 @@(unsafe, value, poly, safe, sign, vars, specialization, reference)@@. 131 140 … … 137 146 }; 138 147 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)148 Month a = Februrary; $\C{// (1), with cost (0, 1, 0, 0, 0, 0, 0, 0)}$ 149 double a = 5.5; $\C{// (2), with cost (1, 0, 0, 0, 0, 0, 0, 0)}$ 141 150 142 151 bar(a); … … 148 157 forall(T | @CfaEnum(T)@) void bar(T); 149 158 150 bar(a); // (3), with cost (0, 0, 1, 0, 0, 0, 0, 0)159 bar(a); $\C{// (3), with cost (0, 0, 1, 0, 0, 0, 0, 0)}$ 151 160 \end{cfa} 152 161 % @Value@ is designed to be less significant than @poly@ to allow function being generic over \CFA enumeration (see ~\ref{c:trait}). … … 192 201 \section{Enumeration Inheritance} 193 202 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). 204 Inheritance can be nested, and a \CFA enumeration can inline enumerators from more than one \CFA enumeration, forming a tree-like structure. 205 Howver, 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 206 from 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 207 common supertype (the diamond problem), since such would unavoidably introduce duplicate enumerator labels. 195 208 196 209 \begin{cfa} … … 200 213 \end{cfa} 201 214 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. 204 220 205 221 % The enumeration type for the inheriting type must be the same as the inherited type; … … 211 227 \end{cfa} 212 228 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@. 229 The enumeration type for the inheriting type must be the same as the inherited type. 230 When 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 231 representation 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 215 237 \begin{cfa} 216 238 enum() Phynchocephalia { Tuatara }; … … 220 242 Snake, for example, has the position 0 in Squamata, but 1 in Lepidosauromorpha as Tuatara inherited from Phynchocephalia is position 0 in Lepidosauromorpha. 221 243 222 A subtype enumeration can be casted, or implicitly converted into its supertype, with a safecost.244 A subtype enumeration can be casted, or implicitly converted into its supertype, with a @safe@ cost. 223 245 \begin{cfa} 224 246 enum Squamata squamata_lizard = Lizard; -
doc/theses/jiada_liang_MMath/background.tex
rdd78dbc rfcf3493 157 157 \label{s:Usage} 158 158 159 C proves an implicit \emph{bidirectional} conversion between an enumeration and its integral type .159 C proves an implicit \emph{bidirectional} conversion between an enumeration and its integral type, and between two different enumeration. 160 160 \begin{clang} 161 161 enum Week week = Mon; $\C{// week == 0}$ … … 163 163 int i = Sun; $\C{// implicit conversion to int, i == 13}$ 164 164 @week = 10000;@ $\C{// UNDEFINED! implicit conversion to Week}$ 165 166 enum Season {Spring, Summer, Fall, Winter }; 167 @week = Winter;@ $\C{// UNDEFINED! implicit conversion to Week}$ 165 168 \end{clang} 166 169 While 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 1 1 \chapter{Conclusion} 2 \label{c:conclusion} 2 3 3 The goal of this thesis is to ... 4 The goal of this thesis is to adapt enumeration in \CFA to be aligned with the analogous features in 5 other languages while being backward-compatiable to C. 6 The presented features are based off on tools and techniques that widely used in 7 other languages but they were adapted to better fix \CFA's feature set. Additionally, the thesis provides 8 an improvement on safety and productivity of C enumeration, including enumerator overloading, 9 name scoping and type checking. 4 10 5 \section{Future Work} 11 To further explores the potential of enumerated types, this thesis presents a new \CFA enumeration 12 that is independent on C enumeration. The \CFA enumeration aims to solve the data harmonization problem 13 and have natural support to \CFA generic type, along with some new features that fit with \CFA's 14 programming pattern, such as enumerator conctrol structures. 15 16 The \CFA project's test suite has been expanded to test the enumerations with respect to its 17 implicit conversions, inheritance, interaction with the polymorphic types, and the features 18 built on top of enumeration traits. 19 20 The enumerated type is an attempt to adapt classic data types into \CFA unique type system. It brings 21 valuable new feature to \CFA in its own right, but also serve as a motivation to adapt other data types 22 in \CFA. 23 24 % \section{Future Work} 25
Note: See TracChangeset
for help on using the changeset viewer.