Changeset 17fdf6f


Ignore:
Timestamp:
Sep 15, 2024, 10:13:30 AM (3 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
0c88135
Parents:
8c79dc3c
Message:

missed proofreading in conclusion

File:
1 edited

Legend:

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

    r8c79dc3c r17fdf6f  
    2727Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA. %, like compile-time constant-expression evaluation.
    2828When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them.
     29
    2930\item
    30 Currently, some aspects of the enumeration trait system require explicitly including the file @enum.hfa@, which can lead to problems.
     31Currently, some aspects of the enumeration trait system require explicitly including the file \lstinline[deletekeywords={enum}]{enum.hfa}, which can lead to problems.
    3132It should be possible to have this file included implicitly by updating the \CFA prelude.
    3233\item
     
    3536Enumerations may have to be modified to dovetail with these features.
    3637For example, enumerating with range loops does not align with the current iterator design, so some changes will be necessary.
     38
    3739\item
    3840C 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).
     
    5052enum( wchar_t * ) { Jack = L"John" };
    5153\end{cfa}
     54
    5255\item
    5356Currently, enumeration scoping is all or nothing. In some cases, it might be useful to
     
    6164For @E2@, @A@, and @C@ are scoped; @B@ is unscoped.
    6265Finding a use case is important to justify this extension.
     66
    6367\item
    6468An extension mentioned in \VRef{s:Ada} is using @typedef@ to create an enumerator alias.
    6569\begin{cfa}
    66 enum(int) RGB { @Red@, @Green@, Blue };
    67 enum(int) Traffic_Light { @Red@, Yellow, @Green@ };
     70enum( int ) RGB { @Red@, @Green@, Blue };
     71enum( int ) Traffic_Light { @Red@, Yellow, @Green@ };
    6872typedef RGB.Red OtherRed; // alias
    6973\end{cfa}
     74
    7075\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.
     76Label and values arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a program overhead when unused.
     77It might be possible to provide a new syntax or annotation for a \CFA enumeration definition indicating these arrays are not used.
     78Therefore, \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.
     80But calls on an enumeration variable, generate a compile-time error.
     81The best alternative is for the linker to discard these arrays if unused.
     82
    7683\item
    77 \CFA enumeration has its limitation in separate compilation. Consider the followings example:
     84The \CFA enumeration has limitations with separate compilation.
     85Consider the following:
     86\begin{cquote}
     87\setlength{\tabcolsep}{20pt}
     88\begin{tabular}{@{}ll@{}}
    7889\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,
     90enum C_Codec {
     91        FIRST_VIDEO = 0,
     92        VP8 = 0,
     93        VP9,
     94        LAST_VIDEO,
    8595
    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
    90100};
     101\end{cfa}
     102&
     103\begin{cfa}
     104enum( int ) CFA_Codec {
     105        FIRST_VIDEO = 0,
     106        VP8 = 0,
     107        VP9,
     108        LAST_VIDEO,
    91109
    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}
     118C_Codec c_code = OPUS;
     119CFA_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@.
    97124
    98     FIRST_AUDIO = 3,
    99     VORBIS = 9,
    100     OPUS = 27,
    101     LAST_AUDIO = 81
     125If 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}
     130enum 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
    102141};
     142\end{cfa}
     143&
     144\begin{cfa}
     145enum( int ) CFA_Codec {
     146        FIRST_VIDEO = 0,
     147        VP8 = 0,
     148        VP9,
     149        @AV1@,
     150        LAST_VIDEO,
    103151
    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};
    107157\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}
     160the assignments still result in @c_code@ with value 65, but @cfa_code@ is now 7.
     161For \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.
    110162
    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.
     163For \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@{}}
    114167\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,
     168const int FIRST_VIDEO_posn = 0;
     169const int VP8_posn = 1;
     170const int VP9_posn = 2;
    122171
    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 
     172const int LAST_VIDEO_posn = 3;
     173const int FIRST_AUDIO_posn = 4;
     174const int VORBIS_posn = 5;
     175const int OPUS_posn = 6;
     176const int LAST_AUDIO_posn = 7;
    142177\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}
     179const int FIRST_VIDEO_posn = 0;
     180const int VP8_posn = 1;
     181const int VP9_posn = 2;
     182const int AV1_posn = 3;
     183const int LAST_VIDEO_posn = 4;
     184const int FIRST_AUDIO_posn = 5;
     185const int VORBIS_posn = 6;
     186const int OPUS_posn = 7;
     187const int LAST_AUDIO_posn = 8;
    169188\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}
     191Then the linker always uses the most recent object file with the up-to-date positions.
     192However, this implementation means the equivalent of a position array is generated using more storage.
    174193\end{enumerate}
Note: See TracChangeset for help on using the changeset viewer.