Changeset a8f44c8 for doc/theses
- Timestamp:
- Aug 8, 2024, 1:06:43 PM (3 months ago)
- Branches:
- master
- Children:
- 5b4c8df
- Parents:
- b0069a3
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/conclusion.tex
rb0069a3 ra8f44c8 4 4 The 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. 5 5 Within 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 b urrowed from a number of programming languages, but engineered to work and play with \CFA's type system and feature set.6 Hence, 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. 7 7 8 8 Additional safety is provided by strong type-checking of enumeration initialization and assignment, ensuring an enumeration only contains its enumerators. … … 42 42 enum( wchar_t * ) { Jack = L"John" }; 43 43 \end{cfa} 44 The 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 45 be rewritten with iterator. -
doc/theses/jiada_liang_MMath/relatedwork.tex
rb0069a3 ra8f44c8 150 150 151 151 The 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:152 The integral size can be explicitly specified using compiler directive \$@PACKENUM@~$N$, where $N$ is the number of bytes, \eg: 153 153 \begin{pascal} 154 154 Type @{$\color{red}\$$PACKENUM 1}@ SmallEnum = ( one, two, three ); … … 167 167 \end{ada} 168 168 Object initialization and assignment are restricted to the enumerators of this type. 169 While Ada enumerators are unscoped, like C,Ada enumerators are overloadable.169 While Ada enumerators are unscoped, Ada enumerators are overloadable. 170 170 \begin{ada} 171 171 type RGB is ( @Red@, @Green@, Blue ); … … 438 438 \end{tabular} 439 439 \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 442 impact on its behaviour. As a consequnce, \CC has no meaningful enumerating mechanism. 441 443 \begin{c++} 442 444 enum Week { Mon, Tue, Wed, Thu = 10, Fri, Sat, Sun }; … … 444 446 0 1 2 @3 4 5 6 7 8 9@ 10 11 12 13 445 447 \end{c++} 448 An approximation of enumerating an enum in \CC is to use the last enumerator value as a range. But it inevitably 449 fails the enumeration value does not assemble auto-initialization. 450 446 451 An enumeration type cannot declare an array dimension but an enumerator can be used as a subscript. 447 452 There is no mechanism to subtype or inherit from an enumeration. … … 457 462 \Csharp is a dynamically-typed programming-language with a scoped, integral enumeration similar to \CC \lstinline[language=C++]{enum class}. 458 463 \begin{csharp} 459 enum Week : @long@ { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun @,@ } // terminating comma464 enum Week : @long@ { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun } 460 465 enum RGB { Red, Green, Blue } 461 466 \end{csharp} 462 The default underlying integral type is @int@ (no @char@), with auto-incrementing, implicit/explicit initialization , and terminating comma.467 The default underlying integral type is @int@ (no @char@), with auto-incrementing, implicit/explicit initialization. 463 468 A method cannot be defined in an enumeration type (extension methods are possible). 464 469 There is an explicit bidirectional conversion between an enumeration and its integral type, and an implicit conversion to the enumerator label in display contexts. … … 471 476 Console.WriteLine( Week.Fri ); $\C{// print label Fri}$ 472 477 \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. 481 Like \CC, \Csharp defines enumeration relational and arithemtic operators in terms of value. 482 Enumerators has no defined positional meaning. 474 483 \begin{csharp} 475 484 day = day++ - 5; $\C{// unsafe}$ 476 485 day = day & day; 486 \end{csharp} 487 488 \begin{csharp} 489 for ( Week d = Mon; d <= Sun; @d += 1@ ) { 490 Console.Write( d + " " ); 491 } 492 Mon Tue Wed @3 4 5 6 7 8 9@ Thu Fri Sat Sun 477 493 \end{csharp} 478 494 … … 502 518 \end{tabular} 503 519 \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 521 As 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). 512 522 \begin{csharp} 513 523 foreach ( Week d in @Enum.GetValues@( typeof(Week) ) ) { … … 782 792 #[repr(u8)] 783 793 enum ADT { 784 I(isize) @= 5@, // ???794 I(isize) @= 5@, 785 795 F(f64) @= 10@, 786 796 S(S) @= 0@, … … 1288 1298 As 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. 1289 1299 1290 Enumerating is accomplished by deriving from @enumerate@. 1300 % Enumerating is accomplished by deriving from @enumerate@. 1301 OCaml enumerators has an ordering following the definition order, but they are not enumerable. 1302 To iterate over all enumerators, an OCaml type needs to derive @enumerate@ proprocessor, which appends a list of all enumerators to the program 1303 abstract 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, 1304 we claim it has no capability of enumerating. 1291 1305 1292 1306 Enumeration subtyping is allowed but inheritance is restricted to classes not types. … … 1529 1543 \newcommand{\CM}{\checkmark} 1530 1544 \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 \\ 1532 1546 \hline 1533 @const@ & \CM & & & & & & \CM & & & & & \CM &\\1547 enum &Dialect& \CM & \CM & ADT & \CM & @const@&ADT/\CM &ADT/\CM & \CM &\CM &\CM &\CM\\ 1534 1548 \hline 1535 1549 \hline 1536 opaque & & & & & & & & && & & & \CM \\1550 opaque & & & & \CM & \CM & & & \CM & & & & \CM \\ 1537 1551 \hline 1538 typed & & & & & & & & & & & @int@ & integral & @T@\\1552 typed &Int & Int & Integral & H & U & H & U/H & U/H & H & Int & Integral& U \\ 1539 1553 \hline 1540 safe & & & & & & & & && & & \CM & \CM \\1554 safety & \CM & \CM & & \CM & \CM & & \CM & \CM & & & \CM & \CM \\ 1541 1555 \hline 1542 ordered & & & & & & & & & & & \CM & \CM& \CM \\1556 posn ordered & \CM & \CM & \CM & \CM & \CM & & & \CM & & & & \CM \\ 1543 1557 \hline 1544 dup. values & & & & & & & & && alias & \CM & \CM & \CM \\1558 unique values & \CM & & \CM & & \CM & \CM & & \CM & alias & \CM & \CM & \CM \\ 1545 1559 \hline 1546 setable & & & & & & & & & & & \CM & \CM & \CM \\ 1560 % setable repr. & \CM & \CM & \CM & & \CM & \CM & \CM & \CM & \CM & \CM & \CM & \CM \\ 1561 % \hline 1562 auto-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 1547 1564 \hline 1548 auto-init & & & & & & & & & & & \CM & \CM & \CM\\1565 (Un)Scoped & U & U & S & S & S & U & S & S & S & U & U/S & U/S \\ 1549 1566 \hline 1550 (Un)Scoped & & & & & & & & & & & U & U/S & U/S\\1567 overload & & \CM & n/a & n/a &n/a & & n/a & n/a &n/a & & & \CM \\ 1551 1568 \hline 1552 overload & & \CM & & & & & & & & & & \CM& \CM \\1569 loop & \CM & \CM & & & & & & & \CM & & & \CM \\ 1553 1570 \hline 1554 switch & & & & & & & & & & & \CM & \CM & \CM \\ 1571 % array/subscript & & & & & & & & & & \CM & & \CM \\ 1572 % \hline 1573 subset & \CM & \CM & & \CM & & & & & & & & \CM \\ 1555 1574 \hline 1556 loop & & & & & & & & & & & & & \CM \\ 1557 \hline 1558 array/subscript & & & & & & & & & & & \CM & & \CM \\ 1559 \hline 1560 subtype & & & & & & & & & & & & & \CM \\ 1561 \hline 1562 inheritance & & & & & & & & & & & & & \CM \\ 1575 superset & & & & & & & & & & & & \CM \\ 1563 1576 \end{tabular} 1564 1577 \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. 1582 U: 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.