Changeset bf91d1d for doc/uC++toCFA
- Timestamp:
- Oct 26, 2024, 6:51:04 PM (8 weeks ago)
- Branches:
- master
- Children:
- 33474e6, 63cf80e
- Parents:
- 14c31eb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/uC++toCFA/uC++toCFA.tex
r14c31eb rbf91d1d 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Wed Sep 18 21:35:47202414 %% Update Count : 599913 %% Last Modified On : Tue Oct 22 17:45:48 2024 14 %% Update Count : 6068 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 183 183 struct S { int i; int j; double m; }; // field i has same type in structures S and T 184 184 struct T { int i; int k; int m; }; 185 void foo( S s, T t ) @with( s, t)@ { // open structure scope s and t in parallel185 void foo( S s, T t ) @with( s, t )@ { // open structure scope s and t in parallel 186 186 j + k; $\C[1.6in]{// unambiguous, s.j + t.k}$ 187 187 m = 5.0; $\C{// unambiguous, s.m = 5.0}$ … … 357 357 358 358 359 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} 360 361 \begin{cquote} 362 \begin{tabular}{@{}l|l@{}} 363 \begin{uC++} 364 struct S { 365 int i = 0; // cheat, implicit default constructor 366 int setter( int j ) { int t = i; i = j; return t; } 367 int getter() { return i; } 368 }; 369 S s; 370 @s.@setter( 3 ); // object calls 371 int k = @s.@getter(); 372 \end{uC++} 373 & 374 \begin{cfa} 375 struct S { int i; }; 376 void ?{}( S & s ) { s.i = 0; } // explicit default constructor 377 int setter( @S & s,@ int j ) @with( s )@ { int t = i; i = j; return t; } 378 int getter( @S & s@ ) @with( s )@ { return i; } 379 380 S s; 381 setter( @s,@ 3 ); // normal calls 382 int k = getter( @s@ ); 383 \end{cfa} 384 \end{tabular} 385 \end{cquote} 386 387 359 388 \section{Constructor / Destructor} 360 389 … … 362 391 \begin{tabular}{@{}l|l@{}} 363 392 \begin{uC++} 393 364 394 struct S { 365 ... // fields 366 @S@( ... ) { ... } 367 @~S@( ... ) { ... } 368 }; 369 \end{uC++} 370 & 371 \begin{cfa} 395 int i, j; 396 S( int i, int j ) { S::i = i; S::j = j; } 397 ~S() {} 398 }; 399 S s = { 1, 2 }, s2{ 1, 2 }; 400 S * s3 = new S{ 1, 2 }; 401 S & s4 = *new S{ 1, 2 }; 402 \end{uC++} 403 & 404 \begin{cfa} 405 #include <stdlib.hfa> // malloc 372 406 struct S { 373 ... // fields 374 }; 375 @?{}@( @S & s,@ ... ) { ... } 376 @^?{}@( @S & s@ ) { ... } 407 int i, j; 408 }; 409 void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; } 410 void ^?{}( S & s ) {} 411 S s = { 1, 2 }, s2{ 1, 2 }; 412 S * s3 = &(*malloc()){ 1, 2 }; 413 S & s4 = (*malloc()){ 1, 2 }; // fails 377 414 \end{cfa} 378 415 \end{tabular} … … 422 459 423 460 424 \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}}425 426 \begin{cquote}427 \begin{tabular}{@{}l|l@{}}428 \begin{uC++}429 struct S {430 int i = 0; // cheat, implicit default constructor431 int setter( int j ) { int t = i; i = j; return t; }432 int getter() { return i; }433 };434 435 S s;436 @s.@setter( 3 ); // object calls437 int k = @s.@getter();438 \end{uC++}439 &440 \begin{cfa}441 struct S {442 int i;443 };444 void ?{}( S & s ) { s.i = 0; } // explicit default constructor445 int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; }446 int getter( @S & s@ ) @with(s)@ { return i; }447 S s;448 setter( @s,@ 3 ); // normal calls449 int k = getter( @s@ );450 \end{cfa}451 \end{tabular}452 \end{cquote}453 454 455 461 \section{\texorpdfstring{\lstinline{uArray}}{uArray}} 456 462 … … 503 509 ... suspend(); ... 504 510 ... _Resume E( ... ) _At partner; 511 ... uThisCoroutine(); ... 512 505 513 } 506 514 public: … … 520 528 ... suspend; ... // keyword not routine 521 529 ... resumeAt( partner, ExceptionInst( E, ... ) ); 530 ... active_coroutine(); ... 522 531 } 523 532 void mem( C & c, ... ) { … … 531 540 532 541 542 \section{\lstinline{COBEGIN}/\lstinline{COFOR}} 543 544 \begin{cquote} 545 \begin{tabular}{@{}l|ll@{}} 546 \begin{uC++} 547 548 #include <uCobegin.h> 549 int main() { 550 COBEGIN 551 BEGIN osacquire( cout ) << "A" << endl; END 552 BEGIN osacquire( cout ) << "B" << endl; END 553 BEGIN osacquire( cout ) << "C" << endl; END 554 BEGIN osacquire( cout ) << "D" << endl; END 555 BEGIN osacquire( cout ) << "E" << endl; END 556 COEND 557 COFOR( i, 1, 10, 558 osacquire( cout ) << i << endl; 559 ) 560 } 561 \end{uC++} 562 & 563 \begin{cfa} 564 #include <mutex_stmt.hfa> 565 #include <$cofor$.hfa> 566 int main() { 567 { 568 corun { mutex( sout ) sout | "A"; } 569 corun { mutex( sout ) sout | "B"; } 570 corun { mutex( sout ) sout | "C"; } 571 corun { mutex( sout ) sout | "D"; } 572 corun { mutex( sout ) sout | "E"; } 573 } 574 cofor( i; 10 ) { 575 mutex( sout ) sout | i; 576 } 577 } 578 \end{cfa} 579 \end{tabular} 580 \end{cquote} 581 582 583 \section{Actor} 584 585 \begin{cquote} 586 \begin{tabular}{@{}l|ll@{}} 587 \begin{uC++} 588 #include <iostream> 589 using namespace std; 590 #include <uActor.h> 591 592 struct StrMsg : @public uActor::Message@ { 593 const char * val; // string message 594 595 596 StrMsg( const char * val ) : 597 @Message( uActor::Delete )@, // delete after use 598 val( val ) {} 599 }; 600 _Actor Hello { ${\color{red}\LstCommentStyle{// : public uActor}}$ 601 Allocation receive( Message & msg ) { 602 Case( StrMsg, msg ) { // discriminate 603 osacquire( cout ) << msg_d->val << endl; 604 }; 605 return Delete; // delete after use 606 } 607 }; 608 int main() { 609 @uActor::start();@ // start actor system 610 *new Hello() | *new StrMsg( "hello" ); 611 *new Hello() | *new StrMsg( "bonjour" ); 612 @uActor::stop();@ // wait for all actors to terminate 613 } 614 \end{uC++} 615 & 616 \begin{cfa} 617 #include <fstream.hfa> 618 #include <mutex_stmt.hfa> 619 #include <actor.hfa> 620 621 struct StrMsg { 622 @inline message;@ // derived message 623 const char * val; // string message 624 }; 625 void ?{}( StrMsg & msg, char * str ) { 626 msg.val = str; 627 @set_allocation( msg, Delete );@ // delete after use 628 } 629 struct Hello { 630 @inline actor;@ // derived actor 631 }; 632 allocation receive( Hello & receiver, StrMsg & msg ) { 633 mutex( sout ) sout | msg.val; 634 return Delete; // delete after use 635 } 636 637 int main() { 638 @start_actor_system();@ // start actor system 639 *(Hello *)new() | *(StrMsg *)new( "hello" ); 640 *(Hello *)new() | *(StrMsg *)new( "bonjour" ); 641 @stop_actor_system();@ // wait for all actors to terminate 642 } 643 \end{cfa} 644 \end{tabular} 645 \end{cquote} 646 647 648 \section{Threads} 649 650 \begin{cquote} 651 \begin{tabular}{@{}l|ll@{}} 652 \begin{uC++} 653 654 @_Task@ T { 655 // private task fields 656 void main() { 657 ... _Resume E( ... ) _At partner; 658 ... uThisTask(); ... 659 } 660 public: 661 }; 662 \end{uC++} 663 & 664 \begin{cfa} 665 #include <$thread$.hfa> 666 @thread@ T { 667 // private task fields 668 669 }; 670 void main( @T & t@ ) { 671 ... resumeAt( partner, ExceptionInst( E, ... ) ); 672 ... active_thread(); ... 673 } 674 \end{cfa} 675 \\ 676 \multicolumn{2}{@{}l@{}}{\lstinline{T t; // start thread in main routine}} 677 \end{tabular} 678 \end{cquote} 679 680 533 681 \section{Locks} 534 682 … … 539 687 uOwnerLock m; 540 688 uCondLock s; 541 bool avail = true;542 689 m.acquire(); 543 if ( ! avail) s.wait( m );690 if ( ! s.empty() ) s.wait( m ); 544 691 else { 545 avail = false;546 692 m.release(); 547 693 } … … 552 698 #include <locks.hfa> 553 699 owner_lock m; 554 condition_variable( owner_lock ) s; 555 bool avail = true; 700 condition_variable( owner_lock ) s; // generic type on mutex lock 556 701 lock( m ); 557 if ( ! avail) wait( s, m );702 if ( ! empty( s ) ) wait( s, m ); 558 703 else { 559 avail = false;560 704 unlock( m ); 561 705 } … … 599 743 \\ 600 744 \multicolumn{2}{@{}l@{}}{\lstinline{M m;}} 601 \end{tabular}602 \end{cquote}603 604 605 \section{Threads}606 607 \begin{cquote}608 \begin{tabular}{@{}l|ll@{}}609 \begin{uC++}610 611 @_Task@ T {612 // private task fields613 void main() {614 ... _Resume E( ... ) _At partner;615 }616 public:617 };618 \end{uC++}619 &620 \begin{cfa}621 #include <$thread$.hfa>622 @thread@ T {623 // private task fields624 625 };626 void main( @T & t@ ) {627 ... resumeAt( partner, ExceptionInst( E, ... ) );628 }629 \end{cfa}630 \\631 \multicolumn{2}{@{}l@{}}{\lstinline{T t; // start thread in main routine}}632 745 \end{tabular} 633 746 \end{cquote}
Note: See TracChangeset
for help on using the changeset viewer.