Changes in / [3eb55f98:c993b15]


Ignore:
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    r3eb55f98 rc993b15  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Apr 27 12:03:17 2021
    14 %% Update Count     : 539
     13%% Last Modified On : Sun Feb 14 15:52:46 2021
     14%% Update Count     : 524
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    102102\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    103103\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
    104 \renewcommand\subparagraph{\@startsection{subparagraph}{4}{\z@}{-1.5ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries\itshape}}
    105104
    106105% index macros
     
    285284showlines=true,                                                 % show blank lines at end of code
    286285aboveskip=4pt,                                                  % spacing above/below code block
    287 belowskip=2pt,
     286belowskip=0pt,
    288287numberstyle=\footnotesize\sf,                   % numbering style
    289288% replace/adjust listing characters that look bad in sanserif
     
    298297\lstset{
    299298language=CFA,
    300 %moredelim=**[is][\color{red}]{@}{@},   % red highlighting @...@
    301 moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
     299moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
     300%moredelim=**[is][\color{red}]{®}{®},   % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    302301%moredelim=**[is][\color{blue}]{ß}{ß},  % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
    303302%moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
  • doc/theses/andrew_beach_MMath/Makefile

    r3eb55f98 rc993b15  
    3434        ${LATEX} ${BASE}
    3535        ${BIBTEX} ${BUILD}/${BASE}
     36        ${LATEX} ${BASE}
    3637        ${GLOSSARY} ${BUILD}/${BASE}
    3738        ${LATEX} ${BASE}
  • doc/theses/andrew_beach_MMath/cfalab.sty

    r3eb55f98 rc993b15  
    1010
    1111% Other packages required.
    12 %
    13 % Access to new basic LaTeX tools and other low level commands.
    1412\RequirePackage{etoolbox}
    15 % Code formatting tools and environments.
    1613\RequirePackage{listings}
    17 % Automatically adds spaces.
    1814\RequirePackage{xspace}
    19 % Improved reference tools.
    20 \RequirePackage[nospace]{varioref}
    2115
    2216% Symbols: All symbols are zero argument robust commands with special rules
     
    2620
    2721% \newsymbolcmd{<command>}{<replacement text>}
    28 % Defines <command> to be a symbol that has the given <replacement text>.
     22%     Defines <command> to be a symbol that has the given <replacement text>.
    2923\newrobustcmd*\newsymbolcmd[2]{\newrobustcmd{#1}{\cfalab@symbol{#2}}}
    3024\def\cfalab@symbol#1{\@ifnextchar*{#1\cfalab@eatstar}{#1\xspace}}
     
    3428\newsymbolcmd\CFA{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}}
    3529% C++ with kerning. (No standard number support.)
    36 \newsymbolcmd\Cpp{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}}
     30\newsymbolcmd\CPP{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}}
    3731
    38 % This is executed very early in the \begin{document} code, before the
    39 % document's contents but after packages are loaded.
     32% This is executed very early in the \begin{document} code.
    4033\AtEndPreamble{
    4134  \@ifpackageloaded{hyperref}{
     
    4336    \pdfstringdefDisableCommands{
    4437      \def\CFA{CFA}
    45       \def\Cpp{C++}
    46       \def\lstinline{}
     38      \def\CPP{C++}
    4739    }
    4840  }{}
    4941}
    50 
    51 % \colour{<colour>}{<text>}
    52 % Just \color but using the LaTeX style instead of TeX style command.
    53 \newcommand*\colour[2]{{\color{#1}#2}}
    54 
    55 % \code*{<code>}
    56 % Use the listings package to format a snipit of <code>.
    57 \newrobustcmd*\codeCFA[1]{\lstinline[language=CFA]{#1}}
    58 \newrobustcmd*\codeC[1]{\lstinline[language=C]{#1}}
    59 \newrobustcmd*\codeCpp[1]{\lstinline[language=C++]{#1}}
    60 \newrobustcmd*\codePy[1]{\lstinline[language=Python]{#1}}
    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.
    64 \lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{}
    65 
    66 % \settextunderscore{(new|old)}
    67 % Redefines the underscore either as a new repersentation or the old one.
    68 % Not that some other packages (ex. hyperref) can override this. Set it up
    69 % after loading them.
    70 \let\cfalab@textunderscore@old=\textunderscore
    71 \newcommand\cfalab@textunderscore@new{%
    72     \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    73 \newcommand\settextunderscore[1]{%
    74     \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}}
    7542
    7643% The CFA listings language. Based off of ANCI C and including GCC extensions.
     
    9461\lstset{defaultdialect={[UW]CFA}}
    9562
    96 % Create an internal paragraph indent amount. This is used internally to
    97 % mimic the standard indent even when it has been overriden in the document.
    98 \newlength\cfalab@parindent
    99 \deflength\cfalab@parindent{\parindent}
    100 
    101 % The cfacommon style has many useful defaults for CFA and other types of
    102 % code. Use the listings option "style=cfacommon" to load them.
    103 \lstdefinestyle{cfacommon}{
    104   columns=fullflexible,
    105   basicstyle=\linespread{0.9}\sf,
    106   stringstyle=\tt,
    107   tabsize=5,
    108   % Indent code to paragraph indentation.
    109   xleftmargin=\cfalab@parindent,
    110   % Allow ASCII characters in the range 128-255.
    111   extendedchars=true,
    112   % This allows you to use "math mode" to insert LaTeX into the code.
    113   % Use \( and \) if you need to insert math mode inside that code.
    114   escapechar=\$,
    115   % Disable LaTeX math escape in CFA code $...$
    116   mathescape=false,
    117   keepspaces=true,
    118   % Do not show spaces with cup.
    119   showstringspaces=false,
    120   % Show blank lines at end of code.
    121   showlines=true,
    122   % Spacing above/below code block.
    123   aboveskip=4pt,belowskip=0pt,
    124   numberstyle=\footnotesize\sf,
    125   % Replace/adjust listing characters that look bad in sanserif.
    126   literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
    127     {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
    128     {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    129     {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2
    130     {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
     63% The cfalab style defines some common settings useful in different languages.
     64\lstdefinestyle{cfalab}{%
     65    columns=fullflexible,
     66    basicstyle=\linespread{0.9}\tt,
     67    stringstyle=\tt,
    13168}
    13269
    133 % common.tex Compatablity ===================================================
    134 % Below this line is for compatability with the old common.tex file.
     70% \code*[<escape character>]{<code>}
     71%     Use the listings package to format a snipit of <code>.
     72%     The <escape character> must be a character that does not appear in
     73%     <code> and defaults to a backtick.
     74\newcommand*\codeC[2][\`]{\lstinline[language=C]#1#2#1}
     75\newcommand*\codeCFA[2][\`]{\lstinline[language=CFA]#1#2#1}
    13576
    136 % Backwards compatable way to activate the cfacommon style.
    137 \newcommand{\CFAStyle}{\lstset{style=cfacommon}}
    138 
    139 % A couple of abbreviations are provided. Just ones someone liked.
    140 %
    141 % Abbreviation formatting commands (renew to customize):
    142 \newcommand{\abbrevFont}{\textit}
    143 %
    144 % Abbreviations that, if not followed by a comma or colon, add a comma.
    145 \newrobustcmd*\cfalab@abbrev@comma{%
    146   \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}}
    147 \providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma}
    148 \providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma}
    149 %
    150 % Abbreviations that, if not followed by a period, add a period.
    151 \newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}}
    152 \providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period}
    153 \providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period}
    154 \providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period}
     77% \settextunderscore{(new|old)}
     78%     Redefines the underscore either as a new repersentation or the old one.
     79%     Not that some other packages (ex. hyperref) can override this. Set it
     80%     up after loading them.
     81\let\cfalab@textunderscore@old=\textunderscore
     82\newcommand\cfalab@textunderscore@new{%
     83    \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     84\newcommand\settextunderscore[1]{%
     85    \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}}
    15586
    15687\endinput
  • doc/theses/andrew_beach_MMath/existing.tex

    r3eb55f98 rc993b15  
    1616to be defined~\cite{Moss18}.
    1717\begin{cfa}
    18 char i; int i; double i;
    19 int f(); double f();
    20 void g( int ); void g( double );
     18char i; int i; double i;                        $\C[3.75in]{// variable overload}$
     19int f(); double f();                            $\C{// return overload}$
     20void g( int ); void g( double );        $\C{// parameter overload}\CRT$
    2121\end{cfa}
    2222This feature requires name mangling so the assembly symbols are unique for
     
    2626mangling is:
    2727\begin{cfa}
    28 // name mangling on by default
     28// name mangling
    2929int i; // _X1ii_1
    30 extern "C" {  // disables name mangling
     30@extern "C"@ {  // no name mangling
    3131        int j; // j
    32         extern "Cforall" {  // enables name mangling
     32        @extern "Cforall"@ {  // name mangling
    3333                int k; // _X1ki_1
    3434        }
    35         // revert to no name mangling
    36 }
    37 // revert to name mangling
     35        // no name mangling
     36}
     37// 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,
    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 (@?++@).
     66token with @?@, which indicates the position of the arguments. For example, infixed
     67multiplication is @?*?@ while prefix dereference is @*?@. This syntax make it
     68easy to tell the difference between prefix operations (such as @++?@) and
     69post-fix operations (@?++@).
    7070
    7171The special name for a constructor is @?{}@, which comes from the
    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) { ... }
     72initialization syntax in C. The special name for a destructor is @^{}@, where
     73the @^@ has no special meaning.
     74% I don't like the \^{} symbol but $^\wedge$ isn't better.
     75\begin{cfa}
     76struct T { ... };
     77void ?@{}@(@T &@ this, ...) { ... }  // constructor
     78void ?@^{}@(@T &@ this, ...) { ... } // destructor
    7879{
    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 
    91 % I don't like the \^{} symbol but $^\wedge$ isn't better.
    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) { ... }
    97 {
    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.
     80        T s = @{@ ... @}@;  // same constructor/initialization braces
     81} // destructor call automatically generated
     82\end{cfa}
     83The first parameter is a reference parameter to the type for the
     84constructor/destructor. Destructors may have multiple parameters.  The compiler
     85implicitly matches an overloaded constructor @void ^?{}(T &, ...);@ to an
     86object declaration with associated initialization, and generates a construction
     87call after the object is allocated. When an object goes out of scope, the
     88matching overloaded destructor @void ^?{}(T &);@ is called.  Without explicit
     89definition, \CFA creates a default and copy constructor, destructor and
     90assignment (like \Cpp). It is possible to define constructors/destructors for
     91basic and existing types (unlike \Cpp).
    11092
    11193\section{Polymorphism}
     
    123105works on any type @T@:
    124106\begin{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).
     107@forall( T )@ @T@ identity( @T@ val ) { return val; }
     108int forty_two = identity( 42 ); // T bound to int, forty_two == 42
     109\end{cfa}
    132110
    133111To allow a polymorphic function to be separately compiled, the type @T@ must be
     
    137115types used in a function, \eg:
    138116\begin{cfa}
    139 forall( T | { void do_once(T); })
     117forall( T @| { void do_once(T); }@) // assertion
    140118void do_twice(T value) {
    141119        do_once(value);
    142120        do_once(value);
    143121}
    144 \end{cfa}
     122void do_once(@int@ i) { ... }  // provide assertion
     123@int@ i;
     124do_twice(i); // implicitly pass assertion do_once to do_twice
     125\end{cfa}
     126Any object with a type fulfilling the assertion may be passed as an argument to
     127a @do_twice@ call.
    145128
    146129A polymorphic function can be used in the same way as a normal function.  The
     
    149132all the variables replaced with the concrete types from the arguments) is
    150133defined 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.
    158134
    159135Note, a function named @do_once@ is not required in the scope of @do_twice@ to
     
    162138call.
    163139\begin{cfa}
    164 void do_once(double y) { ... }
     140void do_once(double y) { ... } // global
    165141int quadruple(int x) {
    166         void do_once(int y) { y = y * 2; }
    167         do_twice(x);
     142        void do_once(int y) { y = y * 2; } // local
     143        do_twice(x); // using local "do_once"
    168144        return x;
    169145}
     
    174150function. The matched assertion function is then passed as a function pointer
    175151to @do_twice@ and called within it.
    176 The global definition of @do_once@ is ignored.
    177152
    178153To avoid typing long lists of assertions, constraints can be collect into
     
    186161and the @forall@ list in the previous example is replaced with the trait.
    187162\begin{cfa}
    188 forall(dtype T | done_once(T))
     163forall(dtype T | @done_once(T)@)
    189164\end{cfa}
    190165In general, a trait can contain an arbitrary number of assertions, both
     
    197172declarations instead of parameters, returns, and local variable declarations.
    198173\begin{cfa}
    199 forall(dtype T)
     174forall(dtype @T@)
    200175struct node {
    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.
     176        node(@T@) * next;  // generic linked node
     177        @T@ * data;
     178}
     179node(@int@) inode;
     180\end{cfa}
     181The generic type @node(T)@ is an example of a polymorphic-type usage.  Like \Cpp
     182template usage, a polymorphic-type usage must specify a type parameter.
    208183
    209184There are many other polymorphism features in \CFA but these are the ones used
     
    244219Each coroutine has a @main@ function, which takes a reference to a coroutine
    245220object and returns @void@.
    246 \begin{cfa}
    247 void main(CountUp & this) {
    248     for (unsigned int next = 0 ; true ; ++next) {
    249                 next = up;
    250                 suspend;$\label{suspend}$
     221\begin{cfa}[numbers=left]
     222void 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;
    251228        }
    252229}
     
    277254@mutex@.
    278255\begin{cfa}
    279 void example(MonitorA & mutex argA, MonitorB & mutex argB);
     256void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
    280257\end{cfa}
    281258When the function is called, it implicitly acquires the monitor lock for all of
  • doc/theses/andrew_beach_MMath/features.tex

    r3eb55f98 rc993b15  
    2020\subparagraph{Raise}
    2121The raise is the starting point for exception handling. It marks the beginning
    22 of exception handling by raising an excepion, which passes it to
     22of exception handling by \newterm{raising} an excepion, which passes it to
    2323the EHM.
    2424
     
    101101between different sub-hierarchies.
    102102This design is used in \CFA even though it is not a object-orientated
    103 language; so different tools are used to create the hierarchy.
     103language using different tools to create the hierarchy.
    104104
    105105% Could I cite the rational for the Python IO exception rework?
     
    123123\section{Virtuals}
    124124Virtual types and casts are not part of \CFA's EHM nor are they required for
    125 any EHM.
    126 However the \CFA uses a hierarchy built with the virtual system as the basis
    127 for exceptions and exception matching.
    128 
    129 The virtual system would have ideally been part of \CFA before the work
    130 on exception handling began, but unfortunately it was not.
    131 Because of this only the features and framework needed for the EHM were
    132 designed and implemented. Other features were considered to ensure that
    133 the structure could accomidate other desirable features but they were not
    134 implemented.
    135 The rest of this section will only discuss the finalized portion of the
    136 virtual system.
     125any EHM. But \CFA uses a hierarchial system of exceptions and this feature
     126is leveraged to create that.
     127
     128% Maybe talk about why the virtual system is so minimal.
     129% Created for but not a part of the exception system.
    137130
    138131The virtual system supports multiple ``trees" of types. Each tree is
     
    182175While much of the virtual infrastructure is created, it is currently only used
    183176internally for exception handling. The only user-level feature is the virtual
    184 cast, which is the same as the \Cpp \codeCpp{dynamic_cast}.
     177cast, which is the same as the \Cpp \lstinline[language=C++]|dynamic_cast|.
    185178\label{p:VirtualCast}
    186179\begin{cfa}
     
    204197\begin{cfa}
    205198trait is_exception(exceptT &, virtualT &) {
    206         // Numerous imaginary assertions.
     199        virtualT const & get_exception_vtable(exceptT *);
    207200};
    208201\end{cfa}
    209202The trait is defined over two types, the exception type and the virtual table
    210 type. Each exception type should have but a single virtual table type.
    211 Now there are no actual assertions in this trait because the trait system
    212 actually can't express them (adding such assertions would be part of
    213 completing the virtual system). The imaginary assertions would probably come
    214 from a trait defined by the virtual system, and state that the exception type
    215 is a virtual type, is a decendent of @exception_t@ (the base exception type)
    216 and note its virtual table type.
     203type. This should be one-to-one: each exception type has only one virtual
     204table type and vice versa. The only assertion in the trait is
     205@get_exception_vtable@, which takes a pointer of the exception type and
     206returns a reference to the virtual table type instance.
     207
     208% TODO: This section, and all references to get_exception_vtable, are
     209% out-of-data. Perhaps wait until the update is finished before rewriting it.
     210The function @get_exception_vtable@ is actually a constant function.
     211Regardless of the value passed in (including the null pointer) it should
     212return a reference to the virtual table instance for that type.
     213The reason it is a function instead of a constant is that it make type
     214annotations easier to write as you can use the exception type instead of the
     215virtual table type; which usually has a mangled name.
     216% Also \CFA's trait system handles functions better than constants and doing
     217% it this way reduce the amount of boiler plate we need.
    217218
    218219% I did have a note about how it is the programmer's responsibility to make
     
    234235Both traits ensure a pair of types are an exception type and its virtual table
    235236and defines one of the two default handlers. The default handlers are used
    236 as fallbacks and are discussed in detail in \vref{s:ExceptionHandling}.
     237as fallbacks and are discussed in detail in \VRef{s:ExceptionHandling}.
    237238
    238239However, all three of these traits can be tricky to use directly.
     
    350351for particular exception type.
    351352The global default termination handler performs a cancellation
    352 (see \vref{s:Cancellation}) on the current stack with the copied exception.
     353\see{\VRef{s:Cancellation}} on the current stack with the copied exception.
    353354
    354355\subsection{Resumption}
     
    425426
    426427\subsubsection{Resumption Marking}
    427 \label{s:ResumptionMarking}
    428428A key difference between resumption and termination is that resumption does
    429429not unwind the stack. A side effect that is that when a handler is matched
     
    472472The symmetry between resumption termination is why this pattern was picked.
    473473Other patterns, such as marking just the handlers that caught, also work but
    474 lack the symmetry means there are more rules to remember.
     474lack the symmetry means there are less rules to remember.
    475475
    476476\section{Conditional Catch}
     
    557557\end{cfa}
    558558If there are further handlers after this handler only the first version will
    559 check them. If multiple handlers on a single try block that could handle the
    560 same exception the translations get more complex but they are equivilantly
     559check them. If multiple handlers on a single try block could handle the same
     560exception the translations get more complex but they are equivilantly
    561561powerful.
    562562
     
    633633and the current stack is
    634634unwound. After that it depends one which stack is being cancelled.
    635 
    636 \paragraph{Main Stack}
     635\begin{description}
     636\item[Main Stack:]
    637637The main stack is the one used by the program main at the start of execution,
    638638and is the only stack in a sequential program.
     
    645645to, so it would have be explicitly managed.
    646646
    647 \paragraph{Thread Stack}
     647\item[Thread Stack:]
    648648A thread stack is created for a \CFA @thread@ object or object that satisfies
    649649the @is_thread@ trait.
     
    671671Also you can always add an explicit join if that is the desired behaviour.
    672672
    673 \paragraph{Coroutine Stack}
     673\item[Coroutine Stack:]
    674674A coroutine stack is created for a @coroutine@ object or object that
    675675satisfies the @is_coroutine@ trait.
     
    685685(in terms of coroutine state) called resume on this coroutine, so the message
    686686is passed to the latter.
     687\end{description}
  • doc/theses/andrew_beach_MMath/future.tex

    r3eb55f98 rc993b15  
    110110\section{Zero-Cost Try}
    111111\CFA does not have zero-cost try-statements because the compiler generates C
    112 code rather than assembler code (see \vpageref{p:zero-cost}). When the compiler
     112code rather than assembler code \see{\VPageref{p:zero-cost}}. When the compiler
    113113does create its own assembly (or LLVM byte-code), then zero-cost try-statements
    114114are possible. The downside of zero-cost try-statements is the LSDA complexity,
  • doc/theses/andrew_beach_MMath/implement.tex

    r3eb55f98 rc993b15  
    99% Virtual table rules. Virtual tables, the pointer to them and the cast.
    1010While the \CFA virtual system currently has only one public feature, virtual
    11 cast (see the virtual cast feature \vpageref{p:VirtualCast}),
    12 substantial structure is required to support it,
    13 and provide features for exception handling and the standard library.
     11cast \see{\VPageref{p:VirtualCast}}, substantial structure is required to
     12support it, and provide features for exception handling and the standard
     13library.
    1414
    1515\subsection{Virtual Type}
     
    215215\subsection{libunwind Usage}
    216216Libunwind, accessed through @unwind.h@ on most platforms, is a C library that
    217 provides \Cpp-style stack-unwinding. Its operation is divided into two phases:
     217provides \CC-style stack-unwinding. Its operation is divided into two phases:
    218218search and cleanup. The dynamic target search -- phase 1 -- is used to scan the
    219219stack and decide where unwinding should stop (but no unwinding occurs). The
     
    291291@_UA_FORCE_UNWIND@ specifies a forced unwind call. Forced unwind only performs
    292292the cleanup phase and uses a different means to decide when to stop
    293 (see \vref{s:ForcedUnwind}).
     293\see{\VRef{s:ForcedUnwind}}.
    294294\end{enumerate}
    295295
     
    400400
    401401Termination exceptions use libunwind heavily because it matches the intended
    402 use from \Cpp exceptions closely. The main complication for \CFA is that the
     402use from \CC exceptions closely. The main complication for \CFA is that the
    403403compiler generates C code, making it very difficult to generate the assembly to
    404404form the LSDA for try blocks or destructors.
     
    509509
    510510% Recursive Resumption Stuff:
    511 Search skipping (see \vpageref{s:ResumptionMarking}), which ignores parts of
    512 the stack
     511Search skipping \see{\VPageref{p:searchskip}}, which ignores parts of the stack
    513512already examined, is accomplished by updating the front of the list as the
    514513search continues. Before the handler at a node is called the head of the list
     
    555554Cancellation also uses libunwind to do its stack traversal and unwinding,
    556555however it uses a different primary function @_Unwind_ForcedUnwind@. Details
    557 of its interface can be found in the \vref{s:ForcedUnwind}.
     556of its interface can be found in the \VRef{s:ForcedUnwind}.
    558557
    559558The first step of cancellation is to find the cancelled stack and its type:
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    r3eb55f98 rc993b15  
    6666% Tip: Photographs should be cropped and compressed so as not to be too large.
    6767
     68% To create a PDF output that is optimized for double-sided printing:
     69% 1) comment-out the \documentclass statement in the preamble below, and
     70%    un-comment the second \documentclass line.
     71% 2) change the value assigned below to the boolean variable "PrintVersion"
     72%    from "false" to "true".
     73
    6874% ======================================================================
    6975%   D O C U M E N T   P R E A M B L E
     
    8187}
    8288
    83 % Does nothing, ignores \href tags (redefined by hyperref package).
    84 \newcommand{\href}[1]{#1}
     89% Some LaTeX commands I define for my own nomenclature.
     90% If you have to, it's easier to make changes to nomenclature once here than
     91% in a million places throughout your thesis!
     92\newcommand{\package}[1]{\textbf{#1}} % package names in bold text
     93\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
     94\newcommand{\href}[1]{#1} % does nothing, but defines the command so the
     95% print-optimized version will ignore \href tags (redefined by hyperref pkg).
     96% Anything defined here may be redefined by packages added below...
    8597
    8698% For a nomenclature (optional; available from ctan.org)
     
    95107% Adds todos (Must be included after comment.)
    96108\usepackage{todonotes}
    97 % cfa macros used in the document
    98 \usepackage{cfalab}
    99109
    100110% Hyperlinks make it very easy to navigate an electronic document.
     
    198208\makeglossaries
    199209
    200 % listings package configuation:
    201 \lstMakeShortInline@
    202 \lstset{language=CFA,style=cfacommon,basicstyle=\linespread{0.9}\tt}
    203 \lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
     210% cfa macros used in the document
     211%\usepackage{cfalab}
     212% I'm going to bring back eventually.
     213\makeatletter
     214% Combines all \CC* commands:
     215\newrobustcmd*\Cpp[1][\xspace]{\cfalab@Cpp#1}
     216\newcommand\cfalab@Cpp{C\kern-.1em\hbox{+\kern-.25em+}}
     217% Optional arguments do not work with pdf string. (Some fix-up required.)
     218\pdfstringdefDisableCommands{\def\Cpp{C++}}
     219
     220% Wrappers for inline code snippits.
     221\newrobustcmd*\codeCFA[1]{\lstinline[language=CFA]{#1}}
     222\newrobustcmd*\codeC[1]{\lstinline[language=C]{#1}}
     223\newrobustcmd*\codeCpp[1]{\lstinline[language=C++]{#1}}
     224\newrobustcmd*\codePy[1]{\lstinline[language=Python]{#1}}
     225
     226% Colour text, formatted in LaTeX style instead of TeX style.
     227\newcommand*\colour[2]{{\color{#1}#2}}
     228\makeatother
     229
     230\input{common}
     231% CFA code-style for all languages
     232\CFAStyle
     233% CFA default lnaguage
     234\lstset{language=CFA,basicstyle=\linespread{0.9}\tt}
    204235% Annotations from Peter:
    205236\newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
  • doc/user/user.tex

    r3eb55f98 rc993b15  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Apr 28 21:48:59 2021
    14 %% Update Count     : 5051
     13%% Last Modified On : Sun Apr 25 19:03:03 2021
     14%% Update Count     : 4951
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    33123312
    33133313\section{Tuples}
    3314 \label{tuples}
    33153314
    33163315In C and \CFA, lists of elements appear in several contexts, such as the parameter list for a routine call.
     
    34213420
    34223421\subsection{Tuple Coercions}
    3423 \label{tuple coercions}\label{coercions!tuple}
    34243422
    34253423There are four coercions that can be performed on tuples and tuple variables: closing, opening, flattening and structuring.
     
    34663464
    34673465\subsection{Mass Assignment}
    3468 \label{mass assignment}\label{assignment!mass}
    34693466
    34703467\CFA permits assignment to several variables at once using mass assignment~\cite{CLU}.
     
    35073504
    35083505\subsection{Multiple Assignment}
    3509 \label{multiple assignment}\label{assignment!multiple}
    35103506
    35113507\CFA also supports the assignment of several values at once, known as multiple assignment~\cite{CLU,Galletly96}.
     
    35493545
    35503546\subsection{Cascade Assignment}
    3551 \index{cascade assignment}\index{assignment!cascade}
    35523547
    35533548As in C, \CFA mass and multiple assignments can be cascaded, producing cascade assignment.
     
    35693564\section{Stream I/O Library}
    35703565\label{s:StreamIOLibrary}
    3571 \index{input}\index{output}
    3572 \index{stream library}\index{library!stream}
     3566\index{input/output stream library}
     3567\index{stream library}
    35733568
    35743569The goal of \CFA stream input/output (I/O) is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
    35753570Stream I/O can be implicitly or explicitly formatted.
    3576 Implicit formatting means \CFA selects the output or input format for values that matches the variable's type.
     3571Implicit formatting means \CFA selects the output or input format for values that match with the type of a variable.
    35773572Explicit formatting means additional information is specified to augment how an output or input of value is interpreted.
    3578 \CFA formatting incorporates ideas from C ©printf©, \CC ©stream© manipulators, and Python implicit spacing and newline.
     3573\CFA formatting is a cross between C ©printf© and \CC ©cout© manipulators, and Python implicit spacing and newline.
    35793574Specifically:
    35803575\begin{itemize}
     
    35893584Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
    35903585Without this programming style, errors occur when moving prints, as manipulator effects incorrectly flow into the new location.
    3591 Furthermore, to guarantee no side-effects, manipulator values must be saved and restored across function calls.
    3592 \item
    3593 \CFA has more sophisticated implicit value spacing than Python, plus implicit newline at the end of a print.
     3586(To guarantee no side-effects, manipulator values must be saved and restored across function calls.)
     3587\item
     3588\CFA has more sophisticated implicit spacing between values than Python, plus implicit newline at the end of a print.
    35943589\end{itemize}
    3595 
    3596 The standard polymorphic I/Os stream are ©stdin©/©sin© (input), ©stdout©/©sout© and ©stderr©/©serr© (output) (like C++ ©cin©/©cout©/©cerr©).
    3597 Polymorphic streams ©exit© and ©abort© provide implicit program termination without and with generating a stack trace and core file.
    3598 Stream ©exit© implicitly returns ©EXIT_FAILURE© to the shell.
    3599 \begin{cfa}
    3600 ®exit®   | "x (" | x | ") negative value."; // terminate and return EXIT_FAILURE to shell
    3601 ®abort® | "x (" | x | ") negative value."; // terminate and generate stack trace and core file
    3602 \end{cfa}
    3603 Note, \CFA stream variables ©stdin©, ©stdout©, ©stderr©, ©exit©, and ©abort© overload C variables ©stdin©, ©stdout©, ©stderr©, and functions ©exit© and ©abort©, respectively.
    36043590The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
    3605 
    3606 
    3607 \subsection{Basic I/O}
    36083591
    36093592For implicit formatted output, the common case is printing a series of variables separated by whitespace.
     
    36183601\begin{cfa}
    36193602
    3620 cout  <<  x  ®<< " "®  <<  y  ®<< " "®  <<  z << endl;
     3603cout << x ®<< " "® << y ®<< " "® << z << endl;
    36213604\end{cfa}
    36223605&
     
    36703653\end{tabular}
    36713654\end{cquote}
    3672 Input and output use a uniform operator, ©|©, rather than \CC's ©>>© and ©<<© input/output operators.
     3655Input and output use a uniform operator, ©|©, rather than separate operators, as in ©>>© and ©<<© for \CC.
    36733656There is a weak similarity between the \CFA logical-or operator and the \Index{Shell pipe-operator} for moving data, where data flows in the correct direction for input but the opposite direction for output.
    36743657
     
    37153698\end{cquote}
    37163699
    3717 \VRef[Figure]{f:CFACommand-LineProcessing} shows idiomatic \CFA command-line processing and copying an input file to an output file.
    3718 Note, a stream variable may be copied because it is a reference to an underlying stream data-structures.
    3719 All I/O errors are handles as exceptions, but end-of-file is not an exception as C programmers are use to explicitly checking for it.
    3720 
    3721 \begin{figure}
    3722 \begin{cfa}
    3723 #include ®<fstream.hfa>®
    3724 
    3725 int main( int argc, char * argv[] ) {
    3726         ®ifstream® in  = stdin;                                 $\C{// copy default files}$
    3727         ®ofstream® out = stdout;
    3728 
    3729         try {
    3730                 choose ( argc ) {
    3731                   case 2, 3:
    3732                         ®open®( in, argv[1] );                  $\C{// open input file first as output creates file}$
    3733                         if ( argc == 3 ) ®open®( out, argv[2] ); $\C{// do not create output unless input opens}$
    3734                   case 1: ;                                                     $\C{// use default files}$
    3735                   default:
    3736                         ®exit® | "Usage" | argv[0] | "[ input-file (default stdin) "
    3737                                    "[ output-file (default stdout) ] ]";
    3738                 } // choose
    3739         } catch( ®Open_Failure® * ex; ex->istream == &in ) {
    3740                 ®exit® | "Unable to open input file" | argv[1];
    3741         } catch( ®Open_Failure® * ex; ex->ostream == &out ) {
    3742                 ®close®( in );                                          $\C{// optional}$
    3743                 ®exit® | "Unable to open output file" | argv[2];
    3744         } // try
    3745 
    3746         out | nlOff;                                                    $\C{// turn off auto newline}$
    3747         in | nlOn;                                                              $\C{// turn on reading newline}$
    3748         char ch;
    3749         for () {                                                                $\C{// read/write characters}$
    3750                 in | ch;
    3751           if ( eof( in ) ) break;                               $\C{// eof ?}$
    3752                 out | ch;
    3753         } // for
    3754 } // main
    3755 \end{cfa}
    3756 \caption{\CFA Command-Line Processing}
    3757 \label{f:CFACommand-LineProcessing}
    3758 \end{figure}
    3759 
    3760 \VRef[Figure]{f:StreamFunctions} shows the stream operations.
    3761 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    3762 \item
    3763 \Indexc{fail} tests the stream error-indicator, returning nonzero if it is set.
    3764 \item
    3765 \Indexc{clear} resets the stream error-indicator.
    3766 \item
    3767 \Indexc{flush} (©ofstream© only) causes any unwritten data for a stream to be written to the file.
    3768 \item
    3769 \Indexc{eof} (©ifstream© only) tests the end-of-file indicator for the stream pointed to by stream.
    3770 Returns true if the end-of-file indicator is set, otherwise false.
    3771 \item
    3772 \Indexc{open} binds the file with ©name© to a stream accessed with ©mode© (see ©fopen©).
    3773 \item
    3774 \Indexc{close} flushes the stream and closes the file.
    3775 \item
    3776 \Indexc{write} (©ofstream© only) write ©size© bytes to the stream.
    3777 The bytes are written lazily to file when internal buffers fill.
    3778 Eager buffer writes are done with ©flush©
    3779 \item
    3780 \Indexc{read} (©ifstream© only) read ©size© bytes to the stream.
    3781 \item
    3782 \Indexc{ungetc} (©ifstream© only) pushes the character back to the input stream.
    3783 Pushed-back characters returned by subsequent reads in the reverse order of pushing.
    3784 \end{itemize}
    3785 The constructor functions:
    3786 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    3787 \item
    3788 create an unbound stream, which is subsequently bound to a file with ©open©.
    3789 \item
    3790 create a bound stream to the associated file with given ©mode©.
    3791 \end{itemize}
    3792 The destructor closes the stream.
    3793 
    3794 \begin{figure}
    3795 \begin{cfa}
    3796 // *********************************** ofstream ***********************************
    3797 
    3798 bool fail( ofstream & );$\indexc{fail}\index{ofstream@©ofstream©!©fail©}$
    3799 void clear( ofstream & );$\indexc{clear}\index{ofstream@©ofstream©!©clear©}$
    3800 int flush( ofstream & );$\indexc{flush}\index{ofstream@©ofstream©!©flush©}$
    3801 void open( ofstream &, const char name[], const char mode[] = "w" );$\indexc{open}\index{ofstream@©ofstream©!©open©}$
    3802 void close( ofstream & );$\indexc{close}\index{ofstream@©ofstream©!©close©}$
    3803 ofstream & write( ofstream &, const char data[], size_t size );$\indexc{write}\index{ofstream@©ofstream©!©write©}$
    3804 
    3805 void ?{}( ofstream & );$\index{ofstream@©ofstream©!©?{}©}$
    3806 void ?{}( ofstream &, const char name[], const char mode[] = "w" );
    3807 void ^?{}( ofstream & );$\index{ofstream@©ofstream©!©^?{}©}$
    3808 
    3809 // *********************************** ifstream ***********************************
    3810 
    3811 bool fail( ifstream & is );$\indexc{fail}\index{ifstream@©ifstream©!©fail©}$
    3812 void clear( ifstream & );$\indexc{clear}\index{ifstream@©ifstream©!©clear©}$
    3813 bool eof( ifstream & is );$\indexc{eof}\index{ifstream@©ifstream©!©eof©}$
    3814 void open( ifstream & is, const char name[], const char mode[] = "r" );$\indexc{open}\index{ifstream@©ifstream©!©open©}$
    3815 void close( ifstream & is );$\indexc{close}\index{ifstream@©ifstream©!©close©}$
    3816 ifstream & read( ifstream & is, char data[], size_t size );$\indexc{read}\index{ifstream@©ifstream©!©read©}$
    3817 ifstream & ungetc( ifstream & is, char c );$\indexc{unget}\index{ifstream@©ifstream©!©unget©}$
    3818 
    3819 void ?{}( ifstream & is );$\index{ifstream@©ifstream©!©?{}©}$
    3820 void ?{}( ifstream & is, const char name[], const char mode[] = "r" );
    3821 void ^?{}( ifstream & is );$\index{ifstream@©ifstream©!©^?{}©}$
    3822 \end{cfa}
    3823 \caption{Stream Functions}
    3824 \label{f:StreamFunctions}
    3825 \end{figure}
    38263700
    38273701
     
    41564030sout | wd( 4, "ab" ) | wd( 3, "ab" ) | wd( 2, "ab" );
    41574031\end{cfa}
    4158 \begin{cfa}[showspaces=true,aboveskip=0pt]
     4032\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    41594033®  ®34 ® ®34 34
    41604034®  ®4.000000 ® ®4.000000 4.000000
     
    45044378\end{cfa}
    45054379
    4506 
    4507 \section{String Stream}
    4508 
    4509 All the stream formatting capabilities are available to format text to/from a C string rather than to a stream file.
    4510 \VRef[Figure]{f:StringStreamProcessing} shows writing (output) and reading (input) from a C string.
    4511 \begin{figure}
    4512 \begin{cfa}
    4513 #include <fstream.hfa>
    4514 #include <strstream.hfa>
    4515 
    4516 int main() {
    4517         enum { size = 256 };
    4518         char buf[size]; $\C{// output buffer}$
    4519         ®ostrstream osstr = { buf, size };® $\C{// bind output buffer/size}$
    4520         int i = 3, j = 5, k = 7;
    4521         double x = 12345678.9, y = 98765.4321e-11;
    4522 
    4523         osstr | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y)); $\C{// same lines of output}$
    4524         write( osstr );
    4525         printf( "%s", buf );
    4526         sout | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y));
    4527 
    4528         char buf2[] = "12 14 15 3.5 7e4"; $\C{// input buffer}$
    4529         ®istrstream isstr = { buf2 };®
    4530         isstr | i | j | k | x | y;
    4531         sout | i | j | k | x | y;
    4532 }
    4533 \end{cfa}
    4534 \caption{String Stream Processing}
    4535 \label{f:StringStreamProcessing}
    4536 \end{figure}
    4537 
    4538 \VRef[Figure]{f:StringStreamFunctions} shows the string stream operations.
    4539 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    4540 \item
    4541 \Indexc{write} (©ostrstream© only) writes all the buffered characters to the specified stream (©stdout© default).
    4542 \end{itemize}
    4543 The constructor functions:
    4544 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    4545 \item
    4546 create a bound stream to a write buffer (©ostrstream©) of ©size© or a read buffer (©istrstream©) containing a C string terminated with ©'\0'©.
    4547 \end{itemize}
    4548 
    4549 \begin{figure}
    4550 \begin{cfa}
    4551 // *********************************** ostrstream ***********************************
    4552 
    4553 ostrstream & write( ostrstream & os, FILE * stream = stdout );
    4554 
    4555 void ?{}( ostrstream &, char buf[], size_t size );
    4556 
    4557 // *********************************** istrstream ***********************************
    4558 
    4559 void ?{}( istrstream & is, char buf[] );
    4560 \end{cfa}
    4561 \caption{String Stream Functions}
    4562 \label{f:StringStreamFunctions}
    4563 \end{figure}
     4380\Textbf{WARNING:} ©printf©\index{printf@©printf©}, ©scanf©\index{scanf@©scanf©} and their derivatives are unsafe when used with user-level threading, as in \CFA.
     4381These stream routines use kernel-thread locking (©futex©\index{futex@©futex©}), which block kernel threads, to prevent interleaving of I/O.
     4382However, the following simple example illustrates how a deadlock can occur (other complex scenarios are possible).
     4383Assume a single kernel thread and two user-level threads calling ©printf©.
     4384One user-level thread acquires the I/O lock and is time-sliced while performing ©printf©.
     4385The other user-level thread then starts execution, calls ©printf©, and blocks the only kernel thread because it cannot acquire the I/O lock.
     4386It does not help if the kernel lock is multiple acquisition, \ie, the lock owner can acquire it multiple times, because it then results in two user threads in the ©printf© critical section, corrupting the stream.
    45644387
    45654388
     
    82888111\begin{cquote}
    82898112\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    8290 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c@{}}{\textbf{C}}   \\
     8113\multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}@{}}   \\
    82918114\hline
    82928115\begin{cfa}
    8293 #include <gmp.hfa>$\indexc{gmp}$
     8116#include <gmp>$\indexc{gmp}$
    82948117int main( void ) {
    82958118        sout | "Factorial Numbers";
  • libcfa/src/fstream.cfa

    r3eb55f98 rc993b15  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 28 20:37:53 2021
    13 // Update Count     : 445
     12// Last Modified On : Tue Apr 27 22:08:57 2021
     13// Update Count     : 442
    1414//
    1515
     
    114114} // fail
    115115
    116 void clear( ofstream & os ) {
    117         clearerr( (FILE *)(os.file$) );
    118 } // clear
    119 
    120116int flush( ofstream & os ) {
    121117        return fflush( (FILE *)(os.file$) );
     
    211207} // nl
    212208
    213 
    214209// *********************************** ifstream ***********************************
    215210
     
    245240} // fail
    246241
    247 void clear( ifstream & is ) {
    248         clearerr( (FILE *)(is.file$) );
    249 } // clear
    250 
    251242void ends( ifstream & is ) {
    252243        if ( is.acquired$ ) { is.acquired$ = false; release( is ); }
    253244} // ends
    254245
    255 bool eof( ifstream & is ) {
     246int eof( ifstream & is ) {
    256247        return feof( (FILE *)(is.file$) );
    257248} // eof
     
    282273} // close
    283274
    284 ifstream & read( ifstream & is, char data[], size_t size ) {
     275ifstream & read( ifstream & is, char * data, size_t size ) {
    285276        if ( fail( is ) ) {
    286277                abort | IO_MSG "attempt read I/O on failed stream";
  • libcfa/src/fstream.hfa

    r3eb55f98 rc993b15  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 28 20:37:57 2021
    13 // Update Count     : 230
     12// Last Modified On : Tue Apr 27 22:00:30 2021
     13// Update Count     : 226
    1414//
    1515
     
    7070
    7171bool fail( ofstream & );
    72 void clear( ofstream & );
    7372int flush( ofstream & );
    7473void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
     
    120119
    121120bool fail( ifstream & is );
    122 void clear( ifstream & );
    123 bool eof( ifstream & is );
     121int eof( ifstream & is );
    124122void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
    125123void open( ifstream & is, const char name[] );
    126124void close( ifstream & is );
    127 ifstream & read( ifstream & is, char data[], size_t size );
     125ifstream & read( ifstream & is, char * data, size_t size );
    128126ifstream & ungetc( ifstream & is, char c );
    129127
  • libcfa/src/iostream.hfa

    r3eb55f98 rc993b15  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 28 20:37:56 2021
    13 // Update Count     : 401
     12// Last Modified On : Tue Apr 27 17:59:21 2021
     13// Update Count     : 398
    1414//
    1515
     
    5252       
    5353trait ostream( ostype & | basic_ostream( ostype ) ) {
     54        int flush( ostype & );
    5455        bool fail( ostype & );                                                          // operation failed?
    55         void clear( ostype & );
    56         int flush( ostype & );
    5756        void open( ostype &, const char name[], const char mode[] );
    5857        void close( ostype & );
     
    303302        int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    304303        istype & ungetc( istype &, char );
    305         bool eof( istype & );
     304        int eof( istype & );
    306305}; // basic_istream
    307306
    308307trait istream( istype & | basic_istream( istype ) ) {
    309308        bool fail( istype & );
    310         void clear( istype & );
    311309        void open( istype & is, const char name[] );
    312310        void close( istype & is );
    313         istype & read( istype &, char [], size_t );
     311        istype & read( istype &, char *, size_t );
    314312        void acquire( istype & );                                                       // concurrent access
    315313}; // istream
  • tests/strstream.cfa

    r3eb55f98 rc993b15  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo
    3 //
    4 // strstream.cfa --
    5 //
    6 // Author           : Peter A. Buhr
    7 // Created On       : Wed Apr 28 21:47:35 2021
    8 // Last Modified By : Peter A. Buhr
    9 // Last Modified On : Wed Apr 28 21:50:02 2021
    10 // Update Count     : 3
    11 //
    12 
    131#include <fstream.hfa>
    142#include <strstream.hfa>
    153
    164int main() {
    17         enum { size = 256 };
    18         char buf[size];                                                                         // output buffer
    19         ostrstream osstr = { buf, size };                                       // bind output buffer/size
    20         int i = 3, j = 5, k = 7;
    21         double x = 12345678.9, y = 98765.4321e-11;
     5    enum { size = 256 };
     6    char buf[size];
     7    ostrstream osstr = { buf, size };
     8    int i = 3, j = 5, k = 7;
     9    double x = 12345678.9, y = 98765.4321e-11;
    2210
    23         osstr | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y)); // same lines of output
    24         write( osstr );
    25         printf( "%s", buf );
    26         sout | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y));
     11    osstr | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y));
     12    write( osstr );
     13    printf( "%s", buf );
     14    sout | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y));
    2715
    28         // char buf2[] = "12 14 15 3.5 7e4";                                    // input buffer
    29         // istrstream isstr = { buf2 };
    30         // isstr | i | j | k | x | y;
    31         // sout | i | j | k | x | y;
     16    // char buf2[] = "12 14 15 3.5 7e4";
     17    // istrstream isstr = { buf2 };
     18    // isstr | i | j | k | x | y;
     19    // sout | i | j | k | x | y;
    3220}
    33 
    34 // Local Variables: //
    35 // tab-width: 4 //
    36 // compile-command: "cfa strstream.cfa" //
    37 // End: //
Note: See TracChangeset for help on using the changeset viewer.