Changeset 17fdf6f
- Timestamp:
- Sep 15, 2024, 10:13:30 AM (2 months ago)
- Branches:
- master
- Children:
- 0c88135
- Parents:
- 8c79dc3c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/conclusion.tex
r8c79dc3c r17fdf6f 27 27 Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA. %, like compile-time constant-expression evaluation. 28 28 When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them. 29 29 30 \item 30 Currently, some aspects of the enumeration trait system require explicitly including the file @enum.hfa@, which can lead to problems.31 Currently, some aspects of the enumeration trait system require explicitly including the file \lstinline[deletekeywords={enum}]{enum.hfa}, which can lead to problems. 31 32 It should be possible to have this file included implicitly by updating the \CFA prelude. 32 33 \item … … 35 36 Enumerations may have to be modified to dovetail with these features. 36 37 For example, enumerating with range loops does not align with the current iterator design, so some changes will be necessary. 38 37 39 \item 38 40 C already provides @const@-style aliasing using the \emph{unnamed} enumerator \see{\VRef{s:TypeName}}, even if the name @enum@ is misleading (@const@ would be better). … … 50 52 enum( wchar_t * ) { Jack = L"John" }; 51 53 \end{cfa} 54 52 55 \item 53 56 Currently, enumeration scoping is all or nothing. In some cases, it might be useful to … … 61 64 For @E2@, @A@, and @C@ are scoped; @B@ is unscoped. 62 65 Finding a use case is important to justify this extension. 66 63 67 \item 64 68 An extension mentioned in \VRef{s:Ada} is using @typedef@ to create an enumerator alias. 65 69 \begin{cfa} 66 enum( int) RGB { @Red@, @Green@, Blue };67 enum( int) Traffic_Light { @Red@, Yellow, @Green@ };70 enum( int ) RGB { @Red@, @Green@, Blue }; 71 enum( int ) Traffic_Light { @Red@, Yellow, @Green@ }; 68 72 typedef RGB.Red OtherRed; // alias 69 73 \end{cfa} 74 70 75 \item 71 Label arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a considerable program overhead. 72 It is helpful to provide a new syntax or annotation for a \CFA enumeration definition that tells the compiler the labels will not be used 73 throughout the execution. Therefore, \CFA optimizes the label array away. The @label()@ function can still be used on an enumeration constant, 74 and the function called is reduced to a @char *@ constant expression that holds the name of the enumerator. But if @label()@ is called on 75 a variable with an enumerated type, it returns an empty string since the label information is lost for the runtime. 76 Label and values arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a program overhead when unused. 77 It might be possible to provide a new syntax or annotation for a \CFA enumeration definition indicating these arrays are not used. 78 Therefore, \CFA does not generated them. 79 @label@ can still be used on an enumeration constant, as the call reduces to a @char *@ constant expression that holds the name of the enumerator. 80 But calls on an enumeration variable, generate a compile-time error. 81 The best alternative is for the linker to discard these arrays if unused. 82 76 83 \item 77 \CFA enumeration has its limitation in separate compilation. Consider the followings example: 84 The \CFA enumeration has limitations with separate compilation. 85 Consider the following: 86 \begin{cquote} 87 \setlength{\tabcolsep}{20pt} 88 \begin{tabular}{@{}ll@{}} 78 89 \begin{cfa} 79 // libvacodec.h: v1 80 enum(int) C_Codec ! { 81 FIRST_VIDEO = 0, 82 VP8 = 2, 83 VP9 = 4, 84 LAST_VIDEO = 8, 90 enum C_Codec { 91 FIRST_VIDEO = 0, 92 VP8 = 0, 93 VP9, 94 LAST_VIDEO, 85 95 86 FIRST_AUDIO = 3,87 VORBIS = 9,88 OPUS = 27,89 LAST_AUDIO = 81 96 FIRST_AUDIO = 64, 97 VORBIS = 64, 98 OPUS, 99 LAST_AUDIO 90 100 }; 101 \end{cfa} 102 & 103 \begin{cfa} 104 enum( int ) CFA_Codec { 105 FIRST_VIDEO = 0, 106 VP8 = 0, 107 VP9, 108 LAST_VIDEO, 91 109 92 enum(int) CFA_Codec ! { 93 FIRST_VIDEO = 0, 94 VP8 = 2, 95 VP9 = 4, 96 LAST_VIDEO = 8, 110 FIRST_AUDIO = 64, 111 VORBIS = 64, 112 OPUS, 113 LAST_AUDIO 114 }; 115 \end{cfa} 116 \\ 117 \begin{cfa} 118 C_Codec c_code = OPUS; 119 CFA_Codec cfa_code = OPUS; 120 \end{cfa} 121 \end{tabular} 122 \end{cquote} 123 @c_code@ has value 65, the integral value of @c_code.OPUS@, while @cfa_code@ has value 6, the position of @CFA_Codec.OPUS@. 97 124 98 FIRST_AUDIO = 3, 99 VORBIS = 9, 100 OPUS = 27, 101 LAST_AUDIO = 81 125 If the enumerator @AV1@ is inserted in @C_Codec@ and @CFA_Codec@, 126 \begin{cquote} 127 \setlength{\tabcolsep}{20pt} 128 \begin{tabular}{@{}ll@{}} 129 \begin{cfa} 130 enum C_Codec { 131 FIRST_VIDEO = 0, 132 VP8 = 0, 133 VP9, 134 @AV1@, 135 LAST_VIDEO, 136 137 FIRST_AUDIO = 64, 138 VORBIS = 64, 139 OPUS, 140 LAST_AUDIO 102 141 }; 142 \end{cfa} 143 & 144 \begin{cfa} 145 enum( int ) CFA_Codec { 146 FIRST_VIDEO = 0, 147 VP8 = 0, 148 VP9, 149 @AV1@, 150 LAST_VIDEO, 103 151 104 // main.c 105 C_Codec c_code = C_Codec.VORBIS; 106 CFA_Codec cfa_code = CFA_Codec.VORBIS; 152 FIRST_AUDIO = 64, 153 VORBIS = 64, 154 OPUS, 155 LAST_AUDIO 156 }; 107 157 \end{cfa} 108 The memory location of @c_code@ stores a value 9, the integral value of VORBIS. 109 The memory of @cfa_code@ stores 5, which is the position of @CFA_Codec.VORBIS@ and can be mapped to value 9. 158 \end{tabular} 159 \end{cquote} 160 the assignments still result in @c_code@ with value 65, but @cfa_code@ is now 7. 161 For \CFA, if all translation units including @CFA_Codec@ are not recompiled, some could assign the old 6 and some the new 7, while partially compiled C translation units all continue to assign 65. 110 162 111 If to insert a new enumerator in both @C_Codec@ and @CFA_Codec@ 112 before the relative position of VORBIS, without a re-compilation of @main.c@, variable @cfa_code@ would be mapped 113 to an unintented value. 163 For \CFA to achieve the same behaviour for positions as C does with value for partial recompilation, enumeration positions could be represented as @const@ declarations with corresponding @extern@ declarations in the include file. 164 \begin{cquote} 165 \setlength{\tabcolsep}{20pt} 166 \begin{tabular}{@{}ll@{}} 114 167 \begin{cfa} 115 // libvacodec.h: v2 116 enum(int) C_Codec ! { 117 FIRST_VIDEO = 0, 118 VP8 = 2, 119 VP9 = 4, 120 @AV1@, 121 LAST_VIDEO = 8, 168 const int FIRST_VIDEO_posn = 0; 169 const int VP8_posn = 1; 170 const int VP9_posn = 2; 122 171 123 FIRST_AUDIO = 3, 124 VORBIS = 9, 125 OPUS = 27, 126 LAST_AUDIO = 81 127 }; 128 129 enum(int) CFA_Codec ! { 130 FIRST_VIDEO = 0, 131 VP8 = 2, 132 VP9 = 4, 133 @AV1@, 134 LAST_VIDEO = 8, 135 136 FIRST_AUDIO = 3, 137 VORBIS = 9, 138 OPUS = 27, 139 LAST_AUDIO = 81 140 }; 141 172 const int LAST_VIDEO_posn = 3; 173 const int FIRST_AUDIO_posn = 4; 174 const int VORBIS_posn = 5; 175 const int OPUS_posn = 6; 176 const int LAST_AUDIO_posn = 7; 142 177 \end{cfa} 143 While @c_code@ still has the correct value of 9, @cfa_code@ (5) is now mapped to @First_AUDIO@. In other words, it is 144 necessary to to recompile @main.c@ when to update @libvacodec.h@. 145 146 To avoid a recompilation, enumeration positions can be represented as @extern const@. For example, \CFA-cc can generate the following code for @CFA_Codec@: 147 \begin{cfa} 148 // CFA-cc transpile: libvacodec.h 149 const int FIRST_VIDEO = 0; 150 const int VP8 = 1; 151 const int VP9 = 2; 152 const int LAST_VIDEO = 3; 153 const int FIRST_AUDIO = 4; 154 const int VORBIS = 5; 155 const int OPUS = 6; 156 const int LAST_AUDIO = 7; 157 158 // CFA-cc transpile: main.c 159 extern const int FIRST_VIDEO; 160 extern const int VP8; 161 extern const int VP9; 162 extern const int LAST_VIDEO; 163 extern const int FIRST_AUDIO; 164 extern const int VORBIS; 165 extern const int OPUS; 166 extern const int LAST_AUDIO; 167 168 int cfa_code = VORBIS; 178 &\begin{cfa} 179 const int FIRST_VIDEO_posn = 0; 180 const int VP8_posn = 1; 181 const int VP9_posn = 2; 182 const int AV1_posn = 3; 183 const int LAST_VIDEO_posn = 4; 184 const int FIRST_AUDIO_posn = 5; 185 const int VORBIS_posn = 6; 186 const int OPUS_posn = 7; 187 const int LAST_AUDIO_posn = 8; 169 188 \end{cfa} 170 If later a position of an enumerator is changed, the generated expression @int cfa_code = VORBIS;@ will still have the correct 171 value, because it is linked to a external constant @VORBIS@ from @libvacodec.h@. This implementation requires extra memory to store position, but 172 solve the separate compilation problem. 173 189 \end{tabular} 190 \end{cquote} 191 Then the linker always uses the most recent object file with the up-to-date positions. 192 However, this implementation means the equivalent of a position array is generated using more storage. 174 193 \end{enumerate}
Note: See TracChangeset
for help on using the changeset viewer.