- Timestamp:
- Sep 10, 2025, 10:32:19 PM (2 weeks ago)
- Branches:
- master
- Children:
- a307552
- Parents:
- 421b242
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/uC++toCFA/uC++toCFA.tex
r421b242 r04375cf 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Aug 28 13:41:34202514 %% Update Count : 6 49313 %% Last Modified On : Mon Sep 8 18:10:30 2025 14 %% Update Count : 6534 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 138 138 \section{Introduction} 139 139 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. 142 142 \begin{cfa} 143 143 int x; char x; double x; // overload name x … … 160 160 \end{tabular} 161 161 \end{cquote} 162 \CFA has rebindable references.162 \CFA generalizes reference types, allowing multiple and rebindable references (like pointers). 163 163 \begin{cquote} 164 164 \begin{tabular}{@{}l|l@{}} … … 189 189 int & @const@ & @const@ crcr = cr; // generalize 190 190 \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 T194 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 parallel196 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 \noindent206 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA.207 191 208 192 … … 246 230 \end{tabular} 247 231 \end{cquote} 248 To simplify loop iteration a range is provided, specifiedfrom low to high, and a traversal direction, ascending (@+@) or descending (@-@).232 To simplify loop iteration a range is provided, from low to high, and a traversal direction, ascending (@+@) or descending (@-@). 249 233 The following is the syntax for the loop range, where @[@\,@]@ means optional. 250 234 \begin{cfa}[deletekeywords=default] … … 449 433 \section{String} 450 434 435 The @string@ type in \CFA is very similar to that in \CC. 451 436 \begin{cquote} 452 437 \begin{tabular}{@{}l|l@{}} … … 475 460 s1 == s2; s1 != s2; 476 461 s1 < s2; s1 <= s2; s1 > s2; s1 >= s2; 477 len( s1 ); 462 len( s1 ); // like C strlen( s1 ) 478 463 s1[3]; 479 464 s1( 2 ); s1( 2, 3 ); … … 492 477 493 478 \begin{cquote} 479 \setlength{\tabcolsep}{5pt} 494 480 \begin{tabular}{@{}l|l@{}} 495 481 \begin{uC++} … … 501 487 S( int i ) { S::i = i; } 502 488 }; 503 void f( uArrayRef( S, parm ));489 void f( @uArrayRef( S, parm )@ ); 504 490 int main() { 505 491 enum { N = 5 }; … … 523 509 }; 524 510 void ?{}( 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@ ) {} 526 512 int main() { 527 513 enum { N = 5 }; … … 542 528 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} 543 529 530 \CFA is NOT an object-oriented programming-language, so there is no receiver (\lstinline[language=c++]{this}) or nested structure routines. 531 The equivalent of a \emph{member} routine has an explicit structure parameter in any parameter position (often the first). 544 532 \begin{cquote} 545 533 \begin{tabular}{@{}l|l@{}} … … 567 555 \end{tabular} 568 556 \end{cquote} 557 Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause. 558 \begin{cfa} 559 struct S { int i; int j; double m; }; // field i has same type in structures S and T 560 struct T { int i; int k; int m; }; 561 void 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 572 In subsequent code examples, the left example is \CC/\uC and the right example is \CFA. 569 573 570 574 571 575 \section{Constructor / Destructor} 572 576 577 A constructor/destructor must have its structure type as the first parameter and be a reference. 573 578 \begin{cquote} 574 579 \begin{tabular}{@{}l|l@{}} … … 599 604 struct S { int i, j; }; 600 605 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$606 void @?{}@( @S & s@ ) { s.i = s.j = 3; } $\C[3in]{// default}$ 607 void @?{}@( @S & s@, int i, int j ) { s.i = i; s.j = j; } $\C{// initializer}$ 608 void @?{}@( @S & s@, const S rhs ) { ?{}( s, rhs.i, rhs.j ); } $\C{// copy}$ 609 void @^?{}@( @S & s@ ) { s.i = 0; s.j = 0; } $\C{// destructor}\CRT$ 605 610 606 611 S s0; 607 612 S 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" 614 S * s2 = new( 0@n@, 2 ); // suffix n => (natural int) 610 615 delete( s2 ); 611 s2 = new( 1 n, 2 );616 s2 = new( 1@n@, 2 ); 612 617 delete( s2 ); 613 S & s3 = *new( 1n, 2 );618 S & s3 = *new( 2, 2 ); 614 619 delete( &s3 ); 615 &s3 = &*new( 1n, 2 );620 &s3 = &*new( 3, 2 ); 616 621 delete( &s3 ); 617 622 \end{cfa} … … 625 630 \begin{tabular}{@{}l|ll@{}} 626 631 \begin{uC++} 627 628 632 @_Coroutine@ C { 629 633 // private coroutine fields … … 718 722 val( val ) {} 719 723 }; 724 \end{uC++} 725 & 726 \begin{cfa} 727 #include <fstream.hfa> 728 #include <mutex_stmt.hfa> 729 #include <actor.hfa> 730 731 struct StrMsg { 732 @inline message;@ // derived message 733 const char * val; // string message 734 }; 735 void ?{}( 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++} 720 743 _Actor Hello { ${\color{red}\LstCommentStyle{// : public uActor}}$ 721 744 Allocation receive( Message & msg ) { … … 741 764 & 742 765 \begin{cfa} 743 #include <fstream.hfa>744 #include <mutex_stmt.hfa>745 #include <actor.hfa>746 747 struct StrMsg {748 @inline message;@ // derived message749 const char * val; // string message750 };751 void ?{}( StrMsg & msg, const char * str ) {752 @set_allocation( msg, Delete );@ // delete after use753 msg.val = str;754 }755 766 struct Hello { @inline actor;@ }; // derived actor 756 767 allocation receive( Hello & receiver, @start_msg_t@ & ) { … … 898 909 \end{cquote} 899 910 900 \newpage 911 912 \enlargethispage{1000pt} 901 913 902 914 \section{Monitor} … … 967 979 \end{cquote} 968 980 969 \enlargethispage{1000pt} 970 981 \newpage 971 982 \noindent 972 983 External Scheduling
Note:
See TracChangeset
for help on using the changeset viewer.