Changes in / [61e5d99:c298079]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/main.tex
r61e5d99 rc298079 73 73 74 74 75 76 %%77 %% Submission ID.78 %% Use this when submitting an article to a sponsored event. You'll79 %% receive a unique submission ID from the organizers80 %% 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 bibliography85 %% 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 include89 %% support for advanced citation of software artefact from the90 %% biblatex-software package, also separately available on CTAN.91 %%92 %% Look at the sample-*-biblatex.tex files for templates showcasing93 %% the biblatex styles.94 %%95 96 %%97 %% The majority of ACM publications use numbered citations and98 %% references. The command \citestyle{authoryear} switches to the99 %% "author year" style.100 %%101 %% If you are preparing content for an event102 %% sponsored by ACM SIGGRAPH, you must use the "author year" style of103 %% citations and references.104 %% Uncommenting105 %% the next command will enable that style.106 %%\citestyle{acmauthoryear}107 108 75 %% 109 76 %% end of the preamble, start of the body of the document source. … … 128 95 %% article. 129 96 \begin{abstract} 130 An enumeration, or enum in short, is a type that defines a list of named constant values in C. C forall 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. 131 98 \end{abstract} 132 99 … … 143 110 144 111 \section{C-Style Enum} 112 \begin{lstlisting}[style=CStyle, label{lst:weekday}] 113 enum Weekday { Monday, Tuesday, Wednesday, Thursday=10, Friday, Saturday, Sunday }; 114 \end{lstlisting} 115 Cforall 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} 126 C-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}] 130 enum Color(char *) { Red="R", Green="G", Blue="B" }; 131 \end{lstlisting} 132 A 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} 135 A 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} 137 A type is enumerable if it can map an integer to a value. 145 138 \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} 139 forall(T) 140 trait Enumerable { 141 T value( *class_name* , int ); 142 }; 143 \end{lstlisting} 144 The parameter class name stands for the name of an enumeration class, Weekday, for example. 145 146 \subsection{AutoInitializable} 147 \begin{lstlisting}[style=CStyle] 148 forall(T) 149 trait 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] 160 forall(T) 161 trait 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} 169 A 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 151 171 \subsection{Enumerable Type} 152 172 \begin{lstlisting}[style=CStyle] … … 160 180 }; 161 181 \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 163 186 164 187 (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) … … 224 247 Names of labels are distinct in an enum declaration. Cforall therefore allows indexing an enum value with its string representation of a label. 225 248 226 \subsection{Range Functions and Iteration (Placeholder)} 249 \subsection{Iteration and Range} 250 A Cforall enum is iterable and supports range function. 227 251 \begin{lstlisting}[caption={Range Functions}, label{lst:range_functions}, style=CStyle] 228 enum Weekday( 229 Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 230 }; 252 struct string; 253 enum(string) Weekday( 254 Monday = "M", Tuesday = "Tu", ... 255 }; 256 for ( i; Weekday ) { sout | i; } 257 >> M Tu W Th F Sat Sun 258 for ( Monday ~= Tuesday ) 259 >> M Tu 231 260 \end{lstlisting} 232 261 … … 249 278 } 250 279 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 280 enum Color.Label; 251 281 Companion( string ) Color = { 252 282 .values = [ "Red", "Green", "Blue" ], … … 255 285 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 256 286 forall( 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} 287 T value( Companion companion, int index ) { return companion.values[ index ]; } 288 T value( Companion, enum Color.Label ); 289 char* label( Companion companion, int index ) { return companion.values[ index ]; } 290 char* label( Companion, enum Color.Label ); 291 292 \end{lstlisting} 293 294 295 \subsection{Companion Trait} 296 Users 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} 262 305 %% 263 306 %% If your work has an appendix, this is the place to put it.
Note: See TracChangeset
for help on using the changeset viewer.