Changeset 04375cf for doc


Ignore:
Timestamp:
Sep 10, 2025, 10:32:19 PM (2 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
a307552
Parents:
421b242
Message:

major updates to the uC++toCFA cheat sheet

File:
1 edited

Legend:

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

    r421b242 r04375cf  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Aug 28 13:41:34 2025
    14 %% Update Count     : 6493
     13%% Last Modified On : Mon Sep  8 18:10:30 2025
     14%% Update Count     : 6534
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    138138\section{Introduction}
    139139
    140 \CFA is NOT an object-oriented programming-language.
    141 \CFA uses parametric polymorphism and allows overloading of variables and routines:
     140\CFA is an extension of the C programming with a trait-style type-system rather then templates and objects as in \CC.
     141\CFA allows overloading of variables and routines using the left-hand assignment type to precisely select among overloaded names.
    142142\begin{cfa}
    143143int x;  char x;  double x;    // overload name x
     
    160160\end{tabular}
    161161\end{cquote}
    162 \CFA has rebindable references.
     162\CFA generalizes reference types, allowing multiple and rebindable references (like pointers).
    163163\begin{cquote}
    164164\begin{tabular}{@{}l|l@{}}
     
    189189int & @const@ & @const@ crcr = cr; // generalize
    190190\end{cfa}
    191 Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause.
    192 \begin{cfa}
    193 struct S { int i; int j; double m; };  // field i has same type in structures S and T
    194 struct T { int i; int k; int m; };
    195 void foo( S s, T t ) @with( s, t )@ {   // open structure scope s and t in parallel
    196         j + k;                          $\C[1.6in]{// unambiguous, s.j + t.k}$
    197         m = 5.0;                        $\C{// unambiguous, s.m = 5.0}$
    198         m = 1;                          $\C{// unambiguous, t.m = 1}$
    199         int a = m;                      $\C{// unambiguous, a = t.m}$
    200         double b = m;           $\C{// unambiguous, b = s.m}$
    201         int c = s.i + t.i;      $\C{// unambiguous with qualification}$
    202         (double)m;                      $\C{// unambiguous with cast s.m}\CRT$
    203 }
    204 \end{cfa}
    205 \noindent
    206 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA.
    207191
    208192
     
    246230\end{tabular}
    247231\end{cquote}
    248 To simplify loop iteration a range is provided, specified from low to high, and a traversal direction, ascending (@+@) or descending (@-@).
     232To simplify loop iteration a range is provided, from low to high, and a traversal direction, ascending (@+@) or descending (@-@).
    249233The following is the syntax for the loop range, where @[@\,@]@ means optional.
    250234\begin{cfa}[deletekeywords=default]
     
    449433\section{String}
    450434
     435The @string@ type in \CFA is very similar to that in \CC.
    451436\begin{cquote}
    452437\begin{tabular}{@{}l|l@{}}
     
    475460s1 == s2; s1 != s2;
    476461s1 < s2;  s1 <= s2;  s1 > s2;  s1 >= s2;
    477 len( s1 );
     462len( s1 ); // like C strlen( s1 )
    478463s1[3];
    479464s1( 2 );  s1( 2, 3 );
     
    492477
    493478\begin{cquote}
     479\setlength{\tabcolsep}{5pt}
    494480\begin{tabular}{@{}l|l@{}}
    495481\begin{uC++}
     
    501487        S( int i ) { S::i = i; }
    502488};
    503 void f( uArrayRef( S, parm ) );
     489void f( @uArrayRef( S, parm )@ );
    504490int main() {
    505491        enum { N = 5 };
     
    523509};
    524510void ?{}( S & s, int i ) { s.i = i; }
    525 forall( [N] ) void f( array( S, N ) & parm ) {}
     511@forall( [N] )@ void f( @array( S, N ) & parm@ ) {}
    526512int main() {
    527513        enum { N = 5 };
     
    542528\section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}}
    543529
     530\CFA is NOT an object-oriented programming-language, so there is no receiver (\lstinline[language=c++]{this}) or nested structure routines.
     531The equivalent of a \emph{member} routine has an explicit structure parameter in any parameter position (often the first).
    544532\begin{cquote}
    545533\begin{tabular}{@{}l|l@{}}
     
    567555\end{tabular}
    568556\end{cquote}
     557Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause.
     558\begin{cfa}
     559struct S { int i; int j; double m; };  // field i has same type in structures S and T
     560struct T { int i; int k; int m; };
     561void foo( S s, T t ) @with( s, t )@ {   // open structure scope s and t in parallel
     562        j + k;                          $\C[1.6in]{// unambiguous, s.j + t.k}$
     563        m = 5.0;                        $\C{// unambiguous, s.m = 5.0}$
     564        m = 1;                          $\C{// unambiguous, t.m = 1}$
     565        int a = m;                      $\C{// unambiguous, a = t.m}$
     566        double b = m;           $\C{// unambiguous, b = s.m}$
     567        int c = s.i + t.i;      $\C{// unambiguous with qualification}$
     568        (double)m;                      $\C{// unambiguous with cast s.m}\CRT$
     569}
     570\end{cfa}
     571\noindent
     572In subsequent code examples, the left example is \CC/\uC and the right example is \CFA.
    569573
    570574
    571575\section{Constructor / Destructor}
    572576
     577A constructor/destructor must have its structure type as the first parameter and be a reference.
    573578\begin{cquote}
    574579\begin{tabular}{@{}l|l@{}}
     
    599604struct S { int i, j; };
    600605
    601 void @?{}@( S & s ) { s.i = s.j = 3; } $\C[3in]{// default}$
    602 void @?{}@( S & s, int i, int j ) { s.i = i; s.j = j; } $\C{// initializer}$
    603 void @?{}@( S & s, const S rhs ) { ?{}( s, rhs.i, rhs.j ); } $\C{// copy}$
    604 void @^?{}@( S & s ) { s.i = 0; s.j = 0; } $\C{// destructor}\CRT$
     606void @?{}@( @S & s@ ) { s.i = s.j = 3; } $\C[3in]{// default}$
     607void @?{}@( @S & s@, int i, int j ) { s.i = i; s.j = j; } $\C{// initializer}$
     608void @?{}@( @S & s@, const S rhs ) { ?{}( s, rhs.i, rhs.j ); } $\C{// copy}$
     609void @^?{}@( @S & s@ ) { s.i = 0; s.j = 0; } $\C{// destructor}\CRT$
    605610
    606611S s0;
    607612S s1 = { 1, 2 };
    608 // cannot use 0/1 (zero_t/one_t) with "new"
    609 S * s2 = new( 1@n@, 2 ); // n => (int)
     613// bug, cannot use 0/1 (zero_t/one_t) with "new"
     614S * s2 = new( 0@n@, 2 ); // suffix n => (natural int)
    610615delete( s2 );
    611 s2 = new( 1n, 2 );
     616s2 = new( 1@n@, 2 );
    612617delete( s2 );
    613 S & s3 = *new( 1n, 2 );
     618S & s3 = *new( 2, 2 );
    614619delete( &s3 );
    615 &s3 = &*new( 1n, 2 );
     620&s3 = &*new( 3, 2 );
    616621delete( &s3 );
    617622\end{cfa}
     
    625630\begin{tabular}{@{}l|ll@{}}
    626631\begin{uC++}
    627 
    628632@_Coroutine@ C {
    629633        // private coroutine fields
     
    718722                val( val ) {}
    719723};
     724\end{uC++}
     725&
     726\begin{cfa}
     727#include <fstream.hfa>
     728#include <mutex_stmt.hfa>
     729#include <actor.hfa>
     730
     731struct StrMsg {
     732        @inline message;@ // derived message
     733        const char * val; // string message
     734};
     735void ?{}( StrMsg & msg, const char * str ) {
     736        @set_allocation( msg, Delete );@ // delete after use
     737        msg.val = str;
     738}
     739\end{cfa}
     740\end{tabular}
     741\begin{tabular}{@{}l|ll@{}}
     742\begin{uC++}
    720743_Actor Hello { ${\color{red}\LstCommentStyle{// : public uActor}}$
    721744        Allocation receive( Message & msg ) {
     
    741764&
    742765\begin{cfa}
    743 #include <fstream.hfa>
    744 #include <mutex_stmt.hfa>
    745 #include <actor.hfa>
    746 
    747 struct StrMsg {
    748         @inline message;@ // derived message
    749         const char * val; // string message
    750 };
    751 void ?{}( StrMsg & msg, const char * str ) {
    752         @set_allocation( msg, Delete );@ // delete after use
    753         msg.val = str;
    754 }
    755766struct Hello { @inline actor;@ }; // derived actor
    756767allocation receive( Hello & receiver, @start_msg_t@ & ) {
     
    898909\end{cquote}
    899910
    900 \newpage
     911
     912\enlargethispage{1000pt}
    901913
    902914\section{Monitor}
     
    967979\end{cquote}
    968980
    969 \enlargethispage{1000pt}
    970 
     981\newpage
    971982\noindent
    972983External Scheduling
Note: See TracChangeset for help on using the changeset viewer.