Changeset a8f44c8 for doc


Ignore:
Timestamp:
Aug 8, 2024, 1:06:43 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
5b4c8df
Parents:
b0069a30
Message:

Update on comparison table (some checkmark still need to be fixed

Location:
doc/theses/jiada_liang_MMath
Files:
2 edited

Legend:

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

    rb0069a30 ra8f44c8  
    44The goal of this work is to extend the simple and unsafe enumeration type in the C programming-language into a complex and safe enumeration type in the \CFA programming-language, while maintaining backwards compatibility with C.
    55Within this goal, the new \CFA enumeration should align with the analogous enumeration features in other languages to match modern programming expectations.
    6 Hence, the \CFA enumeration features are burrowed from a number of programming languages, but engineered to work and play with \CFA's type system and feature set.
     6Hence, the \CFA enumeration features are borrowed from a number of programming languages, but engineered to work and play with \CFA's type system and feature set.
    77
    88Additional safety is provided by strong type-checking of enumeration initialization and assignment, ensuring an enumeration only contains its enumerators.
     
    4242enum( wchar_t * ) { Jack = L"John" };
    4343\end{cfa}
     44The enumerating feature was developed in parallel with the \CFA iterator. In the forseeable future when iterator come to matuity, \CFA enumeration can adapt iterator-related traits and
     45be rewritten with iterator.
  • doc/theses/jiada_liang_MMath/relatedwork.tex

    rb0069a30 ra8f44c8  
    150150
    151151The underlying type is an implementation-defined integral-type large enough to hold all enumerated values; it does not have to be the smallest possible type.
    152 The integral size can be explicitly specified using compiler directive @$PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
     152The integral size can be explicitly specified using compiler directive \$@PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
    153153\begin{pascal}
    154154Type @{$\color{red}\$$PACKENUM 1}@ SmallEnum = ( one, two, three );
     
    167167\end{ada}
    168168Object initialization and assignment are restricted to the enumerators of this type.
    169 While Ada enumerators are unscoped, like C, Ada enumerators are overloadable.
     169While Ada enumerators are unscoped, Ada enumerators are overloadable.
    170170\begin{ada}
    171171type RGB is ( @Red@, @Green@, Blue );
     
    438438\end{tabular}
    439439\end{cquote}
    440 However, there is no mechanism to iterate through an enumeration without an unsafe cast and it does not understand the enumerator values.
     440% However, there is no mechanism to iterate through an enumeration without an unsafe cast and it does not understand the enumerator values.
     441\CC enumerators are not relational: the only comparator defined for \CC is the value comparison. The define order of enumerator has no
     442impact on its behaviour. As a consequnce, \CC has no meaningful enumerating mechanism.
    441443\begin{c++}
    442444enum Week { Mon, Tue, Wed, Thu = 10, Fri, Sat, Sun };
     
    4444460 1 2 @3 4 5 6 7 8 9@ 10 11 12 13
    445447\end{c++}
     448An approximation of enumerating an enum in \CC is to use the last enumerator value as a range. But it inevitably
     449fails the enumeration value does not assemble auto-initialization.
     450
    446451An enumeration type cannot declare an array dimension but an enumerator can be used as a subscript.
    447452There is no mechanism to subtype or inherit from an enumeration.
     
    457462\Csharp is a dynamically-typed programming-language with a scoped, integral enumeration similar to \CC \lstinline[language=C++]{enum class}.
    458463\begin{csharp}
    459 enum Week : @long@ { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun@,@ } // terminating comma
     464enum Week : @long@ { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun }
    460465enum RGB { Red, Green, Blue }
    461466\end{csharp}
    462 The default underlying integral type is @int@ (no @char@), with auto-incrementing, implicit/explicit initialization, and terminating comma.
     467The default underlying integral type is @int@ (no @char@), with auto-incrementing, implicit/explicit initialization.
    463468A method cannot be defined in an enumeration type (extension methods are possible).
    464469There is an explicit bidirectional conversion between an enumeration and its integral type, and an implicit conversion to the enumerator label in display contexts.
     
    471476Console.WriteLine( Week.Fri );          $\C{// print label Fri}$
    472477\end{csharp}
    473 The majority of the integral operators (relational and arithmetic) work with enumerations, except @*@ and @/@.
     478% The majority of the integral operators (relational and arithmetic) work with enumerations, except @*@ and @/@.
     479% Relational and arithmetic operators are defined in terms of its numeric value only.
     480% Therefore, enumerators are not ordered and not enumerable like \CC.
     481Like \CC, \Csharp defines enumeration relational and arithemtic operators in terms of value.
     482Enumerators has no defined positional meaning.
    474483\begin{csharp}
    475484day = day++ - 5;                                        $\C{// unsafe}$
    476485day = day & day;
     486\end{csharp}
     487
     488\begin{csharp}
     489for ( Week d = Mon; d <= Sun; @d += 1@ ) {
     490        Console.Write( d + " " );
     491}
     492Mon Tue Wed @3 4 5 6 7 8 9@ Thu Fri Sat Sun
    477493\end{csharp}
    478494
     
    502518\end{tabular}
    503519\end{cquote}
    504 However, there is no mechanism to iterate through an enumeration without an unsafe cast to increment and positions versus values is not handled.
    505 \begin{csharp}
    506 for ( Week d = Mon; d <= Sun; @d += 1@ ) {
    507         Console.Write( d + " " );
    508 }
    509 Mon Tue Wed @3 4 5 6 7 8 9@ Thu Fri Sat Sun
    510 \end{csharp}
    511 The @Enum.GetValues@ pseudo-method retrieves an array of the enumeration constants for looping over an enumeration type or variable (expensive operation).
     520
     521As a compliment, \Csharp's Enum library has @Enum.GetValues@ pseudo-method that retrieves an array of the enumeration constants for looping over an enumeration type or variable (expensive operation).
    512522\begin{csharp}
    513523foreach ( Week d in @Enum.GetValues@( typeof(Week) ) ) {
     
    782792#[repr(u8)]
    783793enum ADT {
    784         I(isize) @= 5@,  // ???
     794        I(isize) @= 5@,
    785795        F(f64) @= 10@,
    786796        S(S) @= 0@,
     
    12881298As seen, a type tag can be used in the @if@ and \lstinline[language=ocaml]{match} statements, where \lstinline[language=ocaml]{match} must be exhaustive or have a default case.
    12891299
    1290 Enumerating is accomplished by deriving from @enumerate@.
     1300% Enumerating is accomplished by deriving from @enumerate@.
     1301OCaml enumerators has an ordering following the definition order, but they are not enumerable.
     1302To iterate over all enumerators, an OCaml type needs to derive @enumerate@ proprocessor, which appends a list of all enumerators to the program
     1303abstract syntax tree (AST). The list of value may not persist the define ordering. Given that it needs tools that is outside of the native language to facilate,
     1304we claim it has no capability of enumerating.
    12911305
    12921306Enumeration subtyping is allowed but inheritance is restricted to classes not types.
     
    15291543\newcommand{\CM}{\checkmark}
    15301544\begin{tabular}{r|c|c|c|c|c|c|c|c|c|c|c|c|c}
    1531                                 &Pascal & Ada   &\Csharp& OCaml & Java  &Modula-3&Golang& Rust  & Swift & Python& C             & \CC   & \CFA  \\
     1545                                &Pascal & Ada                   &\Csharp   & OCaml & Java       &Golang& Rust           & Swift                 & Python& C             & \CC   & \CFA  \\
    15321546\hline
    1533 @const@                 & \CM   &               &               &               &               &               & \CM   &               &               &               &               & \CM   &               \\
     1547enum                    &Dialect& \CM                   & \CM      & ADT  & \CM   & @const@&ADT/\CM     &ADT/\CM                & \CM   &\CM    &\CM   &\CM\\
    15341548\hline
    15351549\hline
    1536 opaque                  &               &               &               &               &               &               &               &               &               &               &               &               & \CM   \\
     1550opaque                  &               &                               &                  & \CM   & \CM   &            &                       & \CM                   &               &               &               & \CM   \\
    15371551\hline
    1538 typed                   &               &               &               &               &               &               &               &               &               &               & @int@ & integral      & @T@   \\
     1552typed                   &Int    & Int                   & Integral  & H     & U    & H     & U/H        & U/H           & H         & Int       & Integral& U   \\
    15391553\hline
    1540 safe                    &               &               &               &               &               &               &               &               &               &               &               & \CM   & \CM   \\
     1554safety          & \CM   & \CM                   &          & \CM        & \CM   &               & \CM           & \CM                   &               &               & \CM   & \CM   \\
    15411555\hline
    1542 ordered                 &               &               &               &               &               &               &               &               &               &               & \CM   & \CM   & \CM   \\
     1556posn ordered    & \CM   & \CM                   & \CM      & \CM   & \CM   &            &                       & \CM                   &       &           &       & \CM       \\
    15431557\hline
    1544 dup. values             &               &               &               &               &               &               &               &               &               & alias & \CM   & \CM   & \CM   \\
     1558unique values   & \CM   &                               & \CM      &            & \CM   & \CM   &                       & \CM                   & alias & \CM   & \CM   & \CM   \\
    15451559\hline
    1546 setable                 &               &               &               &               &               &               &               &               &               &               & \CM   & \CM   & \CM   \\
     1560% setable       repr.   & \CM   & \CM                   & \CM      &            & \CM   & \CM   & \CM           & \CM                   & \CM   & \CM   & \CM   & \CM   \\
     1561% \hline
     1562auto-init               & \CM   & @all or none@   & \CM      &       &       & \CM   & \CM      & \CM                      & \CM   & \CM        & \CM   & \CM   \\
     1563% This one is tricky: C/C++/CC has auto-init value. Some have auto-init underlying representation
    15471564\hline
    1548 auto-init               &               &               &               &               &               &               &               &               &               &               & \CM   & \CM   & \CM   \\
     1565(Un)Scoped              & U     & U                     & S        & S      & S         & U     & S             & S                     & S     & U             & U/S   & U/S   \\
    15491566\hline
    1550 (Un)Scoped              &               &               &               &               &               &               &               &               &               &               & U             & U/S   & U/S   \\
     1567overload                &               & \CM                   & n/a       & n/a       &n/a    &               & n/a           & n/a                   &n/a    &               &       & \CM   \\
    15511568\hline
    1552 overload                &               & \CM   &               &               &               &               &               &               &               &               &               & \CM   & \CM   \\
     1569loop                    & \CM   & \CM                   &                  &            &               &               &                       &                       & \CM   &               &               & \CM   \\
    15531570\hline
    1554 switch                  &               &               &               &               &               &               &               &               &               &               & \CM   & \CM   & \CM   \\
     1571% array/subscript       &               &               &               &                               &               &               &               &               &               & \CM   &               & \CM   \\
     1572% \hline
     1573subset                  & \CM   & \CM                   &         & \CM     &           &               &                       &                       &               &               &               & \CM   \\
    15551574\hline
    1556 loop                    &               &               &               &               &               &               &               &               &               &               &               &               & \CM   \\
    1557 \hline
    1558 array/subscript &               &               &               &               &               &               &               &               &               &               & \CM   &               & \CM   \\
    1559 \hline
    1560 subtype                 &               &               &               &               &               &               &               &               &               &               &               &               & \CM   \\
    1561 \hline
    1562 inheritance             &               &               &               &               &               &               &               &               &               &               &               &               & \CM   \\
     1575superset                &               &                               &                 &                 &           &               &                       &               &               &               &               & \CM   \\
    15631576\end{tabular}
    15641577\end{table}
     1578
     1579\begin{enumerate}
     1580\item Opaque: Language has opaque enum if its enumerator cannot be used as its underlying representation or its enum is implemented as ADT.
     1581\item Typed: The type of value. H: heterogeneous type; enumerators from the same enum need not be has the same type.
     1582U: uni-type; enumerators must have the same type.
     1583\item Safe: A enumeration variable can only hold a value from its defined enumerators.
     1584\item Posn ordered: enumerators have defined ordering based on enuemrator declaration order.
     1585\item Unique value: enumerators must have unique value.
     1586\item Auto-init: Value are auto initializable.
     1587\item (Un)Scoped: U: unscoped enuemrators and does not need qualification; S: Scoped enumerators and requires qualification
     1588\item Overload: An enumerator label can be used without type qualification in a context where the label has defined by multiple enumerations
     1589\item Loop: Enumerate enum members without explicitly convert it to other data structures
     1590\item Subset: Name a subset of enumerator as a new type.
     1591\item Superset: Create a new enumeration that contain all enumerators from pre-defined enuemration.
     1592\end{enumerate}
Note: See TracChangeset for help on using the changeset viewer.