Changeset edc6ea2 for doc


Ignore:
Timestamp:
Apr 28, 2021, 2:02:23 PM (3 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, master
Children:
c1136c56
Parents:
df24d37
Message:

Andrew MMath: LaTeX clean-up. Went through existing to make some of the examples more managable.

Location:
doc/theses/andrew_beach_MMath
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/Makefile

    rdf24d37 redc6ea2  
    3434        ${LATEX} ${BASE}
    3535        ${BIBTEX} ${BUILD}/${BASE}
    36         ${LATEX} ${BASE}
    3736        ${GLOSSARY} ${BUILD}/${BASE}
    3837        ${LATEX} ${BASE}
  • doc/theses/andrew_beach_MMath/cfalab.sty

    rdf24d37 redc6ea2  
    2626
    2727% \newsymbolcmd{<command>}{<replacement text>}
    28 %     Defines <command> to be a symbol that has the given <replacement text>.
     28% Defines <command> to be a symbol that has the given <replacement text>.
    2929\newrobustcmd*\newsymbolcmd[2]{\newrobustcmd{#1}{\cfalab@symbol{#2}}}
    3030\def\cfalab@symbol#1{\@ifnextchar*{#1\cfalab@eatstar}{#1\xspace}}
     
    5050
    5151% \colour{<colour>}{<text>}
    52 % Just \colour but using the LaTeX style instead of TeX style command.
     52% Just \color but using the LaTeX style instead of TeX style command.
    5353\newcommand*\colour[2]{{\color{#1}#2}}
    5454
     
    6060\newrobustcmd*\codePy[1]{\lstinline[language=Python]{#1}}
    6161
     62% Use the listings package to format a block of CFA code.
     63% Extra listings options can be passed in as an optional argument.
    6264\lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{}
    6365
     
    124126    % show blank lines at end of code
    125127    showlines=true,
    126     aboveskip=4pt,                          % spacing above/below code block
     128    % spacing above/below code block
     129    aboveskip=4pt,
    127130    belowskip=0pt,
    128131    % numbering style
     
    137140}
    138141
    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}
    172158
    173159\endinput
  • doc/theses/andrew_beach_MMath/existing.tex

    rdf24d37 redc6ea2  
    2626mangling is:
    2727\begin{cfa}
    28 // name mangling
     28// name mangling on by default
    2929int i; // _X1ii_1
    30 @extern "C"@ {  // no name mangling
     30extern "C" {  // disables name mangling
    3131        int j; // j
    32         @extern "Cforall"@ {  // name mangling
     32        extern "Cforall" {  // enables name mangling
    3333                int k; // _X1ki_1
    3434        }
    35         // no name mangling
    36 }
    37 // name mangling
     35        // revert to no name mangling
     36}
     37// revert to name mangling
    3838\end{cfa}
    3939Both forms of @extern@ affect all the declarations within their nested lexical
     
    5050\begin{cfa}
    5151int i, j;
    52 int @&@ ri = i, @&&@ rri = ri;
     52int & ri = i, && rri = ri;
    5353rri = 3;  // auto-dereference assign to i
    54 @&@ri = @&@j; // rebindable
     54&ri = &j; // rebindable
    5555ri = 5;   // assign to j
    5656\end{cfa}
     
    6464
    6565In general, operator names in \CFA are constructed by bracketing an operator
    66 token with @?@, which indicates the position of the arguments. For example, infixed
    67 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 (@?++@).
     66token with @?@, which indicates the position of the arguments. For example,
     67infixed multiplication is @?*?@ while prefix dereference is @*?@.
     68This syntax make it easy to tell the difference between prefix operations
     69(such as @++?@) and post-fix operations (@?++@).
    7070
    7171The 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.
     72initialization syntax in C. That initialation syntax is also the operator
     73form. \CFA will generate a constructor call each time a variable is declared,
     74passing the initialization arguments to the constructort.
     75\begin{cfa}
     76struct Example { ... };
     77void ?{}(Example & this) { ... }
     78{
     79        Example a;
     80        Example b = {};
     81}
     82void ?{}(Example & this, char first, int num) { ... }
     83{
     84        Example c = {'a', 2};
     85}
     86\end{cfa}
     87Both @a@ and @b@ will be initalized with the first constructor (there is no
     88general way to skip initialation) while @c@ will be initalized with the
     89second.
     90
    7491% 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
     92Similarly destructors use the special name @^?{}@ (the @^@ has no special
     93meaning). They can be called explicatly as well but normally they are
     94implicitly called on a variable when it goes out of scope.
     95\begin{cfa}
     96void ^?{}(Example & this) { ... }
    7997{
    80         T s = @{@ ... @}@;  // same constructor/initialization braces
    81 } // destructor call automatically generated
    82 \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}
     101No operator name is restricted in what function signatures they may be bound
     102to although most of the forms cannot be called in operator form. Some
     103``near-misses" will generate warnings.
     104
     105Whenever a type is defined, \CFA will create a default zero-argument
     106constructor, a copy constructor, a series of argument-per-field constructors
     107and a destructor. All user constructors are defined after this.
     108Because operators are never part of the type definition they may be added
     109at any time, including on built-in types.
    92110
    93111\section{Polymorphism}
     
    105123works on any type @T@:
    106124\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}
     125forall( T ) T identity( T val ) { return val; }
     126int forty_two = identity( 42 );
     127char capital_a = identity( 'A' );
     128\end{cfa}
     129Each 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@
     131in the second).
    110132
    111133To allow a polymorphic function to be separately compiled, the type @T@ must be
     
    115137types used in a function, \eg:
    116138\begin{cfa}
    117 forall( T @| { void do_once(T); }@) // assertion
     139forall( T | { void do_once(T); })
    118140void do_twice(T value) {
    119141        do_once(value);
    120142        do_once(value);
    121143}
    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}
    128145
    129146A polymorphic function can be used in the same way as a normal function.  The
     
    132149all the variables replaced with the concrete types from the arguments) is
    133150defined at a call site.
     151\begin{cfa}
     152void do_once(int i) { ... }
     153int i;
     154do_twice(i);
     155\end{cfa}
     156Any object with a type fulfilling the assertion may be passed as an argument to
     157a @do_twice@ call.
    134158
    135159Note, a function named @do_once@ is not required in the scope of @do_twice@ to
     
    138162call.
    139163\begin{cfa}
    140 void do_once(double y) { ... } // global
     164void do_once(double y) { ... }
    141165int quadruple(int x) {
    142         void do_once(int y) { y = y * 2; } // local
    143         do_twice(x); // using local "do_once"
     166        void do_once(int y) { y = y * 2; }
     167        do_twice(x);
    144168        return x;
    145169}
     
    150174function. The matched assertion function is then passed as a function pointer
    151175to @do_twice@ and called within it.
     176The global definition of @do_once@ is ignored.
    152177
    153178To avoid typing long lists of assertions, constraints can be collect into
     
    161186and the @forall@ list in the previous example is replaced with the trait.
    162187\begin{cfa}
    163 forall(dtype T | @done_once(T)@)
     188forall(dtype T | done_once(T))
    164189\end{cfa}
    165190In general, a trait can contain an arbitrary number of assertions, both
     
    172197declarations instead of parameters, returns, and local variable declarations.
    173198\begin{cfa}
    174 forall(dtype @T@)
     199forall(dtype T)
    175200struct node {
    176         node(@T@) * next;  // generic linked node
    177         @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 \Cpp
    182 template usage, a polymorphic-type usage must specify a type parameter.
     201        node(T) * next;  // generic linked node
     202        T * data;
     203}
     204node(int) inode;
     205\end{cfa}
     206The generic type @node(T)@ is an example of a polymorphic type usage.  Like \Cpp
     207template usage, a polymorphic type usage must specify a type parameter.
    183208
    184209There are many other polymorphism features in \CFA but these are the ones used
     
    219244Each coroutine has a @main@ function, which takes a reference to a coroutine
    220245object 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}
     247void main(CountUp & this) {
     248    for (unsigned int next = 0 ; true ; ++next) {
     249                next = up;
     250                suspend;$\label{suspend}$
    228251        }
    229252}
     
    254277@mutex@.
    255278\begin{cfa}
    256 void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
     279void example(MonitorA & mutex argA, MonitorB & mutex argB);
    257280\end{cfa}
    258281When the function is called, it implicitly acquires the monitor lock for all of
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    rdf24d37 redc6ea2  
    8181}
    8282
    83 %
     83% Does nothing, ignores \href tags (redefined by hyperref package).
    8484\newcommand{\href}[1]{#1}
    85 % Does nothing, but defines the command so the
    86 % print-optimized version will ignore \href tags (redefined by hyperref pkg).
    87 % Anything defined here may be redefined by packages added below...
    8885
    8986% For a nomenclature (optional; available from ctan.org)
     
    201198\makeglossaries
    202199
     200
    203201\lstMakeShortInline@
    204202
     
    207205% CFA default lnaguage
    208206\lstset{language=CFA,basicstyle=\linespread{0.9}\tt}
     207\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
    209208% Annotations from Peter:
    210209\newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
Note: See TracChangeset for help on using the changeset viewer.