source: doc/theses/jiada_liang_MMath/main.tex @ 85034ed

Last change on this file since 85034ed was 85034ed, checked in by JiadaL <j82liang@…>, 9 months ago

Initial commit

  • Property mode set to 100644
File size: 10.0 KB
Line 
1%%
2%% This is file `sample-manuscript.tex',
3%% generated with the docstrip utility.
4%%
5%% The original source files were:
6%%
7%% samples.dtx  (with options: `manuscript')
8%%
9%% IMPORTANT NOTICE:
10%%
11%% For the copyright see the source file.
12%%
13%% Any modified versions of this file must be renamed
14%% with new filenames distinct from sample-manuscript.tex.
15%%
16%% For distribution of the original source see the terms
17%% for copying and modification in the file samples.dtx.
18%%
19%% This generated file may be distributed as long as the
20%% original source files, as listed above, are part of the
21%% same distribution. (The sources need not necessarily be
22%% in the same archive or directory.)
23%%
24%% Commands for TeXCount
25%TC:macro \cite [option:text,text]
26%TC:macro \citep [option:text,text]
27%TC:macro \citet [option:text,text]
28%TC:envir table 0 1
29%TC:envir table* 0 1
30%TC:envir tabular [ignore] word
31%TC:envir displaymath 0 word
32%TC:envir math 0 word
33%TC:envir comment 0 0
34%%
35%%
36%% The first command in your LaTeX source must be the \documentclass command.
37\documentclass[manuscript,screen,review]{acmart}
38\usepackage{xcolor}
39\usepackage{listings}
40\usepackage[ligature, inference]{semantic}
41\usepackage{array}
42
43\definecolor{mGreen}{rgb}{0,0.6,0}
44\definecolor{mGray}{rgb}{0.5,0.5,0.5}
45\definecolor{mPurple}{rgb}{0.58,0,0.82}
46\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
47
48\lstdefinestyle{CStyle}{
49    backgroundcolor=\color{backgroundColour},   
50    commentstyle=\color{mGreen},
51    keywordstyle=\color{magenta},
52    numberstyle=\tiny\color{mGray},
53    stringstyle=\color{mPurple},
54    basicstyle=\footnotesize,
55    breakatwhitespace=false,         
56    breaklines=true,                 
57    captionpos=b,                   
58    keepspaces=true,                 
59    numbers=left,                   
60    numbersep=5pt,                 
61    showspaces=false,               
62    showstringspaces=false,
63    showtabs=false,                 
64    tabsize=2,
65    language=C
66}
67
68%%
69%% \BibTeX command to typeset BibTeX logo in the docs
70\AtBeginDocument{%
71  \providecommand\BibTeX{{%
72    \normalfont B\kern-0.5em{\scshape i\kern-0.25em b}\kern-0.8em\TeX}}}
73
74
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
108%%
109%% end of the preamble, start of the body of the document source.
110\begin{document}
111
112%%
113%% The "title" command has an optional parameter,
114%% allowing the author to define a "short title" to be used in page headers.
115\title{Enumeration in Cforall}
116
117%%
118%% The "author" command and its associated commands are used to define
119%% the authors and their affiliations.
120%% Of note is the shared affiliation of the first two authors, and the
121%% "authornote" and "authornotemark" commands
122%% used to denote shared contribution to the research.
123\author{Jiada Liang}
124
125
126%%
127%% The abstract is a short summary of the work to be presented in the
128%% article.
129\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.
131\end{abstract}
132
133%%
134%% The code below is generated by the tool at http://dl.acm.org/ccs.cfm.
135%% Please copy and paste the code instead of the example below.
136%%
137
138
139%%
140%% This command processes the author and affiliation and title
141%% information and builds the first part of the formatted document.
142\maketitle
143
144\section{C-Style Enum}
145\begin{lstlisting}[style=CStyle]
146enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
147\end{lstlisting}
148Cforall 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}
151\subsection{Enumerable Type}
152\begin{lstlisting}[style=CStyle]
153forall(T)
154trait enumerable {
155  void ?()( T & t, zero_t );
156  void ?()( T & t, one_t );
157  S& ?+=?( T & t, one_t );
158  void ?{}( T &, T );
159  T ?{}( T &, T );
160};
161\end{lstlisting}
162A type is enumerable in Cforall if it has defined 0, 1, increment operator, copy constructor, and copy assignment operator.
163
164(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)
165\begin{lstlisting}[caption={An example enumerable type}, label{lst:sample_enumerable}, style=CStyle]
166struct Type { int i; };
167void ?()( Type & t, zero_t ) { t.i = 0; };
168void ?()( Type & t, one_t ) { t.i = 1; };
169int ?!=?( Type t, zero_t ) { return t.i != 0; };
170S& ?+=?( Type & t, one_t ) { t.i += 1; return t; };
171void ?()( Type & t, Type rhs ) { t.i = rhs.i; };
172Type ?()( Type & t, Type rhs ) { t.i = rhs.i; return t; };
173\end{lstlisting}
174
175A Cforall-enum is a C-enum parameterized by an enumerable type. For example,  $enum(int)$ turns a C-enum into a Cforall-enum.
176\begin{lstlisting}[caption={An example Cforall enum}, label{lst:sample_cforall_enum}, style=CStyle]
177enum Color(Type) { Red, Green, Blue };
178
179> Type Color.values[] = { 0, values[0]++, values[1]++ };
180> enum Color.Label { Red_Label, Green_Label, Blue_Label };
181\end{lstlisting}
182Declaring a Cforall-enum, the compiler defines a C-enum names every element in the Cforall-enum, and an array that stores Cforall enumeration values.
183
184\subsection{Cforall Enumerations Behaviour}
185An instance of Cforall-enum (denoted as $<enum\_instance>$) has a label, the defined enum name. The label can be retrieved by calling the function $label()$ on a $<enum\_instance>$. The $value()$ function on the other hand returns the value used to initialize the Cforall-enum.
186
187Cforall-enum supports a qualified expression. The syntax of the qualified expression for Cforall-enum is $$<enum\_type\_name>.<enum\_instance\_name>$$. In the $Color$ example, $Color$ is a $<enum\_type\_name>$ and $Red$, $Green$, $Blue$ are $<enum\_instance\_name>$.
188
189\begin{lstlisting}[caption={An example Cforall enum}, label{lst:sample_cforall_enum_usage}, style=CStyle]
190enum Color red = Color.Red;
191> enum Color.Label red = = Color.Label.Red_Label;
192Type instance = Color.Red;
193> Type instance = Color.values[ Color.Label.Red_Label ];
194\end{lstlisting}
195
196The expression $Color.Red$ is overloaded to represent both $value(Color.Red)$ and $label(Color.Red)$. The expression returns the $label(Color.Red)$ by default but returns $value()$ whenever the $value()$ is a closer candidate in the context. [more explanation] In \ref{lst:sample_cforall_enum_usage}, when assigned to an enum variable, $Color.Red$ returns the label. This is to reduce the memory to store a Cforall-enum variable. In an assignment expression when the left-hand-side expects a $Type$, the resolution finds $value(Color.Red)$ is a better candidate than $label(Color.Red)$, and returns the value instead.
197
198\subsection{Enum Type Functions}
199\begin{lstlisting}[caption={Enum Type Functions}, label{lst:cforall_enum_functions}, style=CStyle]
200enum Color(string) { // assume String has been defined as an enumerable type
201    R = "Red", G = "Green", B = "Blue"
202};
203values( Color );
204> [ String("Red"), String("Green"), String("Blue") ];
205label_strings( Color );
206> [ "R", "G", "B" ];
207enum Color green = Color.G;
208
209label_string( Color, green );
210> "G"
211label( Color, green );
212> 1
213value( Color, green ) ;
214> "Green"
215value( Color, "G" );
216> "Green"
217label( Color, "G" );
218> 1
219value( Color, "DNE" );
220> (null)
221value( Color, 1 ); // "1" is the label "G"
222> "Green"
223\end{lstlisting}
224Names of labels are distinct in an enum declaration. Cforall therefore allows indexing an enum value with its string representation of a label.
225
226\subsection{Range Functions and Iteration (Placeholder)}
227\begin{lstlisting}[caption={Range Functions}, label{lst:range_functions}, style=CStyle]
228enum Weekday(
229    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
230};
231\end{lstlisting}
232
233\section{Implementation}
234
235\subsection{Companion Object}
236The intuition to create a companion object is that functions that support enumeration features need static information of an enumeration class. For example, values() returns an array of values defined for the enumeration. $label( Color, "G" )$ needs information about enum names defined for the enum class $Color$. Theoretically, enum-type functions can be defined as functions that take $TypeName$ expression as the first parameter. An alternative approach is to define that "companion object".
237
238\begin{lstlisting}[caption={Enum Type Functions}, label{lst:cforall_enum_functions}, style=CStyle]
239struct string;
240enum Color( string ) { 
241    R = "Red", G = "Green", B = "Blue"
242};
243
244forall( T | enumerable(T) )  {
245    struct Companion {
246        T* values;
247        char** labels;
248    };
249}
250>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
251Companion( string ) Color = { 
252    .values = [ "Red", "Green", "Blue" ],
253    .labels = [ "R", "G", "B" ]
254};
255>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
256forall( T | enumerable(T) )
257T* value( Companion, int );
258char* label( Companion, int );
259\end{lstlisting}
260
261\subsection{TODO - Type trait for Cforall - Enum}
262%%
263%% If your work has an appendix, this is the place to put it.
264\appendix
265
266
267\end{document}
268\endinput
269%%
270%% End of file `sample-manuscript.tex'.
Note: See TracBrowser for help on using the repository browser.