Changeset 960665c
- Timestamp:
- Aug 20, 2024, 6:15:01 PM (13 months ago)
- Branches:
- master
- Children:
- ad47ec4
- Parents:
- d1f5054 (diff), df2e00f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 12 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rd1f5054 r960665c 471 471 E e; 472 472 473 for () { 474 try { 475 @sin | e@; 476 } catch( missing_data * ) { 477 sout | "missing data"; 478 continue; // try again 473 try { 474 for () { 475 try { 476 @sin | e@; 477 } catch( missing_data * ) { 478 sout | "missing data"; 479 continue; // try again 480 } 481 sout | e | "= " | value( e ); 479 482 } 480 if ( eof( sin ) ) break; 481 sout | e | "= " | value( e ); 482 } 483 } catch( end_of_file ) {} 483 484 } 484 485 \end{cfa} -
doc/theses/mike_brooks_MMath/array.tex
rd1f5054 r960665c 205 205 Orthogonally, the new @array@ type works with \CFA's generic types, providing argument safety and the associated implicit communication of array length. 206 206 Specifically, \CFA allows aggregate types to be generalized with multiple type parameters, including parameterized element types and lengths. 207 Doing so gives a refinement of C's ``flexible array member'' pattern, allowing nesting structures with array members anywhere within otherstructures.207 Doing so gives a refinement of C's ``flexible array member'' pattern, allowing nesting structures with array members anywhere within the structures. 208 208 \lstinput{10-15}{hello-accordion.cfa} 209 This structure's layout has the starting offset of @ municipalities@ varying in @NprovTerty@, and the offset of @total_pt@ and @total_mun@ varying in both generic parameters.210 For a function that operates on a @ CanPop@ structure, the type system handles this variationtransparently.209 This structure's layout has the starting offset of @studentIds@ varying in generic parameter @C@, and the offset of @preferences@ varying in both generic parameters. 210 For a function that operates on a @School@ structure, the type system handles this memory layout transparently. 211 211 \lstinput{40-45}{hello-accordion.cfa} 212 \VRef[Figure]{f:checkHarness} shows the @ CanPop@ harness and results with different array sizes, if the municipalities changed after a census.212 \VRef[Figure]{f:checkHarness} shows the @School@ harness and results with different array sizes, where multidimensional arrays are discussed next. 213 213 214 214 \begin{figure} 215 \lstinput{60-68}{hello-accordion.cfa} 216 \lstinput{70-75}{hello-accordion.cfa} 217 \caption{\lstinline{check} Harness} 215 % super hack to get this to line up 216 \begin{tabular}{@{}ll@{\hspace{25pt}}l@{}} 217 \begin{tabular}{@{}p{3.25in}@{}} 218 \lstinput{60-66}{hello-accordion.cfa} 219 \vspace*{-3pt} 220 \lstinput{73-80}{hello-accordion.cfa} 221 \end{tabular} 222 & 223 \raisebox{0.32\totalheight}{% 224 \lstinput{85-93}{hello-accordion.cfa} 225 }% 226 & 227 \lstinput{95-109}{hello-accordion.cfa} 228 \end{tabular} 229 \caption{\lstinline{school} Harness and Output} 218 230 \label{f:checkHarness} 219 231 \end{figure} … … 488 500 From there, @x[all]@ itself is simply a two-dimensional array, in the strict C sense, of these building blocks. 489 501 An atom (like the bottommost value, @x[all][3][2]@), is the contained value (in the square box) 490 and a lie about its size (the wedgeabove it, growing upward).502 and a lie about its size (the left diagonal above it, growing upward). 491 503 An array of these atoms (like the intermediate @x[all][3]@) is just a contiguous arrangement of them, done according to their size; 492 504 call such an array a column. 493 505 A column is almost ready to be arranged into a matrix; 494 506 it is the \emph{contained value} of the next-level building block, but another lie about size is required. 495 At first, an atom needs to be arranged as if it were bigger, but now a column needs to be arranged as if it is smaller (the wedgeabove it, shrinking upward).507 At first, an atom needs to be arranged as if it were bigger, but now a column needs to be arranged as if it is smaller (the left diagonal above it, shrinking upward). 496 508 These lying columns, arranged contiguously according to their size (as announced) form the matrix @x[all]@. 497 509 Because @x[all]@ takes indices, first for the fine stride, then for the coarse stride, it achieves the requirement of representing the transpose of @x@. … … 502 514 compared with where analogous rows appear when the row-level option is presented for @x@. 503 515 504 \PAB{I don't understand this paragraph: These size lies create an appearance of overlap. 505 For example, in \lstinline{x[all]}, the shaded band touches atoms 2.0, 2.1, 2.2, 2.3, 1.4, 1.5 and 1.6. 516 For example, in \lstinline{x[all]}, the shaded band touches atoms 2.0, 2.1, 2.2, 2.3, 1.4, 1.5 and 1.6 (left diagonal). 506 517 But only the atom 2.3 is storing its value there. 507 The rest are lying about (conflicting) claims on this location, but never exercising these alleged claims. }518 The rest are lying about (conflicting) claims on this location, but never exercising these alleged claims. 508 519 509 520 Lying is implemented as casting. … … 511 522 This structure uses one type in its internal field declaration and offers a different type as the return of its subscript operator. 512 523 The field within is a plain-C array of the fictional type, which is 7 floats long for @x[all][3][2]@ and 1 float long for @x[all][3]@. 513 The subscript operator presents what is really inside, by casting to the type below the wedgeof the lie.524 The subscript operator presents what is really inside, by casting to the type below the left diagonal of the lie. 514 525 515 526 % Does x[all] have to lie too? The picture currently glosses over how it it advertises a size of 7 floats. I'm leaving that as an edge case benignly misrepresented in the picture. Edge cases only have to be handled right in the code. -
doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa
rd1f5054 r960665c 8 8 9 9 10 forall( T, @[NprovTerty]@, @[Nmunicipalities]@ )11 struct CanPop{12 array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$13 array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$14 int total_pt, total_mun;10 forall( [C], [S] ) $\C{// Class size, Students in class}$ 11 struct School { 12 @array( int, C )@ classIds; $\C{// nested VLAs}$ 13 @array( int, S )@ studentIds; 14 @array( int, C, S )@ preferences; $\C{// multidimensional}$ 15 15 }; 16 16 17 17 18 18 19 // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) 19 20 20 forall( T, [NprovTerty], [Nmunicipalities] )21 void ?{}( T &, CanPop( T, NprovTerty, Nmunicipalities) & this ) {}21 forall( [C], [S] ) 22 void ?{}( School( C, S ) & this ) {} 22 23 23 forall( T &, [NprovTerty], [Nmunicipalities] )24 void ^?{}( CanPop( T, NprovTerty, Nmunicipalities) & this ) {}24 forall( [C], [S] ) 25 void ^?{}( School( C, S ) & this ) {} 25 26 26 27 … … 37 38 38 39 39 40 forall( T, [NprovTerty], [Nmunicipalities] ) 41 void check( CanPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) { 42 total_pt = total_mun = 0; 43 for ( i; NprovTerty ) total_pt += provTerty[i]; 44 for ( i; Nmunicipalities ) total_mun += municipalities[i]; 40 forall( [C], [S] ) 41 void init( @School( C, S ) & classes@, int class, int student, int pref ) with( classes ) { 42 classIds[class] = class; $\C{// handle dynamic offsets of fields within structure}$ 43 studentIds[student] = student; 44 preferences[class][student] = pref; 45 45 } 46 46 … … 58 58 59 59 60 int main( int argc, char * argv[] ) { 61 const int npt = ato( argv[1] ), nmun = ato( argv[2] ); 62 @CanPop( int, npt, nmun ) pop;@ 63 // read in population numbers 64 @check( pop );@ 65 sout | setlocale( LC_NUMERIC, getenv( "LANG" ) ); 66 sout | "Total province/territory:" | pop.total_pt; 67 sout | "Total municipalities:" | pop.total_mun; 60 int main() { 61 int classes, students; 62 sin | classes | students; 63 @School( classes, students ) school;@ 64 int class, student, preference; 65 // read data into school calling init 66 // for each student's class/preferences 67 try { 68 for ( ) { 69 sin | class | student | preference; 70 init( school, class, student, preference ); 71 } 72 } catch( end_of_file * ) {} 73 for ( s; students ) { 74 sout | "student" | s | nonl; 75 for ( c; classes ) { 76 sout | school.preferences[c][s] | nonl; 77 } 78 sout | nl; 79 } 68 80 } 81 82 83 69 84 /* 70 $\$$ ./a.out 13 3573 71 Total province/territory: 36,991,981 72 Total municipalities: 36,991,981 73 $\$$ ./a.out 13 3654 74 Total province/territory: 36,991,981 75 Total municipalities: 36,991,981 85 $\$$ cat school1 86 2 2 87 0 0 1 88 1 0 7 89 0 1 12 90 1 1 13 91 $\$$ a.out < school1 92 student 0 1 7 93 student 1 12 13 94 95 $\$$ cat school2 96 3 3 97 0 0 1 98 1 0 7 99 2 0 8 100 0 1 12 101 1 1 13 102 2 1 14 103 0 2 26 104 1 2 27 105 2 2 28 106 $\$$ a.out < school2 107 student 0 1 7 8 108 student 1 12 13 14 109 student 2 26 27 28 76 110 */ 77 111 -
doc/theses/mike_brooks_MMath/string.tex
rd1f5054 r960665c 1 1 \chapter{String} 2 2 3 4 5 6 7 \s ubsection{Logical overlap}3 This chapter presents my work on designing and building a modern string type in \CFA. 4 The discussion starts with examples of interesting string problems, followed by examples of how these issues are solved in my design. 5 6 7 \section{Logical overlap} 8 8 9 9 \input{sharing-demo.tex} … … 20 20 \subsection{RAII limitations} 21 21 22 Earlier work on \CFA [to cite Schluntz] implemented the feature of constructors and destructors. A constructor is a user-defined function that runs implicitly, when control passes an object's declaration, while a destructor runs at the exit of the declaration's lexical scope. The feature allows programmers to assume that, whenever a runtime object of a certain type is accessible, the system called one of the programmer's const uctor functions on that object, and a matching destructor call will happen in the future. The feature helps programmers know that their programs' invariants obtain.23 24 The purposes of such invariants go beyond ensuring authentic values for the bits inside the object. These invariants can track occurrences of the managed objects in other data structures. Reference counting is a typical application of the latter invariant type. With a reference-counting smart pointer, the const urctor and destructor \emph{of the pointer type} track the lifecycles of occurrences of these pointers, by incrementing and decrementing a counter (ususally) on the referent object, that is, they maintain a that is state separate from the objects to whose lifecycles they are attached. Both the \CC and \CFA RAII systems ares powerful enough to achive such reference counting.25 26 The \CC RAII system supports a more advanced application. A life cycle function has access to the object under managamanet, by location; constructors and destuctors receive a @this@ parameter providing its memory address. A lifecycle-function implementation can then add its objects to a collection upon creation, and remove them at destruction. A modulue that provides such objects, by using and encapsulating such a collection, can traverse the collection at relevant times, to keep the objects ``good.'' Then, if you are the user of such an module, declaring an object of its type means not only receiving an authentically ``good'' value at initialization, but receiving a subscription to a service that will keep the value ``good'' until you are done with it.22 Earlier work on \CFA [to cite Schluntz] implemented the feature of constructors and destructors. A constructor is a user-defined function that runs implicitly, when control passes an object's declaration, while a destructor runs at the exit of the declaration's lexical scope. The feature allows programmers to assume that, whenever a runtime object of a certain type is accessible, the system called one of the programmer's constructor functions on that object, and a matching destructor call will happen in the future. The feature helps programmers know that their programs' invariants obtain. 23 24 The purposes of such invariants go beyond ensuring authentic values for the bits inside the object. These invariants can track occurrences of the managed objects in other data structures. Reference counting is a typical application of the latter invariant type. With a reference-counting smart pointer, the constructor and destructor \emph{of the pointer type} track the life cycles of occurrences of these pointers, by incrementing and decrementing a counter (usually) on the referent object, that is, they maintain a that is state separate from the objects to whose life cycles they are attached. Both the \CC and \CFA RAII systems ares powerful enough to achieve such reference counting. 25 26 The \CC RAII system supports a more advanced application. A life cycle function has access to the object under management, by location; constructors and destuctors receive a @this@ parameter providing its memory address. A lifecycle-function implementation can then add its objects to a collection upon creation, and remove them at destruction. A modulue that provides such objects, by using and encapsulating such a collection, can traverse the collection at relevant times, to keep the objects ``good.'' Then, if you are the user of such an module, declaring an object of its type means not only receiving an authentically ``good'' value at initialization, but receiving a subscription to a service that will keep the value ``good'' until you are done with it. 27 27 28 28 In many cases, the relationship between memory location and lifecycle is simple. But with stack-allocated objects being used as parameters and returns, there is a sender version in one stack frame and a receiver version in another. \CC is able to treat those versions as distinct objects and guarantee a copy-constructor call for communicating the value from one to the other. This ability has implications on the language's calling convention. Consider an ordinary function @void f( Vehicle x )@, which receives an aggregate by value. If the type @Vehicle@ has custom lifecycle functions, then a call to a user-provided copy constructor occurs, after the caller evaluates its argument expression, after the callee's stack frame exists, with room for its variable @x@ (which is the location that the copy-constructor must target), but before the user-provided body of @f@ begins executing. \CC achieves this ordering by changing the function signature, in the compiled form, to pass-by-reference and having the callee invoke the copy constructor in its preamble. On the other hand, if @Vehicle@ is a simple structure then the C calling convention is applied as the code originally appeared, that is, the callsite implementation code performs a bitwise copy from the caller's expression result, into the callee's x. -
doc/user/user.tex
rd1f5054 r960665c 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Jul 26 06:56:11202414 %% Update Count : 695 513 %% Last Modified On : Thu Aug 15 22:23:30 2024 14 %% Update Count : 6957 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 4656 4656 \VRef[Figure]{f:CFACommand-LineProcessing} demonstrates the file operations by showing the idiomatic \CFA command-line processing and copying an input file to an output file. 4657 4657 Note, a stream variable may be copied because it is a reference to an underlying stream data-structures. 4658 \Textbf{All I/O errors are handled as exceptions}, but end-of-file is not an exception as C programmers are use to explicitly checking for it.4658 \Textbf{All unusual I/O cases are handled as exceptions, including end-of-file.} 4659 4659 4660 4660 \begin{figure} … … 4686 4686 in | nlOn; §\C{// turn on reading newline}§ 4687 4687 char ch; 4688 for () { §\C{// read/write characters}§ 4689 in | ch; 4690 if ( eof( in ) ) break; §\C{// eof ?}§ 4691 out | ch; 4692 } // for 4688 try { 4689 for () { §\C{// read/write characters}§ 4690 in | ch; 4691 out | ch; 4692 } // for 4693 } catch( end_of_file * ) { §\C{// end-of-file raised}§ 4694 } // try 4693 4695 } // main 4694 4696 \end{cfa} -
libcfa/src/collections/string_res.cfa
rd1f5054 r960665c 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 15 21:56:27202413 // Update Count : 8 512 // Last Modified On : Sat Aug 17 14:08:01 2024 13 // Update Count : 86 14 14 // 15 15 … … 251 251 252 252 ifstream & ?|?( ifstream & is, _Istream_Rquoted f ) with( f.rstr ) { 253 if ( eof( is ) ) throwResume ExceptionInst( missing_data);253 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 254 254 int args; 255 255 fini: { -
libcfa/src/enum.cfa
rd1f5054 r960665c 40 40 istype & ?|?( istype & is, E & e ) { 41 41 // fprintf( stderr, "here0\n" ); 42 if ( eof( is ) ) throwResume ExceptionInst( missing_data);42 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 43 43 44 44 // Match longest input enumerator string to enumerator labels, where enumerator names are unique. … … 59 59 60 60 fmt( is, " " ); // skip optional whitespace 61 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 62 61 63 for ( c; max ) { // scan columns of the label matix (some columns missing) 62 64 int args = fmt( is, "%c", &ch ); // read character -
libcfa/src/heap.cfa
rd1f5054 r960665c 354 354 }; 355 355 356 static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0]), "size of bucket array wrong" );356 static_assert( sizeof(bucketSizes) == NoBucketSizes * sizeof(unsigned int), "size of bucket array wrong" ); 357 357 358 358 -
libcfa/src/iostream.cfa
rd1f5054 r960665c 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 2 07:38:44202413 // Update Count : 20 2112 // Last Modified On : Sat Aug 17 12:31:47 2024 13 // Update Count : 2038 14 14 // 15 15 … … 777 777 forall( istype & | basic_istream( istype ) ) { 778 778 istype & ?|?( istype & is, bool & b ) { 779 if ( eof( is ) ) throwResume ExceptionInst( missing_data);779 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 780 780 int len = -1; // len not set if no match 781 // Optional leading whitespace at start of strings.781 // remove optional leading whitespace at start of strings. 782 782 fmt( is, " " FALSE "%n", &len ); // try false 783 783 if ( len != sizeof( FALSE ) - 1 ) { // -1 removes null terminate … … 792 792 793 793 istype & ?|?( istype & is, char & c ) { 794 if ( eof( is ) ) throwResume ExceptionInst( missing_data);794 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 795 795 char temp; 796 796 for () { 797 797 int args = fmt( is, "%c", &temp ); 798 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 798 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 799 assert( args == 1 ); // if not EOF => a single character must be read 799 800 // do not overwrite parameter with newline unless appropriate 800 801 if ( temp != '\n' || getANL$( is ) ) { c = temp; break; } 801 if ( eof( is ) ) break;802 802 } // for 803 803 return is; … … 805 805 806 806 istype & ?|?( istype & is, signed char & sc ) { 807 if ( eof( is ) ) throwResume ExceptionInst( missing_data);808 int args = fmt( is, "%hhi", &sc ); 809 if ( args != 1 ) throwResume ExceptionInst( missing_data );807 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 808 int args = fmt( is, "%hhi", &sc ); // can be multiple characters (100) 809 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 810 810 return is; 811 811 } // ?|? 812 812 813 813 istype & ?|?( istype & is, unsigned char & usc ) { 814 if ( eof( is ) ) throwResume ExceptionInst( missing_data);815 int args = fmt( is, "%hhi", &usc ); 814 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 815 int args = fmt( is, "%hhi", &usc ); // can be multiple characters (-100) 816 816 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 817 817 return is; … … 819 819 820 820 istype & ?|?( istype & is, short int & si ) { 821 if ( eof( is ) ) throwResume ExceptionInst( missing_data);821 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 822 822 int args = fmt( is, "%hi", &si ); 823 823 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 826 826 827 827 istype & ?|?( istype & is, unsigned short int & usi ) { 828 if ( eof( is ) ) throwResume ExceptionInst( missing_data);828 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 829 829 int args = fmt( is, "%hi", &usi ); 830 830 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 833 833 834 834 istype & ?|?( istype & is, int & i ) { 835 if ( eof( is ) ) throwResume ExceptionInst( missing_data);835 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 836 836 int args = fmt( is, "%i", &i ); 837 837 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 840 840 841 841 istype & ?|?( istype & is, unsigned int & ui ) { 842 if ( eof( is ) ) throwResume ExceptionInst( missing_data);842 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 843 843 int args = fmt( is, "%i", &ui ); 844 844 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 847 847 848 848 istype & ?|?( istype & is, long int & li ) { 849 if ( eof( is ) ) throwResume ExceptionInst( missing_data);849 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 850 850 int args = fmt( is, "%li", &li ); 851 851 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 854 854 855 855 istype & ?|?( istype & is, unsigned long int & ulli ) { 856 if ( eof( is ) ) throwResume ExceptionInst( missing_data);856 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 857 857 int args = fmt( is, "%li", &ulli ); 858 858 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 861 861 862 862 istype & ?|?( istype & is, long long int & lli ) { 863 if ( eof( is ) ) throwResume ExceptionInst( missing_data);863 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 864 864 int args = fmt( is, "%lli", &lli ); 865 865 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 868 868 869 869 istype & ?|?( istype & is, unsigned long long int & ulli ) { 870 if ( eof( is ) ) throwResume ExceptionInst( missing_data);870 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 871 871 int args = fmt( is, "%lli", &ulli ); 872 872 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 891 891 } // for 892 892 if ( sign ) ullli = -ullli; 893 } else if ( sign ) ungetc( '-', is ); // return minus when no digits893 } // if 894 894 return is; 895 895 } // ?|? … … 897 897 898 898 istype & ?|?( istype & is, float & f ) { 899 if ( eof( is ) ) throwResume ExceptionInst( missing_data);899 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 900 900 int args = fmt( is, "%f", &f ); 901 901 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 904 904 905 905 istype & ?|?( istype & is, double & d ) { 906 if ( eof( is ) ) throwResume ExceptionInst( missing_data);906 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 907 907 int args = fmt( is, "%lf", &d ); 908 908 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 911 911 912 912 istype & ?|?( istype & is, long double & ld ) { 913 if ( eof( is ) ) throwResume ExceptionInst( missing_data);913 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 914 914 int args = fmt( is, "%Lf", &ld ); 915 915 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); … … 918 918 919 919 istype & ?|?( istype & is, float _Complex & fc ) { 920 if ( eof( is ) ) throwResume ExceptionInst( missing_data);920 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 921 921 float re, im; 922 922 int args = fmt( is, "%f%fi", &re, &im ); … … 927 927 928 928 istype & ?|?( istype & is, double _Complex & dc ) { 929 if ( eof( is ) ) throwResume ExceptionInst( missing_data);929 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 930 930 double re, im; 931 931 int args = fmt( is, "%lf%lfi", &re, &im ); … … 936 936 937 937 istype & ?|?( istype & is, long double _Complex & ldc ) { 938 if ( eof( is ) ) throwResume ExceptionInst( missing_data);938 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 939 939 long double re, im; 940 940 int args = fmt( is, "%Lf%Lfi", &re, &im ); … … 945 945 946 946 istype & ?|?( istype & is, const char fmt[] ) { // match text 947 if ( eof( is ) ) throwResume ExceptionInst( missing_data);947 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 948 948 size_t len = strlen( fmt ); 949 949 char fmtstr[len + 16]; … … 953 953 // scanf cursor does not move if no match 954 954 fmt( is, fmtstr, &len ); 955 if ( ! eof( is ) &&len == -1 ) throwResume ExceptionInst( missing_data );955 if ( len == -1 ) throwResume ExceptionInst( missing_data ); 956 956 return is; 957 957 } // ?|? … … 987 987 forall( istype & | basic_istream( istype ) ) { 988 988 istype & ?|?( istype & is, _Istream_Cskip f ) { 989 if ( eof( is ) ) throwResume ExceptionInst( missing_data);989 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 990 990 if ( f.scanset ) { 991 991 int nscanset = strlen(f.scanset); … … 1000 1000 for ( f.wd ) { // skip N characters 1001 1001 int args = fmt( is, "%c", &ch ); 1002 if ( args != 1 ) throwResume ExceptionInst( missing_data );1002 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); 1003 1003 } // for 1004 1004 } // if … … 1007 1007 1008 1008 istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) { 1009 if ( eof( is ) ) throwResume ExceptionInst( missing_data);1009 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1010 1010 int args; 1011 1011 fini: { … … 1032 1032 1033 1033 istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) { 1034 if ( eof( is ) ) throwResume ExceptionInst( missing_data);1034 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 1035 1035 const char * scanset; 1036 1036 size_t nscanset = 0; -
libcfa/src/iostream.hfa
rd1f5054 r960665c 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 2 07:37:57202413 // Update Count : 76 012 // Last Modified On : Thu Aug 15 18:21:22 2024 13 // Update Count : 761 14 14 // 15 15 … … 374 374 // *********************************** exceptions *********************************** 375 375 376 ExceptionDecl( end_of_file ); // read encounters end of file 376 377 ExceptionDecl( missing_data ); // read finds no appropriate data 377 378 ExceptionDecl( cstring_length ); // character string size exceeded -
libcfa/src/parseconfig.cfa
rd1f5054 r960665c 105 105 106 106 static [ bool ] comments( & ifstream in, size_t size, [] char name ) { 107 while () { 108 in | wdi( size, name ); 109 if ( eof( in ) ) return true; 110 if ( name[0] != '#' ) return false; 111 in | nl; // ignore remainder of line 112 } // while 107 bool comment = false; 108 try { 109 while () { 110 in | wdi( size, name ); 111 if ( name[0] != '#' ) break; 112 in | nl; // ignore remainder of line 113 } // while 114 } catch( end_of_file * ) { 115 comment = true; 116 } // try 117 return comment; 113 118 } // comments 114 119 … … 125 130 [256] char value; 126 131 127 while () { // parameter names can appear in any order 128 // NOTE: Must add check to see if already read in value for this key, 129 // once we switch to using hash table as intermediate storage 130 if ( comments( in, 64, key ) ) break; // eof ? 131 in | wdi( 256, value ); 132 133 add_kv_pair( *kv_pairs, key, value ); 134 135 if ( eof( in ) ) break; 136 in | nl; // ignore remainder of line 137 } // for 132 try { 133 while () { // parameter names can appear in any order 134 // NOTE: Must add check to see if already read in value for this key, 135 // once we switch to using hash table as intermediate storage 136 if ( comments( in, 64, key ) ) break; // eof ? 137 in | wdi( 256, value ); 138 139 add_kv_pair( *kv_pairs, key, value ); 140 141 in | nl; // ignore remainder of line 142 } // while 143 } catch( end_of_file * ) { 144 } // try 138 145 } catch( open_failure * ex; ex->istream == &in ) { 139 146 delete( kv_pairs ); -
src/GenPoly/GenPoly.cpp
rd1f5054 r960665c 27 27 #include "AST/Type.hpp" 28 28 #include "AST/TypeSubstitution.hpp" 29 #include "Common/Eval.hpp" // for eval 29 30 #include "GenPoly/ErasableScopedMap.hpp" // for ErasableScopedMap<>::const_... 30 31 #include "ResolvExpr/Typeops.hpp" // for flatten … … 243 244 } // namespace 244 245 246 // This function, and its helpers following, have logic duplicated from 247 // unification. The difference in context is that unification applies where 248 // the types "must" match, while this variation applies to arbitrary type 249 // pairs, when an optimization could apply if they happen to match. This 250 // variation does not bind type variables. The helper functions support 251 // the case for matching ArrayType. 252 bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ); 253 254 static bool exprsPolyCompatibleByStaticValue( 255 const ast::Expr * e1, const ast::Expr * e2 ) { 256 Evaluation r1 = eval(e1); 257 Evaluation r2 = eval(e2); 258 259 if ( !r1.hasKnownValue ) return false; 260 if ( !r2.hasKnownValue ) return false; 261 262 if ( r1.knownValue != r2.knownValue ) return false; 263 264 return true; 265 } 266 267 static bool exprsPolyCompatible( ast::Expr const * lhs, 268 ast::Expr const * rhs ) { 269 type_index const lid = typeid(*lhs); 270 type_index const rid = typeid(*rhs); 271 if ( lid != rid ) return false; 272 273 if ( exprsPolyCompatibleByStaticValue( lhs, rhs ) ) return true; 274 275 if ( type_index(typeid(ast::CastExpr)) == lid ) { 276 ast::CastExpr const * l = as<ast::CastExpr>(lhs); 277 ast::CastExpr const * r = as<ast::CastExpr>(rhs); 278 279 // inspect casts' target types 280 if ( !typesPolyCompatible( 281 l->result, r->result ) ) return false; 282 283 // inspect casts' inner expressions 284 return exprsPolyCompatible( l->arg, r->arg ); 285 286 } else if ( type_index(typeid(ast::VariableExpr)) == lid ) { 287 ast::VariableExpr const * l = as<ast::VariableExpr>(lhs); 288 ast::VariableExpr const * r = as<ast::VariableExpr>(rhs); 289 290 assert(l->var); 291 assert(r->var); 292 293 // conservative: variable exprs match if their declarations are 294 // represented by the same C++ AST object 295 return (l->var == r->var); 296 297 } else if ( type_index(typeid(ast::SizeofExpr)) == lid ) { 298 ast::SizeofExpr const * l = as<ast::SizeofExpr>(lhs); 299 ast::SizeofExpr const * r = as<ast::SizeofExpr>(rhs); 300 301 assert((l->type != nullptr) ^ (l->expr != nullptr)); 302 assert((r->type != nullptr) ^ (r->expr != nullptr)); 303 if ( !(l->type && r->type) ) return false; 304 305 // mutual recursion with type poly compatibility 306 return typesPolyCompatible( l->type, r->type ); 307 308 } else { 309 // All other forms compare on static value only, done earlier 310 return false; 311 } 312 } 313 245 314 bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ) { 246 315 type_index const lid = typeid(*lhs); … … 256 325 257 326 // So remaining types can be examined case by case. 258 // Recurse through type structure (conditions borrowed from Unify.cpp).327 // Recurse through type structure (conditions duplicated from Unify.cpp). 259 328 260 329 if ( type_index(typeid(ast::BasicType)) == lid ) { … … 280 349 ast::ArrayType const * r = as<ast::ArrayType>(rhs); 281 350 282 if ( l->isVarLen ) {283 if ( !r->isVarLen ) return false;284 } else {285 if ( r->isVarLen ) return false; 286 287 a uto lc = l->dimension.as<ast::ConstantExpr>();288 auto rc = r->dimension.as<ast::ConstantExpr>();289 if ( lc && rc && lc->intValue() != rc->intValue() ) {351 if ( l->isVarLen != r->isVarLen ) return false; 352 if ( (l->dimension != nullptr) != (r->dimension != nullptr) ) 353 return false; 354 355 if ( l->dimension ) { 356 assert( r->dimension ); 357 // mutual recursion with expression poly compatibility 358 if ( !exprsPolyCompatible(l->dimension, r->dimension) ) 290 359 return false; 291 }292 360 } 293 361 -
src/Parser/DeclarationNode.cpp
rd1f5054 r960665c 999 999 assert( type ); 1000 1000 1001 // Some types are parsed as declarations and, syntactically, can have 1002 // initializers. However, semantically, this is meaningless. 1003 if ( initializer ) { 1004 SemanticError( this, "Initializer on type declaration " ); 1005 } 1006 1001 1007 switch ( type->kind ) { 1002 1008 case TypeData::Aggregate: { -
src/ResolvExpr/CandidateFinder.cpp
rd1f5054 r960665c 1241 1241 Cost minCastCost = Cost::infinity; 1242 1242 for ( CandidateRef & cand : finder.candidates ) { 1243 ast::ptr< ast::Type > fromType = cand->expr->result; 1244 assert( fromType ); 1245 fromType = resolveTypeof( fromType, context ); 1246 fromType = adjustExprType( fromType, tenv, symtab ); 1247 1243 1248 ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have; 1244 1249 ast::OpenVarSet open( cand->open ); … … 1250 1255 // subexpression results that are cast directly. The candidate is invalid if it 1251 1256 // has fewer results than there are types to cast to. 1252 int discardedValues = cand->expr->result->size() - toType->size();1257 int discardedValues = fromType->size() - toType->size(); 1253 1258 if ( discardedValues < 0 ) continue; 1254 1259 1255 1260 // unification run for side-effects 1256 unify( toType, cand->expr->result, cand->env, need, have, open );1261 unify( toType, fromType, cand->env, need, have, open ); 1257 1262 Cost thisCost = 1258 1263 (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast) 1259 ? conversionCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env )1260 : castCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env );1264 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1265 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1261 1266 1262 1267 // Redefine enum cast 1263 auto argAsEnum = cand->expr->result.as<ast::EnumInstType>();1268 auto argAsEnum = fromType.as<ast::EnumInstType>(); 1264 1269 auto toAsEnum = toType.as<ast::EnumInstType>(); 1265 1270 if ( argAsEnum && toAsEnum && argAsEnum->name != toAsEnum->name ) { … … 1272 1277 PRINT( 1273 1278 std::cerr << "working on cast with result: " << toType << std::endl; 1274 std::cerr << "and expr type: " << cand->expr->result<< std::endl;1279 std::cerr << "and expr type: " << fromType << std::endl; 1275 1280 std::cerr << "env: " << cand->env << std::endl; 1276 1281 ) -
tests/.expect/copyfile.txt
rd1f5054 r960665c 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:07 202313 // Update Count : 512 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 22 22 23 23 try { 24 choose ( argc ) { 25 case 2, 3:24 choose ( argc ) { // terminate if command-line errors 25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens 28 28 case 1: ; // use default files 29 default: 29 default: // wrong number of options 30 30 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 31 31 } // choose … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } //for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/.in/copyfile.txt
rd1f5054 r960665c 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:07 202313 // Update Count : 512 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 22 22 23 23 try { 24 choose ( argc ) { 25 case 2, 3:24 choose ( argc ) { // terminate if command-line errors 25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens 28 28 case 1: ; // use default files 29 default: 29 default: // wrong number of options 30 30 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 31 31 } // choose … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } //for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/Makefile.am
rd1f5054 r960665c 210 210 CFACOMPILE_SYNTAX = ${CFACOMPILETEST} -Wno-unused-variable -Wno-unused-label -c -fsyntax-only -o ${abspath ${@}} 211 211 212 SYNTAX_ONLY_CODE = expression typedefRedef variableDeclarator switch numericConstants identFuncDeclarator \ 213 init1 limits nested-types cast ctrl-flow/labelledExit array quasiKeyword include/stdincludes include/includes builtins/sync warnings/self-assignment concurrency/waitfor/parse 212 SYNTAX_ONLY_CODE = \ 213 array cast expression identFuncDeclarator init1 limits nested-types numericConstants opt-params quasiKeyword switch typedefRedef variableDeclarator \ 214 builtins/sync concurrency/waitfor/parse ctrl-flow/labelledExit include/stdincludes include/includes warnings/self-assignment 215 214 216 ${SYNTAX_ONLY_CODE} : % : %.cfa ${CFACCBIN} 215 217 ${CFACOMPILE_SYNTAX} -
tests/array-collections/dimexpr-match.hfa
rd1f5054 r960665c 15 15 // 16 16 // compiler=gcc -x c # pick one 17 // compiler=$ fa17 // compiler=$cfa 18 18 // 19 19 // test=dimexpr-match-c.cfa # pick one -
tests/concurrency/examples/quickSort.cfa
rd1f5054 r960665c 11 11 // Created On : Wed Dec 6 12:15:52 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Mon Jan 1 12:07:59202414 // Update Count : 1 8813 // Last Modified On : Sat Aug 17 13:59:15 2024 14 // Update Count : 199 15 15 // 16 16 … … 145 145 146 146 if ( size == -1 ) { // generate output ? 147 for () { 148 unsortedfile | size; // read number of elements in the list 149 if ( eof( unsortedfile ) ) break; 150 151 int * values = aalloc( size ); // values to be sorted, too large to put on stack 152 for ( counter; size ) { // read unsorted numbers 153 unsortedfile | values[counter]; 154 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 155 sortedfile | values[counter]; 156 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 147 int * values = 0p; 148 try { 149 for () { 150 unsortedfile | size; // read number of elements in the list 151 values = aalloc( size ); // values to be sorted, too large to put on stack 152 for ( counter; size ) { // read unsorted numbers 153 unsortedfile | values[counter]; 154 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 155 sortedfile | values[counter]; 156 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 157 } // for 158 sortedfile | nl; 159 160 if ( size > 0 ) { // values to sort ? 161 Quicksort QS = { values, size - 1, 0 }; // sort values 162 } // wait until sort tasks terminate 163 for ( counter; size ) { // print sorted list 164 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 165 sortedfile | values[counter]; 166 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 167 } // for 168 sortedfile | nl | nl; 169 170 delete( values ); 171 values = 0p; 157 172 } // for 158 sortedfile | nl; 159 160 if ( size > 0 ) { // values to sort ? 161 Quicksort QS = { values, size - 1, 0 }; // sort values 162 } // wait until sort tasks terminate 163 for ( counter; size ) { // print sorted list 164 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 165 sortedfile | values[counter]; 166 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 167 } // for 168 sortedfile | nl | nl; 169 173 } catch( end_of_file * ) { 170 174 delete( values ); 171 } // for175 } // try 172 176 } else { // timing 173 177 PRNG prng; -
tests/copyfile.cfa
rd1f5054 r960665c 10 10 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 5 21:20:19 202313 // Update Count : 712 // Last Modified On : Sat Aug 17 14:18:47 2024 13 // Update Count : 11 14 14 // 15 15 … … 23 23 try { 24 24 choose ( argc ) { // terminate if command-line errors 25 case 2, 3:25 case 3, 2: 26 26 open( in, argv[1] ); // open input file first as output creates file 27 27 if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens … … 41 41 42 42 char ch; 43 for () { // read all characters 44 in | ch; 45 if ( eof( in ) ) break; // eof ? 46 out | ch; 47 } // for 43 try { 44 for () { // read all characters 45 in | ch; 46 out | ch; 47 } // for 48 } catch( end_of_file * ) { 49 } // try 48 50 } // main 49 50 // Local Variables: //51 // tab-width: 4 //52 // compile-command: "cfa copyfile.cfa" //53 // End: // -
tests/coroutine/.expect/fmtLines.txt
rd1f5054 r960665c 9 9 E" d istr ibut ed w ith 10 10 Cfor all. //// fmt Line 11 s.cc --/ /// Auth or 12 : P eter A. 13 Buhr // C reat ed O n 14 : Su n Se p 17 21: 15 56:1 5 20 17// Las t Mo 16 difi ed B y : Pete r A. 17 Buh r// Last Mod ifie 18 d On : F ri M ar 2 2 13 19 :41: 03 2 019/ / Up date 20 Cou nt : 33/ /#in 21 clud e <f stre am.h fa># 22 incl ude <cor outi ne.h 23 fa>c orou tine For mat 24 { ch ar c h; 25 // used for com muni 26 cati on i nt g , b; 27 / / gl obal bec 28 ause use d in des truc 29 tor} ;voi d ?{ }( F orma 30 t & fmt ) { r esum 31 e( f mt ) ; / 32 / st art coro utin e}vo 33 id ^ ?{}( For mat & fm 34 t ) { if ( fm t.g 35 != 0 || fmt. b != 0 ) 36 sou t | nl;} void mai 37 n( F orma t & fmt ) { 38 for ( ;; ) { 39 // for as many cha 40 ract ers for ( f mt.g 41 = 0 ; fm t.g < 5; fmt 42 .g + = 1 ) { // grou 11 s.cc -- form at c hara 12 cter s in to b lock s of 13 4 a nd g roup s of 5 b 14 lock s pe r li ne// // A 15 utho r : Pe 16 ter A. B uhr/ / Cr eate 17 d On : Sun Sep 18 17 21:5 6:15 201 7// 19 Last Mod ifie d By : P 20 eter A. Buhr // L ast 21 Modi fied On : Sa t Au 22 g 17 14: 26:0 3 20 24// 23 Upd ate Coun t : 24 60// #inc lude <fs trea 25 m.hf a>#i nclu de < coro 26 utin e.hf a>co rout ine 27 Form at { cha r ch ; 28 // u sed for 29 comm unic atio n in t g, 30 b; // glo 31 bal beca use used in 32 dest ruct or}; void mai 33 n( F orma t & fmt ) wi 34 th( fmt ) { for () { 35 / / fo r as 36 man y ch arac ters fo 37 r ( g = 0; g < 5 ; g 38 += 1 ) { // grou 43 39 ps o f 5 bloc ks for 44 ( f mt.b = 0 ; fm t.b 45 < 4; fmt .b + = 1 ) { 46 // b lock s of 4 c hara 47 cter s for ( ; ; ) 48 { // f or n ewli 49 ne c hara cter s su 50 spen d; i f ( fmt. 51 ch ! = '\ n' ) bre ak; 52 // igno re n ewli ne 53 } // f or so ut | 54 fmt .ch; / / pr 55 int char acte r } // 56 for s out | " "; 57 / / pr int bloc 58 k se para tor } / / fo 59 r s out | nl ; 60 // pri nt g roup sep 61 arat or } // for} // 62 main void prt ( Fo rmat 63 & f mt, char ch ) { 64 f mt.c h = ch; r 65 esum e( f mt ) ;} / / pr 66 tint mai n() { Fo rmat 67 fmt ; ch ar c h; f or ( 68 ;; ) { sin | c h; 69 // r ead one 70 char acte r if ( eof 71 ( si n ) ) br eak; 72 / / eo f ? prt ( fm 73 t, c h ); } / / fo r} / 74 / ma in// Loc al V aria 75 bles : // // t ab-w idth 76 : 4 //// com pile -com 77 mand : "c fa f mtLi nes. 78 cfa" /// / En d: / / 40 ( b = 0 ; b < 4; b + 41 = 1 ) { / / bl ocks 42 of 4 ch arac ters 43 for () { // f 44 or n ewli ne c hara cter 45 s su spen d; 46 if ( ch != ' \n' ) br 47 eak; // i gnor e ne 48 wlin e } / / fo r 49 sou t | ch; / 50 / pr int char acte r 51 } // for s out | " 52 "; / / pr int 53 bloc k se para tor } / 54 / fo r s out | nl ; 55 / / pr int grou 56 p se para tor } // for 57 } // mai nvoi d ?{ }( F 58 orma t & fmt ) { resu 59 me( fmt ); 60 // p rime (st art) cor 61 outi ne}v oid ^?{} ( Fo 62 rmat & f mt ) wit h( f 63 mt ) { i f ( g != 0 | 64 | b != 0 ) s out | nl 65 ;}vo id f orma t( F orma 66 t & fmt ) { resu me( 67 fmt );} // f orma tint 68 mai n() { Fo rmat fmt 69 ; so ut | nlO ff; 70 // turn off aut 71 o ne wlin e tr y { for 72 () { / / re 73 ad u ntil end of file 74 s in | fmt .ch; 75 // r ead one char 76 acte r form at( fmt 77 ); // pus h ch 78 arac ter for form atti 79 ng } // for } c atch 80 ( en d_of _fil e * ) { 81 } // try } // mai n -
tests/coroutine/.in/fmtLines.txt
rd1f5054 r960665c 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.cc -- 7 // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:03 201913 // Update Count : 3312 // Last Modified On : Sat Aug 17 14:26:03 2024 13 // Update Count : 60 14 14 // 15 15 … … 22 22 }; 23 23 24 void ?{}( Format & fmt ) { 25 resume( fmt ); // start coroutine 26 } 27 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl; 30 } 31 32 void main( Format & fmt ) { 33 for ( ;; ) { // for as many characters 34 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) { // groups of 5 blocks 35 for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) { // blocks of 4 characters 36 for ( ;; ) { // for newline characters 24 void main( Format & fmt ) with( fmt ) { 25 for () { // for as many characters 26 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 27 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 28 for () { // for newline characters 37 29 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline30 if ( ch != '\n' ) break; // ignore newline 39 31 } // for 40 sout | fmt.ch;// print character32 sout | ch; // print character 41 33 } // for 42 34 sout | " "; // print block separator 43 35 } // for 44 sout | nl; // print group separator36 sout | nl; // print group separator 45 37 } // for 46 38 } // main 47 39 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 40 void ?{}( Format & fmt ) { 41 resume( fmt ); // prime (start) coroutine 42 } 43 44 void ^?{}( Format & fmt ) with( fmt ) { 45 if ( g != 0 || b != 0 ) sout | nl; 46 } 47 48 void format( Format & fmt ) { 49 resume( fmt ); 50 } // format 52 51 53 52 int main() { 54 53 Format fmt; 55 char ch;54 sout | nlOff; // turn off auto newline 56 55 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 56 try { 57 for () { // read until end of file 58 sin | fmt.ch; // read one character 59 format( fmt ); // push character for formatting 60 } // for 61 } catch( end_of_file * ) { 62 } // try 62 63 } // main 63 64 // Local Variables: //65 // tab-width: 4 //66 // compile-command: "cfa fmtLines.cfa" //67 // End: // -
tests/coroutine/cntparens.cfa
rd1f5054 r960665c 10 10 // Created On : Sat Apr 20 11:04:45 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 20 11:06:21 201913 // Update Count : 112 // Last Modified On : Thu Aug 15 20:39:34 2024 13 // Update Count : 2 14 14 // 15 15 … … 46 46 char ch; 47 47 48 for () { // read until end of file 49 sin | ch; // read one character 50 if ( eof( sin ) ) { sout | "Error"; break; } // eof ? 51 Status ret = next( cpns, ch ); // push character for formatting 52 if ( ret == Match ) { sout | "Match"; break; } 53 if ( ret == Error ) { sout | "Error"; break; } 54 } // for 48 try { 49 for () { // read until end of file 50 sin | ch; // read one character 51 Status ret = next( cpns, ch ); // push character for formatting 52 if ( ret == Match ) { sout | "Match"; break; } 53 if ( ret == Error ) { sout | "Error"; break; } 54 } // for 55 } catch( end_of_file * ) { 56 sout | "Error"; 57 } // try 55 58 } // main 56 59 -
tests/coroutine/devicedriver.cfa
rd1f5054 r960665c 10 10 // Created On : Sat Mar 16 15:30:34 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 17 09:11:56 202313 // Update Count : 9 412 // Last Modified On : Thu Aug 15 18:45:45 2024 13 // Update Count : 96 14 14 // 15 15 … … 71 71 72 72 sin | nlOn; // read newline (all) characters 73 eof: for () { // read until end of file 74 sin | byte; // read one character 75 if ( eof( sin ) ) break eof; // eof ? 76 choose( next( driver, byte ) ) { // analyse character 77 case CONT: ; 78 case MSG: sout | "msg:" | msg; 79 case ESTX: sout | "STX in message"; 80 case ELNTH: sout | "message too long"; 81 case ECRC: sout | "CRC failure"; 82 } // choose 83 } // for 73 try { 74 for () { // read until end of file 75 sin | byte; // read one character 76 choose( next( driver, byte ) ) { // analyse character 77 case CONT: ; 78 case MSG: sout | "msg:" | msg; 79 case ESTX: sout | "STX in message"; 80 case ELNTH: sout | "message too long"; 81 case ECRC: sout | "CRC failure"; 82 } // choose 83 } // for 84 } catch( end_of_file * ) { 85 } // try 84 86 } // main 85 87 -
tests/coroutine/fmtLines.cfa
rd1f5054 r960665c 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:16 201913 // Update Count : 5812 // Last Modified On : Sat Aug 17 14:26:03 2024 13 // Update Count : 60 14 14 // 15 15 … … 54 54 sout | nlOff; // turn off auto newline 55 55 56 eof: for () { // read until end of file 57 sin | fmt.ch; // read one character 58 if ( eof( sin ) ) break eof; // eof ? 59 format( fmt ); // push character for formatting 60 } // for 56 try { 57 for () { // read until end of file 58 sin | fmt.ch; // read one character 59 format( fmt ); // push character for formatting 60 } // for 61 } catch( end_of_file * ) { 62 } // try 61 63 } // main 62 63 // Local Variables: //64 // tab-width: 4 //65 // compile-command: "cfa fmtLines.cfa" //66 // End: // -
tests/enum_tests/input.cfa
rd1f5054 r960665c 6 6 E e; 7 7 8 for () { 9 try { 10 sin | e; 11 } catch( missing_data * ) { 12 sout | "missing data"; 13 continue; // try again 14 } // try 15 if ( eof( sin ) ) break; 16 sout | e | "= " | value( e ); 17 } // for 18 } 8 try { 9 for () { 10 try { 11 sin | e; 12 } catch( missing_data * ) { 13 sout | "missing data"; 14 continue; // try again 15 } // try 16 sout | e | "= " | value( e ); 17 } // for 18 } catch( end_of_file * ) { 19 } // try 20 } // main -
tests/generator/.expect/fmtLines.txt
rd1f5054 r960665c 9 9 E" d istr ibut ed w ith 10 10 Cfor all. //// fmt Line 11 s.cc --/ /// Auth or 12 : P eter A. 13 Buhr // C reat ed O n 14 : Su n Se p 17 21: 15 56:1 5 20 17// Las t Mo 16 difi ed B y : Pete r A. 17 Buh r// Last Mod ifie 18 d On : F ri M ar 2 2 13 19 :41: 03 2 019/ / Up date 20 Cou nt : 33/ /#in 21 clud e <f stre am.h fa># 22 incl ude <cor outi ne.h 23 fa>c orou tine For mat 24 { ch ar c h; 25 // used for com muni 26 cati on i nt g , b; 27 / / gl obal bec 28 ause use d in des truc 29 tor} ;voi d ?{ }( F orma 30 t & fmt ) { r esum 31 e( f mt ) ; / 32 / st art coro utin e}vo 33 id ^ ?{}( For mat & fm 34 t ) { if ( fm t.g 35 != 0 || fmt. b != 0 ) 36 sou t | nl;} void mai 37 n( F orma t & fmt ) { 38 for ( ;; ) { 39 // for as many cha 40 ract ers for ( f mt.g 41 = 0 ; fm t.g < 5; fmt 42 .g + = 1 ) { // grou 43 ps o f 5 bloc ks for 44 ( f mt.b = 0 ; fm t.b 45 < 4; fmt .b + = 1 ) { 46 // b lock s of 4 c hara 47 cter s for ( ; ; ) 48 { // f or n ewli 49 ne c hara cter s su 50 spen d; i f ( fmt. 51 ch ! = '\ n' ) bre ak; 52 // igno re n ewli ne 53 } // f or so ut | 54 fmt .ch; / / pr 55 int char acte r } // 56 for s out | " "; 57 / / pr int bloc 58 k se para tor } / / fo 59 r s out | nl ; 60 // pri nt g roup sep 61 arat or } // for} // 62 main void prt ( Fo rmat 63 & f mt, char ch ) { 64 f mt.c h = ch; r 65 esum e( f mt ) ;} / / pr 66 tint mai n() { Fo rmat 67 fmt ; ch ar c h; f or ( 68 ;; ) { sin | c h; 69 // r ead one 70 char acte r if ( eof 71 ( si n ) ) br eak; 72 / / eo f ? prt ( fm 73 t, c h ); } / / fo r} / 74 / ma in// Loc al V aria 75 bles : // // t ab-w idth 76 : 4 //// com pile -com 77 mand : "c fa f mtLi nes. 78 cfa" /// / En d: / / 11 s.cf a -- for mat char 12 acte rs i nto bloc ks o 13 f 4 and grou ps o f 5 14 bloc ks p er l ine/ /// 15 Auth or : T 16 hier ry D elis le// Cre 17 ated On : Thu 18 Mar 5 1 6:09 :08 2020 19 // L ast Modi fied By 20 : Pe ter A. B uhr/ / La 21 st M odif ied On : Sat 22 Aug 17 14:2 1:28 202 23 4// Upda te C ount 24 : 5 //#i nclu de < fstr 25 eam. hfa> gene rato r Fo 26 rmat { c har ch; 27 // use d fo r co 28 mmun icat ion int g, b 29 ; // g loba 30 l be caus e us ed i n de 31 stru ctor };vo id m ain( 32 For mat & fm t ) with 33 ( fm t ) { fo r () { 34 // for as m 35 any char acte rs for 36 ( g = 0; g < 5; g += 37 1 ) { / / gr oups 38 of 5 bl ocks f or ( 39 b = 0; b < 4; b += 40 1 ) { // bloc ks o 41 f 4 char acte rs fo 42 r () { // for 43 new line cha ract ers 44 susp end; if 45 ( c h != '\n ' ) brea 46 k; // ign ore newl 47 ine } // for s 48 out | ch ; // 49 prin t ch arac ter } 50 // f or sou t | " " 51 ; // prin t bl 52 ock sepa rato r } // 53 for sou t | nl; 54 // prin t gr oup 55 sepa rato r } // f or} 56 // m ainv oid ?{}( For 57 mat & fm t ) { re sume 58 ( fm t ); // 59 pri me ( star t) c orou 60 tine }voi d ^? {}( Form 61 at & fmt ) w ith( fmt 62 ) { if ( g != 0 || 63 b != 0 ) sou t | nl;} 64 void for mat( For mat 65 & fm t ) { re sume ( fm 66 t ); } // for mati nt m 67 ain( ) { Form at f mt; 68 sout | n lOff ; 69 / / tu rn o ff a uto 70 newl ine try { f or ( 71 ) { // read 72 unt il e nd o f fi le 73 sin | f mt.c h; 74 // rea d on e ch arac 75 ter fo rmat ( fm t ); 76 // p ush char 77 acte r fo r fo rmat ting 78 } // f or } cat ch( 79 end_ of_f ile * ) { } 80 // t ry} // m ain -
tests/generator/.in/fmtLines.txt
rd1f5054 r960665c 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.c c --7 // fmtLines.cfa -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 // Author : Peter A. Buhr10 // Created On : Sun Sep 17 21:56:15 20179 // Author : Thierry Delisle 10 // Created On : Thu Mar 5 16:09:08 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:03 201913 // Update Count : 3312 // Last Modified On : Sat Aug 17 14:21:28 2024 13 // Update Count : 5 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <coroutine.hfa>18 17 19 coroutineFormat {18 generator Format { 20 19 char ch; // used for communication 21 20 int g, b; // global because used in destructor 22 21 }; 23 22 24 void ?{}( Format & fmt ) { 25 resume( fmt ); // start coroutine 26 } 27 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl; 30 } 31 32 void main( Format & fmt ) { 33 for ( ;; ) { // for as many characters 34 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) { // groups of 5 blocks 35 for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) { // blocks of 4 characters 36 for ( ;; ) { // for newline characters 23 void main( Format & fmt ) with( fmt ) { 24 for () { // for as many characters 25 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 26 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 27 for () { // for newline characters 37 28 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline29 if ( ch != '\n' ) break; // ignore newline 39 30 } // for 40 sout | fmt.ch;// print character31 sout | ch; // print character 41 32 } // for 42 33 sout | " "; // print block separator 43 34 } // for 44 sout | nl; // print group separator35 sout | nl; // print group separator 45 36 } // for 46 37 } // main 47 38 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 39 void ?{}( Format & fmt ) { 40 resume( fmt ); // prime (start) coroutine 41 } 42 43 void ^?{}( Format & fmt ) with( fmt ) { 44 if ( g != 0 || b != 0 ) sout | nl; 45 } 46 47 void format( Format & fmt ) { 48 resume( fmt ); 49 } // format 52 50 53 51 int main() { 54 52 Format fmt; 55 char ch;53 sout | nlOff; // turn off auto newline 56 54 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 55 try { 56 for () { // read until end of file 57 sin | fmt.ch; // read one character 58 format( fmt ); // push character for formatting 59 } // for 60 } catch( end_of_file * ) { 61 } // try 62 62 } // main 63 64 // Local Variables: //65 // tab-width: 4 //66 // compile-command: "cfa fmtLines.cfa" //67 // End: // -
tests/generator/fmtLines.cfa
rd1f5054 r960665c 10 10 // Created On : Thu Mar 5 16:09:08 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 10 21:56:22 202113 // Update Count : 212 // Last Modified On : Sat Aug 17 14:21:28 2024 13 // Update Count : 5 14 14 // 15 15 … … 53 53 sout | nlOff; // turn off auto newline 54 54 55 eof: for () { // read until end of file 56 sin | fmt.ch; // read one character 57 if ( eof( sin ) ) break eof; // eof ? 58 format( fmt ); // push character for formatting 59 } // for 55 try { 56 for () { // read until end of file 57 sin | fmt.ch; // read one character 58 format( fmt ); // push character for formatting 59 } // for 60 } catch( end_of_file * ) { 61 } // try 60 62 } // main 61 62 // Local Variables: //63 // tab-width: 4 //64 // compile-command: "cfa fmtLines.cfa" //65 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.