Changeset acab1bd for doc/theses/jiada_liang_MMath/CFAenum.tex
- Timestamp:
- Aug 8, 2024, 11:19:51 PM (10 hours ago)
- Branches:
- master
- Children:
- f125e96
- Parents:
- 7568e5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r7568e5c racab1bd 179 179 180 180 \section{Auto Initialization} 181 \CFA implements auto-initialization for both C enumerations and \CFA enumerations. For the first category, the semantics is consistent with C: 182 % A partially implemented feature is auto-initialization, which works for the C integral type with constant expressions. 183 \begin{cfa} 184 enum Week { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun }; // 0-2, 10-13 185 \end{cfa} 186 % The complexity of the constant expression depends on the level of computation the compiler implements, \eg \CC \lstinline[language={[GNU]C++}]{constexpr} provides complex compile-time computation across multiple types, which blurs the compilation/runtime boundary. 187 188 % If \CFA had powerful compilation expression evaluation, auto initialization would be implemented as follows. 181 \CFA extends C's auto-initialization scheme to \CFA enumeration. For an enumeration type with base type T, the initialization scheme is the following: 182 \begin{enumerate} 183 \item the first enumerator is initialized with @T@'s @zero_t@. 184 \item Every other enumerator is initialized with its previous enumerator's value "+1", where "+1" is defined in terms of overloaded operator @?+?(T, one_t)@. 185 \end{enumerate} 189 186 190 187 \begin{cfa} … … 194 191 enum(S) E { A, B, C, D }; 195 192 \end{cfa} 196 For \CFA enumeration, the semantics is the following:197 \begin{enumerate}198 \item the first enumerator, @A@, is initialized with @T@'s @zero_t@.199 \item otherwise, the next enumerator is initialized with the previous enumerator's value using the operator @?+?(T, one_t)@, which can be overloaded for any type @T@.200 \end{enumerate}201 202 % Unfortunately, constant expressions in C are not powerful and \CFA is only a transpiler, relying on generated C code to perform the detail work.203 % It is currently beyond the scope of the \CFA project to implement a complex runtime interpreter in the transpiler to evaluate complex expressions across multiple builtin and user-defined type.204 % Nevertheless, the necessary language concepts exist to support this feature.205 206 193 207 194 \section{Subset}
Note: See TracChangeset
for help on using the changeset viewer.