Ignore:
Timestamp:
Sep 15, 2024, 12:25:59 PM (5 weeks ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
68a7028
Parents:
17fdf6f
Message:

Update on thesis

Location:
doc/theses/jiada_liang_MMath
Files:
2 edited

Legend:

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

    r17fdf6f r0c88135  
    145145\begin{cfa}
    146146enum E { E1, E2, E3 };
    147 static const char * E_labels[3] = { "E1", "E2", "E3" };
    148 static const T E_values[3] = { t1, t2, t3 };
     147const char * E_labels[3] = { "E1", "E2", "E3" };
     148const T E_values[3] = { t1, t2, t3 };
    149149\end{cfa}
    150150The generated C enumeration has enumerator values that match \CFA enumerator positions because of C's auto-initialization.
     
    156156so these expressions remain unchanged by \CFA-cc.
    157157Therefore, a \CFA enumeration variable has the same underlying representation as its generated C enumeration.
    158 This semantics implies a \CFA enumeration variable does not use memory, that @posn@ can use its underlying representation, and the label and value arrays take little storage.
     158This semantics implies a \CFA enumeration variable uses the same storages as a C enumeration variable that @posn@ can use as its underlying representation, and the label and value arrays take little storage.
    159159It should be possible to eliminated the two arrays if unused, either by \CFA if local to a translation unit and unused, or by the linker if global but unreferenced.
    160160Also, the label and value arrays are declared @static@ and initialized with constants, so the arrays are allocated in the @.data@ section and initialized before program execution.
  • doc/theses/jiada_liang_MMath/relatedwork.tex

    r17fdf6f r0c88135  
    13131313PPX is beyond the scope of OCaml native language and it is a preprocessor directly modifying a parsed AST. In conclusion, there is no enumerating mechanism within the scope of OCaml language.
    13141314
    1315 \PAB{Why was this removed?}
    1316 Enumeration subsetting is allowed but inheritance is restricted to classes not types.
     1315New types can be formed as a composition of existing types.
    13171316\begin{ocaml}
    13181317type weekday = Mon | Tue | Wed | Thu | Fri
     
    13201319type week = Weekday of weekday | Weekend of weekend
    13211320let day : week = Weekend Sun
     1321\end{ocaml}
     1322The @week@ is a sum of @weekday@ and @weekend@; @week@ has all the enumerator from the set @weekday@ and @weekend@.
     1323The sum type construction resembles containment inheritance from non-functional programming discipline, with
     1324the sum type being a wrapper class that contains one of its parent type.
     1325
     1326The wrapper can be "unwrapped" with pattern matching:
     1327\begin{ocaml}
     1328let wd : weekday = Mon
     1329let _ = match wd with
     1330                Mon -> printf "Mon\n" |
     1331                _ -> printf "Take a break\n"
     1332
     1333let we : weekend = Sun
     1334let _ = match we with
     1335                Sun -> printf "Sun\n" |
     1336                _ -> printf "Take a break\n"
     1337
     1338let day : week = Weekend Sun
     1339let _ = match day with
     1340                Weekend Sun -> printf "Sun\n" |
     1341                _ -> printf "Take a break\n"
    13221342\end{ocaml}
    13231343
Note: See TracChangeset for help on using the changeset viewer.