Changeset 86f384b
- Timestamp:
- Jul 2, 2017, 10:49:41 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 307a732
- Parents:
- d395012
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
rd395012 r86f384b 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : S at Jul 1 17:19:42201714 %% Update Count : 2 49513 %% Last Modified On : Sun Jul 2 09:49:56 2017 14 %% Update Count : 2503 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 2433 2433 2434 2434 The goal of \CFA I/O is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way. 2435 The approach combines ideas from \CC and Python. 2435 2436 The \CFA header file for the I/O library is \Indexc{fstream}. 2436 2437 … … 2458 2459 \end{tabular} 2459 2460 \end{quote2} 2460 The \CFA form has half as many characters asthe \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.2461 Similar simplification occurs for \Index{tuple} I/O, which prints all a tuple's values, eachseparated by ``\lstinline[showspaces=true]@, @''.2461 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators. 2462 Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''. 2462 2463 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2463 [int, int] t1 = [1, 2], t2 = [3, 4];2464 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 2464 2465 sout | t1 | t2 | endl; §\C{// print tuples}§ 2465 2466 \end{cfa} 2466 2467 \begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt] 2467 1®, ®2®, ®3 ®, ®42468 \end{cfa} 2469 Finally, \CFA uses the logical-or operator for I/O becauseit is the lowest-priority overloadable operator, other than assignment.2468 1®, ®2®, ®3 3®, ®4®, ®5 2469 \end{cfa} 2470 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment. 2470 2471 Therefore, fewer output expressions require parenthesis. 2471 2472 \begin{quote2} … … 2660 2661 int x = 1, y = 2, z = 3; 2661 2662 sout | x | y | z | endl; 2662 [int, int] t1 = [1, 2], t2 = [3, 4];2663 sout | t1 | t2 | endl; // print tuple 2663 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 2664 sout | t1 | t2 | endl; // print tuples 2664 2665 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 2665 2666 sout | 1 | 2 | 3 | endl; -
src/libcfa/iostream
rd395012 r86f384b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 1 16:37:52201713 // Update Count : 1 0812 // Last Modified On : Sun Jul 2 08:42:56 2017 13 // Update Count : 110 14 14 // 15 15 … … 26 26 const char * sepGetCur( ostype * ); // get current separator string 27 27 void sepSetCur( ostype *, const char * ); // set current separator string 28 _Bool lastSepOn( ostype * ); // last manipulator is setOn (context sensitive) 28 29 // public 29 30 void sepOn( ostype * ); // turn separator state on … … 31 32 _Bool sepDisable( ostype * ); // set default state to off, and return previous state 32 33 _Bool sepEnable( ostype * ); // set default state to on, and return previous state 33 _Bool lastSepOn( ostype * ); // last manipulator is setOn (context sensitive)34 34 35 35 const char * sepGet( ostype * ); // get separator string … … 44 44 ostype * write( ostype *, const char *, unsigned long int ); 45 45 int fmt( ostype *, const char fmt[], ... ); 46 }; 46 }; // ostream 47 47 48 48 trait writeable( otype T ) { 49 49 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 50 }; 50 }; // writeable 51 51 52 52 // implement writable for intrinsic types … … 104 104 istype * ungetc( istype *, char ); 105 105 int fmt( istype *, const char fmt[], ... ); 106 }; 106 }; // istream 107 107 108 108 trait readable( otype T ) { 109 109 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T ); 110 }; 110 }; // readable 111 111 112 112 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * ); -
src/libcfa/iostream.c
rd395012 r86f384b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 1 16:37:51201713 // Update Count : 37 412 // Last Modified On : Sun Jul 2 08:54:02 2017 13 // Update Count : 375 14 14 // 15 15 … … 201 201 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) 202 202 ostype * ?|?( ostype * os, T arg, Params rest ) { 203 os | arg; // print first argument 203 204 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 204 os | arg; // print first argument205 205 os | rest; // print remaining arguments 206 206 sepSetCur( os, sepGet( os ) ); // switch to regular separator -
src/tests/.expect/io.txt
rd395012 r86f384b 4 4 123 5 5 6 opening delimiters 6 7 x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10 8 9 closing delimiters 7 10 1, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x 11 12 opening/closing delimiters 8 13 x`1`x'2'x"3"x:4:x 5 x 6 x 9 14 7 … … 15 20 10 16 21 x 22 23 override opening/closing delimiters 17 24 x ( 1 ) x 2 , x 3 :x: 4 25 26 input bacis types 27 28 output basic types 18 29 A 19 30 1 2 3 4 5 6 7 8 … … 21 32 1.1+2.3i 1.1-2.3i 1.1-2.3i 22 33 34 tuples 35 1, 2, 3 3, 4, 5 36 37 toggle separator 23 38 1.11.21.3 24 39 1.1+2.3i1.1-2.3i1.1-2.3i … … 26 41 abcxyz 27 42 43 change separator 44 from " "to " , $" 28 45 1.1, $1.2, $1.3 29 46 1.1+2.3i, $1.1-2.3i, $1.1-2.3i 30 47 abc, $xyz, $ 48 1, 2, 3, $3, 4, 5 31 49 32 1, 2, 3, 4 33 34 1, $2, $3 ", $" 35 1 2 3 " " 50 from ", $"to " " 51 1.1 1.2 1.3 52 1.1+2.3i 1.1-2.3i 1.1-2.3i 53 abc xyz 54 1, 2, 3 3, 4, 5 36 55 37 56 1 2 3 … … 49 68 1 2 3 50 69 51 1 2 3 4" "52 1, 2, 3 , 4", "53 1, 2, 3 , 470 1 2 3 3 4 5 " " 71 1, 2, 3 3, 4, 5 ", " 72 1, 2, 3 3, 4, 5 54 73 55 74 3, 4, a, 7.2 … … 57 76 3 4 a 7.2 58 77 3 4 a 7.234a7.23 4 a 7.2 59 3-4-a-7.2^3^4 -3-4-a-7.278 3-4-a-7.2^3^4^3-4-a-7.2 -
src/tests/io.c
rd395012 r86f384b 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 1 16:21:07201713 // Update Count : 5812 // Last Modified On : Sun Jul 2 09:40:58 2017 13 // Update Count : 68 14 14 // 15 15 … … 42 42 sout | endl; 43 43 44 sout | "opening delimiters" | endl; 44 45 sout 45 // opening delimiters46 46 | "x (" | 1 47 47 | "x [" | 2 … … 54 54 | "x ¿" | 9 55 55 | "x «" | 10 56 | endl; 56 | endl | endl; 57 58 sout | "closing delimiters" | endl; 57 59 sout 58 // closing delimiters59 60 | 1 | ", x" 60 61 | 2 | ". x" … … 68 69 | 10 | "] x" 69 70 | 11 | "} x" 70 | endl; 71 | endl | endl; 72 73 sout | "opening/closing delimiters" | endl; 71 74 sout 72 // opening-closing delimiters73 75 | "x`" | 1 | "`x'" | 2 74 76 | "'x\"" | 3 | "\"x:" | 4 … … 76 78 | "\tx\f" | 7 | "\fx\v" | 8 77 79 | "\vx\n" | 9 | "\nx\r" | 10 78 | "\rx" | 79 endl; 80 | "\rx" 81 | endl | endl; 82 83 sout | "override opening/closing delimiters" | endl; 80 84 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; 85 sout | endl; 81 86 82 87 ifstream in; // create / open file 83 88 open( &in, "io.data", "r" ); 84 89 90 sout | "input bacis types" | endl; 85 91 &in | &c // character 86 92 | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli // integral … … 88 94 | &fc | &dc | &ldc // floating-point complex 89 95 | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked 96 sout | endl; 90 97 98 sout | "output basic types" | endl; 91 99 sout | c | ' ' | endl // character 92 100 | si | usi | i | ui | li | uli | lli | ulli | endl // integral … … 94 102 | fc | dc | ldc | endl; // complex 95 103 sout | endl; 104 105 sout | "tuples" | endl; 106 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 107 sout | t1 | t2 | endl; // print tuple 108 sout | endl; 109 110 sout | "toggle separator" | endl; 96 111 sout | f | "" | d | "" | ld | endl // floating point without separator 97 112 | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator … … 100 115 sout | endl; 101 116 117 sout | "change separator" | endl; 118 sout | "from \" " | sepGet( sout ) | "\""; 102 119 sepSet( sout, ", $" ); // change separator, maximum of 15 characters 120 sout | "to \" " | sepGet( sout ) | "\"" | endl; 103 121 sout | f | d | ld | endl 104 122 | fc | dc | ldc | endl 105 | s1 | s2 | endl; 123 | s1 | s2 | endl 124 | t1 | t2 | endl; // print tuple 106 125 sout | endl; 107 108 [int, int] t1 = [1, 2], t2 = [3, 4]; 109 sout | t1 | t2 | endl; // print tuple 110 sout | endl; 111 112 sepSet( sout, " " ); 113 sepSet( sout, ", $" ); // set separator from " " to ", $" 114 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 115 sepSet( sout, " " ); // reset separator to " " 116 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 126 sout | "from \"" | sepGet( sout ) | "\""; 127 sepSet( sout, " " ); // restore separator 128 sout | "to \"" | sepGet( sout ) | "\"" | endl; 129 sout | f | d | ld | endl 130 | fc | dc | ldc | endl 131 | s1 | s2 | endl 132 | t1 | t2 | endl; // print tuple 117 133 sout | endl; 118 134
Note: See TracChangeset
for help on using the changeset viewer.