Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/uC++toCFA/uC++toCFA.tex

    rd96f7c4 re255902b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jan 17 07:39:09 2025
    14 %% Update Count     : 6284
     13%% Last Modified On : Fri Nov 15 09:55:34 2024
     14%% Update Count     : 6249
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    197197
    198198
     199\section{Stream I/O}
     200
     201\CFA output streams automatically separate values and insert a newline at the end of the print.
     202\begin{cquote}
     203\begin{tabular}{@{}l|l@{}}
     204\begin{uC++}
     205#include <@iostream@>
     206using namespace std;
     207int i;   double d;   char c;
     208cin >> i >> d >> c;
     209cout << i << ' ' << d << ' ' << c | endl;
     210\end{uC++}
     211&
     212\begin{cfa}
     213#include <@fstream.hfa@>
     214
     215int i;   double d;   char c;
     216sin | i | d | c;
     217sout | i | d | c
     218\end{cfa}
     219\end{tabular}
     220\end{cquote}
     221
     222
    199223\section{Looping}
    200224
     
    216240for ( i; 0 @-@~ 10 ) { ... }
    217241\end{cfa}
    218 \end{tabular}
    219 \end{cquote}
    220 
    221 \begin{cquote}
    222 \begin{tabular}{@{}l|l@{}}
     242\\
     243\hline
    223244\begin{uC++}
    224245int i = 0
     
    232253@else@ { ... } // i == 10
    233254\end{cfa}
    234 \end{tabular}
    235 \end{cquote}
    236 
    237 \begin{cquote}
    238 \begin{tabular}{@{}l|l@{}}
     255\\
     256\hline
    239257\begin{uC++}
    240258@L1:@ for ( ;; ) {
     
    253271        }
    254272}
    255 \end{cfa}
    256 \end{tabular}
    257 \end{cquote}
    258 
    259 
    260 \section{Stream I/O}
    261 
    262 \CFA output streams automatically separate values and insert a newline at the end of the print.
    263 \begin{cquote}
    264 \begin{tabular}{@{}l|l@{}}
    265 \begin{uC++}
    266 #include <@iostream@>
    267 using namespace std;
    268 int i;   double d;   char c;
    269 cin >> i >> d >> c;
    270 cout << i << ' ' << d << ' ' << c << endl;
    271 \end{uC++}
    272 &
    273 \begin{cfa}
    274 #include <@fstream.hfa@>
    275 
    276 int i;   double d;   char c;
    277 sin | i | d | c;
    278 sout | i | d | c
    279 \end{cfa}
    280 \end{tabular}
    281 \end{cquote}
    282 To disable/enable automatic newline at the end of printing, use @nlOff@/@nlOn@ and @nl@.
    283 \begin{cquote}
    284 \begin{tabular}{@{}l|l@{}}
    285 \begin{uC++}
    286 
    287 for ( int i = 0; i < 5; i += 1 ) cout << i << ' ';
    288 cout << @endl@;
    289 
    290 0 1 2 3 4
    291 \end{uC++}
    292 &
    293 \begin{cfa}
    294 sout | @nlOff@; // disable auto nl
    295 for ( i; 5 ) sout | i;
    296 sout | @nl@;
    297 sout | @nlOn@;  // reenable auto nl
    298 0 1 2 3 4
    299 \end{cfa}
    300 \end{tabular}
    301 \end{cquote}
    302 Floating-point numbers without a fraction print with a decimal point, which can be disabled with @nodp@.
    303 \begin{cquote}
    304 \begin{tabular}{@{}l|l@{}}
    305 \begin{uC++}
    306 cout << 3.0 << ' ' << showpoint << setprecision(0) << 3.0 << endl;
    307 3 3.
    308 \end{uC++}
    309 &
    310 \begin{cfa}
    311 sout | @nodp( 3.0 )@ | 3.0;
    312 3 3.
    313273\end{cfa}
    314274\end{tabular}
     
    331291        if ( ... ) @_Throw@ E( /* initialization */ );
    332292                ...
    333 } @_CatchResume@( E & /* reference */ ) { ... }
    334   catch( E & ) { ... }
    335   catch( ... /* catch any */ ) { ... }
    336   _Finally { ... }
     293} @_CatchResume@( E & ) { ... // reference
     294} catch( E & ) { ...
     295} catch( ... ) { ... // catch any
     296} _Finally { ...
     297}
    337298\end{uC++}
    338299&
     
    347308        if ( ... ) @throw@ @ExceptionInst@( E, /* intialization */ );
    348309        ...
    349 } @catchResume@( E @*@ /* pointer */ ) { ... }
    350   catch( E * ) { ... }
    351   catch( exception_t @*@ /* catch any */ ) { ... }
    352   finally { ... }
     310} @catchResume@( E * ) { ... // pointer
     311} catch( E * ) { ...
     312} catch( exception_t * ) { ... // catch any
     313} finally { ...
     314}
    353315\end{cfa}
    354316\end{tabular}
     
    368330                        ... suspend(); ...
    369331                }
    370         } @_CatchResume@( E & /* reference */ ) { ... }
    371           catch( E & ) { ... }
     332        } @_CatchResume@( E & ) { // reference
     333                ...
     334        } catch( E & ) {
     335                ...
     336        }
    372337}
    373338\end{uC++}
     
    381346                ... suspendPoll ...
    382347                disable_ehm();
    383         } @catchResume@( E * ) { ... }
    384           catch( E & ) { ... }
     348        } @catchResume@( E * ) { // pointer
     349                ...
     350        } catch( E & ) {
     351                ...
     352        }
    385353}
    386354\end{cfa}
     
    588556
    589557
     558\section{Thread}
     559
     560\begin{cquote}
     561\begin{tabular}{@{}l|ll@{}}
     562\begin{uC++}
     563
     564@_Task@ T {
     565        // private task fields
     566        void main() {
     567                ... @_Resume E( ... ) _At partner@;
     568                ... @uThisTask();@ ...
     569        }
     570  public:
     571};
     572\end{uC++}
     573&
     574\begin{cfa}
     575#include <$thread$.hfa>
     576@thread@ T {
     577        // private task fields
     578
     579};
     580void main( @T & t@ ) {
     581        ... @resumeAt( partner, ExceptionInst( E, ... )@ );
     582        ... @active_thread();@ ...
     583}
     584\end{cfa}
     585\\
     586\multicolumn{2}{@{}l@{}}{\lstinline{T t; // start thread in main routine}}
     587\end{tabular}
     588\end{cquote}
     589
     590
    590591\section{\lstinline{COBEGIN}/\lstinline{COFOR}}
    591592
     
    601602                BEGIN osacquire( cout ) << "C" << endl; END
    602603                BEGIN osacquire( cout ) << "D" << endl; END
     604                BEGIN osacquire( cout ) << "E" << endl; END
    603605        @COEND@
    604606        @COFOR@( i, 1, 10,
     
    617619                corun { mutex( sout ) sout | "C"; }
    618620                corun { mutex( sout ) sout | "D"; }
     621                corun { mutex( sout ) sout | "E"; }
    619622        }
    620623        @cofor@( i; 10 ) {
     
    700703}
    701704\end{cfa}
    702 \end{tabular}
    703 \end{cquote}
    704 
    705 
    706 \section{Thread}
    707 
    708 \begin{cquote}
    709 \begin{tabular}{@{}l|ll@{}}
    710 \begin{uC++}
    711 
    712 @_Task@ T {
    713         // private task fields
    714         void main() {
    715                 ... @_Resume E( ... ) _At partner@;
    716                 ... @uThisTask();@ ...
    717         }
    718   public:
    719 };
    720 \end{uC++}
    721 &
    722 \begin{cfa}
    723 #include <$thread$.hfa>
    724 @thread@ T {
    725         // private task fields
    726 
    727 };
    728 void main( @T & t@ ) {
    729         ... @resumeAt( partner, ExceptionInst( E, ... )@ );
    730         ... @active_thread();@ ...
    731 }
    732 \end{cfa}
    733 \\
    734 \multicolumn{2}{@{}l@{}}{\lstinline{T t; // start thread in main routine}}
    735705\end{tabular}
    736706\end{cquote}
Note: See TracChangeset for help on using the changeset viewer.