Changeset bab2917 for doc/theses


Ignore:
Timestamp:
Oct 16, 2023, 1:16:26 PM (8 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
c298079
Parents:
8cbe732
Message:

Update the introduction

File:
1 edited

Legend:

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

    r8cbe732 rbab2917  
    7373
    7474
    75 
    76 %%
    77 %% Submission ID.
    78 %% Use this when submitting an article to a sponsored event. You'll
    79 %% receive a unique submission ID from the organizers
    80 %% of the event, and this ID should be used as the parameter to this command.
    81 %%\acmSubmissionID{123-A56-BU3}
    82 
    83 %%
    84 %% For managing citations, it is recommended to use bibliography
    85 %% files in BibTeX format.
    86 %%
    87 %% You can then either use BibTeX with the ACM-Reference-Format style,
    88 %% or BibLaTeX with the acmnumeric or acmauthoryear sytles, that include
    89 %% support for advanced citation of software artefact from the
    90 %% biblatex-software package, also separately available on CTAN.
    91 %%
    92 %% Look at the sample-*-biblatex.tex files for templates showcasing
    93 %% the biblatex styles.
    94 %%
    95 
    96 %%
    97 %% The majority of ACM publications use numbered citations and
    98 %% references.  The command \citestyle{authoryear} switches to the
    99 %% "author year" style.
    100 %%
    101 %% If you are preparing content for an event
    102 %% sponsored by ACM SIGGRAPH, you must use the "author year" style of
    103 %% citations and references.
    104 %% Uncommenting
    105 %% the next command will enable that style.
    106 %%\citestyle{acmauthoryear}
    107 
    10875%%
    10976%% end of the preamble, start of the body of the document source.
     
    12895%% article.
    12996\begin{abstract}
    130     An enumeration, or enum in short, is a type that defines a list of named constant values in C. Cforall extends the enumeration with additional features.
     97    An enumeration, or enum in short, is a type that defines a list of named constant values in C. C uses integral type as the underlying representation of enum. Cforall extends C enum to allow more types, including custom types, to be used as enumeration inner representation.
    13198\end{abstract}
    13299
     
    143110
    144111\section{C-Style Enum}
     112\begin{lstlisting}[style=CStyle, label{lst:weekday}]
     113enum Weekday { Monday, Tuesday, Wednesday, Thursday=10, Friday, Saturday, Sunday };
     114\end{lstlisting}
     115Cforall supports the C-Style enumeration (C-enum for short). It has the same syntax as C and resembles the same language semantics. In code~\ref{lst:weekday} example, the syntax defines an enum class $Weekday$ with enumerators $Monday$, $Tuesday$, $Wednesday$, $Thursday$, $Friday$, $Saturday$ and $Sunday$ in order. The successor of $Tuesday$ is $Monday$ and the predecessor of $Tuesday$ is $Wednesday$. Enumerators have an integral type, either being explicitly initialized by an initializer or being assigned a value by the compiler. For example, $Thursday$ has been assigned with value $10$. If not explicitly initialized, the first value of an enum, $Monday$ in the $Weekday$ example, has the integer value 0. Other uninitialized enum value has a value that is equal to their successor $+ 1$. The enum value $Tuesday$, $Wednesday$, $Friday$, $Saturday$, and $Sunday$ have value 1, 2, 11, 12, and 13 respectively.
     116
     117\begin{lstlisting}[label{lst:enum_scope}, style=CStyle]
     118{
     119    {
     120        enum RGB {R, G, B};
     121        int i = R  // i == 0
     122    }
     123    int j = G; // ERROR! G is not declared in this scope
     124}
     125\end{lstlisting}
     126C-enums are unscoped: enumerators declared inside of an enum are visible in the enclosing scope of the enum class.
     127
     128\section{Cforall-Style Enum}
     129\begin{lstlisting}[style=CStyle, label{lst:color}]
     130enum Color(char *) { Red="R", Green="G", Blue="B"  };
     131\end{lstlisting}
     132A Cforall enumeration is parameterized by a type declared. Cforall allows any oType in the enum declaration, and values assigned to enumerators must be in the declared type.
     133
     134\section{Enumerable Type Traits}
     135A trait is a collection of constraints in Cforall, which can be used to describe types. Cforall standard library defines traits to categorize types that are related enumeration features.
     136\subsection{Enumerable}
     137A type is enumerable if it can map an integer to a value.
    145138\begin{lstlisting}[style=CStyle]
    146 enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
    147 \end{lstlisting}
    148 Cforall supports the classic C-Style enumeration (C-enum for short) and its syntax is consistent with C. No internal data structure is generated for C-enum, and C-enum does not provide the Cforall-enum interface methods.
    149 
    150 \section{Cforall Enum}
     139forall(T)
     140trait Enumerable {
     141    T value( *class_name* , int );
     142};
     143\end{lstlisting}
     144The parameter class name stands for the name of an enumeration class, Weekday, for example.
     145
     146\subsection{AutoInitializable}
     147\begin{lstlisting}[style=CStyle]
     148forall(T)
     149trait AutoInitializable {
     150  void ?()( T & t, zero_t );
     151  void ?()( T & t, one_t );
     152  S& ?+=?( T & t, one_t );
     153  void ?{}( T &, T );
     154  T ?{}( T &, T );
     155};
     156\end{lstlisting}
     157
     158\subsection{AutoInitializable}
     159\begin{lstlisting}[style=CStyle]
     160forall(T)
     161trait AutoInitializable {
     162  void ?()( T & t, zero_t );
     163  void ?()( T & t, one_t );
     164  S& ?+=?( T & t, one_t );
     165  void ?{}( T &, T );
     166  T ?{}( T &, T );
     167};
     168\end{lstlisting}
     169A type is AutoInitializable if it has defined a zero\_t constructor, a one\_t constructor, an addition assignment operator, a copy constructor, and a copy assignment operator.
     170
    151171\subsection{Enumerable Type}
    152172\begin{lstlisting}[style=CStyle]
     
    160180};
    161181\end{lstlisting}
    162 A type is enumerable in Cforall if it has defined 0, 1, increment operator, copy constructor, and copy assignment operator.
     182
     183
     184
     185
    163186
    164187(Should change the definition of enumerable to something else. Maybe auto-constructible. If a type is not auto-constructible, all enumeration must be explicitly initialized)
     
    224247Names of labels are distinct in an enum declaration. Cforall therefore allows indexing an enum value with its string representation of a label.
    225248
    226 \subsection{Range Functions and Iteration (Placeholder)}
     249\subsection{Iteration and Range}
     250A Cforall enum is iterable and supports range function.
    227251\begin{lstlisting}[caption={Range Functions}, label{lst:range_functions}, style=CStyle]
    228 enum Weekday(
    229     Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
    230 };
     252struct string;
     253enum(string) Weekday(
     254    Monday = "M", Tuesday = "Tu", ...
     255};
     256for ( i; Weekday ) { sout | i; }
     257>> M Tu W Th F Sat Sun
     258for ( Monday ~= Tuesday )
     259>> M Tu
    231260\end{lstlisting}
    232261
     
    249278}
    250279>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     280enum Color.Label;
    251281Companion( string ) Color = {
    252282    .values = [ "Red", "Green", "Blue" ],
     
    255285>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    256286forall( T | enumerable(T) )
    257 T* value( Companion, int );
    258 char* label( Companion, int );
    259 \end{lstlisting}
    260 
    261 \subsection{TODO - Type trait for Cforall - Enum}
     287T value( Companion companion, int index ) { return companion.values[ index ]; }
     288T value( Companion, enum Color.Label );
     289char* label( Companion companion, int index ) { return companion.values[ index ]; }
     290char* label( Companion, enum Color.Label );
     291
     292\end{lstlisting}
     293
     294
     295\subsection{Companion Trait}
     296Users can define the companion object themselves. A companion object should define an array of any type called values and an array of strings representing a label. Defining a companion object effectively creates a new enumerable type.
     297
     298\subsection{Companion Mapping}
     299
     300
     301
     302\begin{lstlisting}[caption={Enum Type Functions}, label{lst:cforall_enum_functions}, style=CStyle]
     303
     304\end{lstlisting}
    262305%%
    263306%% If your work has an appendix, this is the place to put it.
Note: See TracChangeset for help on using the changeset viewer.