- Timestamp:
- Apr 28, 2021, 2:02:23 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c1136c56
- Parents:
- df24d37
- Location:
- doc/theses/andrew_beach_MMath
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/Makefile
rdf24d37 redc6ea2 34 34 ${LATEX} ${BASE} 35 35 ${BIBTEX} ${BUILD}/${BASE} 36 ${LATEX} ${BASE}37 36 ${GLOSSARY} ${BUILD}/${BASE} 38 37 ${LATEX} ${BASE} -
doc/theses/andrew_beach_MMath/cfalab.sty
rdf24d37 redc6ea2 26 26 27 27 % \newsymbolcmd{<command>}{<replacement text>} 28 % 28 % Defines <command> to be a symbol that has the given <replacement text>. 29 29 \newrobustcmd*\newsymbolcmd[2]{\newrobustcmd{#1}{\cfalab@symbol{#2}}} 30 30 \def\cfalab@symbol#1{\@ifnextchar*{#1\cfalab@eatstar}{#1\xspace}} … … 50 50 51 51 % \colour{<colour>}{<text>} 52 % Just \colo ur but using the LaTeX style instead of TeX style command.52 % Just \color but using the LaTeX style instead of TeX style command. 53 53 \newcommand*\colour[2]{{\color{#1}#2}} 54 54 … … 60 60 \newrobustcmd*\codePy[1]{\lstinline[language=Python]{#1}} 61 61 62 % Use the listings package to format a block of CFA code. 63 % Extra listings options can be passed in as an optional argument. 62 64 \lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{} 63 65 … … 124 126 % show blank lines at end of code 125 127 showlines=true, 126 aboveskip=4pt, % spacing above/below code block 128 % spacing above/below code block 129 aboveskip=4pt, 127 130 belowskip=0pt, 128 131 % numbering style … … 137 140 } 138 141 139 \newcommand{\abbrevFont}{\textit} % set empty for no italics 140 \@ifundefined{eg}{ 141 \newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.} 142 \newcommand*{\eg}{% 143 \@ifnextchar{,}{\EG}% 144 {\@ifnextchar{:}{\EG}% 145 {\EG,\xspace}}% 146 }}{}% 147 \@ifundefined{ie}{ 148 \newcommand{\IE}{\abbrevFont{i}.\abbrevFont{e}.} 149 \newcommand*{\ie}{% 150 \@ifnextchar{,}{\IE}% 151 {\@ifnextchar{:}{\IE}% 152 {\IE,\xspace}}% 153 }}{}% 154 \@ifundefined{etc}{ 155 \newcommand{\ETC}{\abbrevFont{etc}} 156 \newcommand*{\etc}{% 157 \@ifnextchar{.}{\ETC}% 158 {\ETC.\xspace}% 159 }}{}% 160 \@ifundefined{etal}{ 161 \newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}} 162 \newcommand*{\etal}{% 163 \@ifnextchar{.}{\protect\ETAL}% 164 {\protect\ETAL.\xspace}% 165 }}{}% 166 \@ifundefined{viz}{ 167 \newcommand{\VIZ}{\abbrevFont{viz}} 168 \newcommand*{\viz}{% 169 \@ifnextchar{.}{\VIZ}% 170 {\VIZ.\xspace}% 171 }}{}% 142 % A couple of abbreviations are provided. Just ones someone liked. 143 % 144 % Abbreviation formatting commands (renew to customize): 145 \newcommand{\abbrevFont}{\textit} 146 % 147 % Abbreviations that, if not followed by a comma or colon, add a comma. 148 \newrobustcmd*\cfalab@abbrev@comma{% 149 \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}} 150 \providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma} 151 \providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma} 152 % 153 % Abbreviations that, if not followed by a period, add a period. 154 \newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}} 155 \providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period} 156 \providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period} 157 \providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period} 172 158 173 159 \endinput -
doc/theses/andrew_beach_MMath/existing.tex
rdf24d37 redc6ea2 26 26 mangling is: 27 27 \begin{cfa} 28 // name mangling 28 // name mangling on by default 29 29 int i; // _X1ii_1 30 @extern "C"@ { // noname mangling30 extern "C" { // disables name mangling 31 31 int j; // j 32 @extern "Cforall"@ { //name mangling32 extern "Cforall" { // enables name mangling 33 33 int k; // _X1ki_1 34 34 } 35 // no name mangling36 } 37 // name mangling35 // revert to no name mangling 36 } 37 // revert to name mangling 38 38 \end{cfa} 39 39 Both forms of @extern@ affect all the declarations within their nested lexical … … 50 50 \begin{cfa} 51 51 int i, j; 52 int @&@ ri = i, @&&@rri = ri;52 int & ri = i, && rri = ri; 53 53 rri = 3; // auto-dereference assign to i 54 @&@ri = @&@j; // rebindable54 &ri = &j; // rebindable 55 55 ri = 5; // assign to j 56 56 \end{cfa} … … 64 64 65 65 In general, operator names in \CFA are constructed by bracketing an operator 66 token with @?@, which indicates the position of the arguments. For example, infixed67 multiplication is @?*?@ while prefix dereference is @*?@. This syntax make it 68 easy to tell the difference between prefix operations (such as @++?@) and 69 post-fix operations (@?++@).66 token with @?@, which indicates the position of the arguments. For example, 67 infixed multiplication is @?*?@ while prefix dereference is @*?@. 68 This syntax make it easy to tell the difference between prefix operations 69 (such as @++?@) and post-fix operations (@?++@). 70 70 71 71 The special name for a constructor is @?{}@, which comes from the 72 initialization syntax in C. The special name for a destructor is @^{}@, where 73 the @^@ has no special meaning. 72 initialization syntax in C. That initialation syntax is also the operator 73 form. \CFA will generate a constructor call each time a variable is declared, 74 passing the initialization arguments to the constructort. 75 \begin{cfa} 76 struct Example { ... }; 77 void ?{}(Example & this) { ... } 78 { 79 Example a; 80 Example b = {}; 81 } 82 void ?{}(Example & this, char first, int num) { ... } 83 { 84 Example c = {'a', 2}; 85 } 86 \end{cfa} 87 Both @a@ and @b@ will be initalized with the first constructor (there is no 88 general way to skip initialation) while @c@ will be initalized with the 89 second. 90 74 91 % I don't like the \^{} symbol but $^\wedge$ isn't better. 75 \begin{cfa} 76 struct T { ... }; 77 void ?@{}@(@T &@ this, ...) { ... } // constructor 78 void ?@^{}@(@T &@ this, ...) { ... } // destructor 92 Similarly destructors use the special name @^?{}@ (the @^@ has no special 93 meaning). They can be called explicatly as well but normally they are 94 implicitly called on a variable when it goes out of scope. 95 \begin{cfa} 96 void ^?{}(Example & this) { ... } 79 97 { 80 T s = @{@ ... @}@; // same constructor/initialization braces 81 } // destructor call automatically generated82 \end{cfa} 83 The first parameter is a reference parameter to the type for the 84 constructor/destructor. Destructors may have multiple parameters. The compiler 85 implicitly matches an overloaded constructor @void ^?{}(T &, ...);@ to an 86 object declaration with associated initialization, and generates a construction 87 call after the object is allocated. When an object goes out of scope, the 88 matching overloaded destructor @void ^?{}(T &);@ is called. Without explicit 89 definition, \CFA creates a default and copy constructor, destructor and 90 assignment (like \Cpp). It is possible to define constructors/destructors for 91 basic and existing types (unlike \Cpp).98 Example d; 99 } // <- implicit destructor call 100 \end{cfa} 101 No operator name is restricted in what function signatures they may be bound 102 to although most of the forms cannot be called in operator form. Some 103 ``near-misses" will generate warnings. 104 105 Whenever a type is defined, \CFA will create a default zero-argument 106 constructor, a copy constructor, a series of argument-per-field constructors 107 and a destructor. All user constructors are defined after this. 108 Because operators are never part of the type definition they may be added 109 at any time, including on built-in types. 92 110 93 111 \section{Polymorphism} … … 105 123 works on any type @T@: 106 124 \begin{cfa} 107 @forall( T )@ @T@ identity( @T@ val ) { return val; } 108 int forty_two = identity( 42 ); // T bound to int, forty_two == 42 109 \end{cfa} 125 forall( T ) T identity( T val ) { return val; } 126 int forty_two = identity( 42 ); 127 char capital_a = identity( 'A' ); 128 \end{cfa} 129 Each use of a polymorphic declaration will resolve its polymorphic parameters 130 (in this case, just @T@) to concrete types (@int@ in the first use and @char@ 131 in the second). 110 132 111 133 To allow a polymorphic function to be separately compiled, the type @T@ must be … … 115 137 types used in a function, \eg: 116 138 \begin{cfa} 117 forall( T @| { void do_once(T); }@) // assertion139 forall( T | { void do_once(T); }) 118 140 void do_twice(T value) { 119 141 do_once(value); 120 142 do_once(value); 121 143 } 122 void do_once(@int@ i) { ... } // provide assertion 123 @int@ i; 124 do_twice(i); // implicitly pass assertion do_once to do_twice 125 \end{cfa} 126 Any object with a type fulfilling the assertion may be passed as an argument to 127 a @do_twice@ call. 144 \end{cfa} 128 145 129 146 A polymorphic function can be used in the same way as a normal function. The … … 132 149 all the variables replaced with the concrete types from the arguments) is 133 150 defined at a call site. 151 \begin{cfa} 152 void do_once(int i) { ... } 153 int i; 154 do_twice(i); 155 \end{cfa} 156 Any object with a type fulfilling the assertion may be passed as an argument to 157 a @do_twice@ call. 134 158 135 159 Note, a function named @do_once@ is not required in the scope of @do_twice@ to … … 138 162 call. 139 163 \begin{cfa} 140 void do_once(double y) { ... } // global164 void do_once(double y) { ... } 141 165 int quadruple(int x) { 142 void do_once(int y) { y = y * 2; } // local143 do_twice(x); // using local "do_once"166 void do_once(int y) { y = y * 2; } 167 do_twice(x); 144 168 return x; 145 169 } … … 150 174 function. The matched assertion function is then passed as a function pointer 151 175 to @do_twice@ and called within it. 176 The global definition of @do_once@ is ignored. 152 177 153 178 To avoid typing long lists of assertions, constraints can be collect into … … 161 186 and the @forall@ list in the previous example is replaced with the trait. 162 187 \begin{cfa} 163 forall(dtype T | @done_once(T)@)188 forall(dtype T | done_once(T)) 164 189 \end{cfa} 165 190 In general, a trait can contain an arbitrary number of assertions, both … … 172 197 declarations instead of parameters, returns, and local variable declarations. 173 198 \begin{cfa} 174 forall(dtype @T@)199 forall(dtype T) 175 200 struct node { 176 node( @T@) * next; // generic linked node177 @T@* data;178 } 179 node( @int@) inode;180 \end{cfa} 181 The generic type @node(T)@ is an example of a polymorphic -type usage. Like \Cpp182 template usage, a polymorphic -type usage must specify a type parameter.201 node(T) * next; // generic linked node 202 T * data; 203 } 204 node(int) inode; 205 \end{cfa} 206 The generic type @node(T)@ is an example of a polymorphic type usage. Like \Cpp 207 template usage, a polymorphic type usage must specify a type parameter. 183 208 184 209 There are many other polymorphism features in \CFA but these are the ones used … … 219 244 Each coroutine has a @main@ function, which takes a reference to a coroutine 220 245 object and returns @void@. 221 \begin{cfa}[numbers=left] 222 void main(@CountUp & this@) { // argument matches trait is_coroutine 223 unsigned int up = 0; // retained between calls 224 while (true) { 225 next = up; // make "up" available outside function 226 @suspend;@$\label{suspend}$ 227 up += 1; 246 \begin{cfa} 247 void main(CountUp & this) { 248 for (unsigned int next = 0 ; true ; ++next) { 249 next = up; 250 suspend;$\label{suspend}$ 228 251 } 229 252 } … … 254 277 @mutex@. 255 278 \begin{cfa} 256 void example(MonitorA & @mutex@ argA, MonitorB & @mutex@argB);279 void example(MonitorA & mutex argA, MonitorB & mutex argB); 257 280 \end{cfa} 258 281 When the function is called, it implicitly acquires the monitor lock for all of -
doc/theses/andrew_beach_MMath/uw-ethesis.tex
rdf24d37 redc6ea2 81 81 } 82 82 83 % 83 % Does nothing, ignores \href tags (redefined by hyperref package). 84 84 \newcommand{\href}[1]{#1} 85 % Does nothing, but defines the command so the86 % print-optimized version will ignore \href tags (redefined by hyperref pkg).87 % Anything defined here may be redefined by packages added below...88 85 89 86 % For a nomenclature (optional; available from ctan.org) … … 201 198 \makeglossaries 202 199 200 203 201 \lstMakeShortInline@ 204 202 … … 207 205 % CFA default lnaguage 208 206 \lstset{language=CFA,basicstyle=\linespread{0.9}\tt} 207 \lstset{moredelim=**[is][\protect\color{red}]{@}{@}} 209 208 % Annotations from Peter: 210 209 \newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
Note: See TracChangeset
for help on using the changeset viewer.