Changes in / [e8b1f23c:34b6a7b6]
- Location:
- doc/theses/colby_parsons_MMAth
- Files:
-
- 4 edited
-
Makefile (modified) (1 diff)
-
style/style.tex (modified) (1 diff)
-
text/CFA_intro.tex (modified) (13 diffs)
-
thesis.tex (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/Makefile
re8b1f23c r34b6a7b6 96 96 97 97 ${BASE}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${DATA} \ 98 style/style.tex${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build}98 ${Macros}/common.tex ${Macros}/indexstyle local.bib ../../bibliography/pl.bib | ${Build} 99 99 # Must have *.aux file containing citations for bibtex 100 100 if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi -
doc/theses/colby_parsons_MMAth/style/style.tex
re8b1f23c r34b6a7b6 1 1 \input{common} 2 \CFAStyle % CFA code-style3 \lstset{language=CFA} % default language4 2 5 3 \lstdefinestyle{defaultStyle}{ -
doc/theses/colby_parsons_MMAth/text/CFA_intro.tex
re8b1f23c r34b6a7b6 9 9 \CFA is a layer over C, is transpiled to C and is largely considered to be an extension of C. 10 10 Beyond C, it adds productivity features, libraries, a type system, and many other language constructions. 11 However, \CFA stays true to C as a language, with most code revolving around @struct@'s and routines, and respects the same rules as C.12 \CFA is not object oriented as it has no notion of @this@and no classes or methods, but supports some object oriented adjacent ideas including costructors, destructors, and limited inheritance.11 However, \CFA stays true to C as a language, with most code revolving around \code{struct}'s and routines, and respects the same rules as C. 12 \CFA is not object oriented as it has no notion of \code{this} and no classes or methods, but supports some object oriented adjacent ideas including costructors, destructors, and limited inheritance. 13 13 \CFA is rich with interesting features, but a subset that is pertinent to this work will be discussed. 14 14 … … 17 17 References in \CFA are a layer of syntactic sugar over pointers to reduce the number of ref/deref operations needed with pointer usage. 18 18 Some examples of references in \CFA are shown in Listing~\ref{l:cfa_ref}. 19 Another related item to note is that the \CFA equivalent of \CC's @nullptr@ is @0p@.20 21 \begin{cfa }[caption={Example of \CFA references},label={l:cfa_ref}]19 Another related item to note is that the \CFA equivalent of \CC's \code{nullptr} is \code{0p}. 20 21 \begin{cfacode}[caption={Example of \CFA references},label={l:cfa_ref}] 22 22 int i = 2; 23 int & ref_i = i; $\C[1.5in]{// declare ref to i}$24 int * ptr_i = &i; $\C{// ptr to i}$23 int & ref_i = i; // declare ref to i 24 int * ptr_i = &i; // ptr to i 25 25 26 26 // address of ref_i is the same as address of i 27 27 assert( &ref_i == ptr_i ); 28 28 29 int && ref_ref_i = ref_i; $\C{// can have a ref to a ref}$30 ref_i = 3; $\C{// set i to 3}$29 int && ref_ref_i = ref_i; // can have a ref to a ref 30 ref_i = 3; // set i to 3 31 31 int new_i = 4; 32 32 33 33 // syntax to rebind ref_i (must cancel implicit deref) 34 &ref_i = &new_i; $\C{// (\&*)ref\_i = \&new\_i; (sets underlying ptr)}\CRT$35 \end{cfa }34 &ref_i = &new_i; // (&*)ref_i = &new_i; (sets underlying ptr) 35 \end{cfacode} 36 36 37 37 … … 43 43 44 44 45 \begin{cfa }[caption={Example of \CFA function overloading},label={l:cfa_overload}]45 \begin{cfacode}[caption={Example of \CFA function overloading},label={l:cfa_overload}] 46 46 int foo() { printf("A\n"); return 0;} 47 47 int foo( int bar ) { printf("B\n"); return 1; } … … 57 57 foo( a ); // prints 3 58 58 } 59 \end{cfa }59 \end{cfacode} 60 60 61 61 … … 68 68 69 69 70 \begin{cfa }[tabsize=3,caption={Usage of \CFA with statement},label={l:cfa_with}]70 \begin{cfacode}[tabsize=3,caption={Usage of \CFA with statement},label={l:cfa_with}] 71 71 struct obj { 72 72 int a, b, c; … … 100 100 p.y = 2.71; 101 101 } 102 \end{cfa }102 \end{cfacode} 103 103 104 104 … … 109 109 110 110 111 \begin{cfa }[tabsize=3,caption={Example of \CFA operators},label={l:cfa_operate}]111 \begin{cfacode}[tabsize=3,caption={Example of \CFA operators},label={l:cfa_operate}] 112 112 struct coord { 113 113 double x; … … 125 125 (op2.x*op2.x + op2.y*op2.y + op2.z*op2.z); 126 126 } 127 \end{cfa }127 \end{cfacode} 128 128 129 129 … … 134 134 135 135 136 \begin{cfa }[tabsize=3,caption={Example of \CFA constructors and destructors},label={l:cfa_ctor}]136 \begin{cfacode}[tabsize=3,caption={Example of \CFA constructors and destructors},label={l:cfa_ctor}] 137 137 struct discrete_point { 138 138 int x; … … 157 157 discrete_point dp{ 2, -4 }; // specialized ctor 158 158 } // ^d{}, ^p{}, ^dp{} all called as they go out of scope 159 \end{cfa }159 \end{cfacode} 160 160 161 161 … … 165 165 166 166 \subsection{Parametric Polymorphism} 167 \CFA provides parametric polymorphism in the form of @forall@, and @trait@s.168 A @forall@takes in a set of types and a list of constraints.169 The declarations that follow the @forall@are parameterized over the types listed that satisfy the constraints.170 Sometimes the list of constraints can be long, which is where a @trait@can be used.171 A @trait@is a collection of constraints that is given a name and can be reused in foralls.167 \CFA provides parametric polymorphism in the form of \code{forall}, and \code{trait}s. 168 A \code{forall} takes in a set of types and a list of constraints. 169 The declarations that follow the \code{forall} are parameterized over the types listed that satisfy the constraints. 170 Sometimes the list of constraints can be long, which is where a \code{trait} can be used. 171 A \code{trait} is a collection of constraints that is given a name and can be reused in foralls. 172 172 An example of the usage of parametric polymorphism in \CFA is shown in Listing~\ref{l:cfa_poly}. 173 173 174 \begin{cfa }[tabsize=3,caption={Example of \CFA polymorphism},label={l:cfa_poly}]174 \begin{cfacode}[tabsize=3,caption={Example of \CFA polymorphism},label={l:cfa_poly}] 175 175 // sized() is a trait that means the type has a size 176 176 forall( V & | sized(V) ) // type params for trait … … 215 215 } 216 216 217 \end{cfa }217 \end{cfacode} 218 218 219 219 \subsection{Inheritance} 220 220 Inheritance in \CFA copies its style from Plan-9 C nominal inheritance. 221 In \CFA structs can @inline@another struct type to gain its fields and to be able to be passed to routines that require a parameter of the inlined type.221 In \CFA structs can \code{inline} another struct type to gain its fields and to be able to be passed to routines that require a parameter of the inlined type. 222 222 An example of \CFA inheritance is shown in Listing~\ref{l:cfa_inherit}. 223 223 224 \begin{cfa }[tabsize=3,caption={Example of \CFA inheritance},label={l:cfa_inherit}]224 \begin{cfacode}[tabsize=3,caption={Example of \CFA inheritance},label={l:cfa_inherit}] 225 225 struct one_d { double x; }; 226 226 struct two_d { … … 260 260 print_food( p ); // prints 5 261 261 } 262 \end{cfa }263 264 262 \end{cfacode} 263 264 -
doc/theses/colby_parsons_MMAth/thesis.tex
re8b1f23c r34b6a7b6 98 98 \hypersetup{ 99 99 plainpages=false, % needed if Roman numbers in frontpages 100 unicode=false, % non-Latin characters in Acrobat 's bookmarks101 pdftoolbar=true, % show Acrobat 's toolbar?102 pdfmenubar=true, % show Acrobat 's menu?100 unicode=false, % non-Latin characters in Acrobat’s bookmarks 101 pdftoolbar=true, % show Acrobat’s toolbar? 102 pdfmenubar=true, % show Acrobat’s menu? 103 103 pdffitwindow=false, % window fit to page when opened 104 104 pdfstartview={FitH}, % fits the width of the page to the window
Note:
See TracChangeset
for help on using the changeset viewer.