Changes in / [85acec94:90cfc16]
- Files:
-
- 87 edited
-
benchmark/Makefile.in (modified) (1 diff)
-
benchmark/Monitor.c (modified) (1 diff)
-
doc/papers/concurrency/Paper.tex (modified) (14 diffs)
-
doc/proposals/flags.md (modified) (2 diffs)
-
doc/user/user.tex (modified) (41 diffs)
-
examples/ArrayN.c (modified) (2 diffs)
-
examples/gc_no_raii/src/internal/collector.c (modified) (1 diff)
-
examples/gc_no_raii/src/internal/state.h (modified) (1 diff)
-
examples/gc_no_raii/src/tools/print.h (modified) (1 diff)
-
examples/multicore.c (modified) (2 diffs)
-
examples/prolog.c (modified) (1 diff)
-
examples/quad.c (modified) (2 diffs)
-
examples/square.c (modified) (4 diffs)
-
examples/twice.c (modified) (2 diffs)
-
examples/wrapper/src/main.c (modified) (1 diff)
-
examples/wrapper/src/pointer.h (modified) (7 diffs)
-
examples/zero_one.c (modified) (1 diff)
-
libcfa/src/fstream.cfa (modified) (7 diffs)
-
libcfa/src/fstream.hfa (modified) (4 diffs)
-
libcfa/src/gmp.hfa (modified) (2 diffs)
-
libcfa/src/iostream.cfa (modified) (20 diffs)
-
libcfa/src/iostream.hfa (modified) (7 diffs)
-
libcfa/src/rational.cfa (modified) (3 diffs)
-
libcfa/src/rational.hfa (modified) (2 diffs)
-
libcfa/src/time.cfa (modified) (3 diffs)
-
tests/abs.cfa (modified) (2 diffs)
-
tests/ato.cfa (modified) (2 diffs)
-
tests/complex.cfa (modified) (3 diffs)
-
tests/concurrent/coroutineYield.c (modified) (2 diffs)
-
tests/concurrent/examples/boundedBufferEXT.c (modified) (2 diffs)
-
tests/concurrent/examples/boundedBufferINT.c (modified) (2 diffs)
-
tests/concurrent/examples/datingService.c (modified) (4 diffs)
-
tests/concurrent/examples/matrixSum.c (modified) (2 diffs)
-
tests/concurrent/examples/quickSort.c (modified) (6 diffs)
-
tests/concurrent/monitor.c (modified) (1 diff)
-
tests/concurrent/multi-monitor.c (modified) (1 diff)
-
tests/concurrent/signal/block.c (modified) (4 diffs)
-
tests/concurrent/signal/disjoint.c (modified) (3 diffs)
-
tests/concurrent/signal/wait.c (modified) (3 diffs)
-
tests/concurrent/thread.c (modified) (4 diffs)
-
tests/concurrent/waitfor/barge.c (modified) (4 diffs)
-
tests/concurrent/waitfor/dtor.c (modified) (3 diffs)
-
tests/concurrent/waitfor/else.c (modified) (1 diff)
-
tests/concurrent/waitfor/recurse.c (modified) (4 diffs)
-
tests/concurrent/waitfor/simple.c (modified) (5 diffs)
-
tests/concurrent/waitfor/statment.c (modified) (3 diffs)
-
tests/concurrent/waitfor/when.c (modified) (3 diffs)
-
tests/coroutine/.expect/fmtLines.txt (modified) (2 diffs)
-
tests/coroutine/.in/fmtLines.txt (modified) (3 diffs)
-
tests/coroutine/fibonacci.c (modified) (2 diffs)
-
tests/coroutine/fibonacci_1.c (modified) (2 diffs)
-
tests/coroutine/fmtLines.c (modified) (4 diffs)
-
tests/coroutine/pingpong.c (modified) (2 diffs)
-
tests/coroutine/prodcons.c (modified) (4 diffs)
-
tests/coroutine/runningTotal.c (modified) (2 diffs)
-
tests/div.cfa (modified) (2 diffs)
-
tests/except-0.cfa (modified) (1 diff)
-
tests/fallthrough.cfa (modified) (4 diffs)
-
tests/fstream_test.cfa (modified) (2 diffs)
-
tests/function-operator.cfa (modified) (2 diffs)
-
tests/gmp.cfa (modified) (2 diffs)
-
tests/heap.cfa (modified) (10 diffs)
-
tests/hello.cfa (modified) (2 diffs)
-
tests/identity.cfa (modified) (2 diffs)
-
tests/ifwhileCtl.cfa (modified) (3 diffs)
-
tests/io1.cfa (modified) (5 diffs)
-
tests/io2.cfa (modified) (3 diffs)
-
tests/literals.cfa (modified) (2 diffs)
-
tests/loopctrl.cfa (modified) (2 diffs)
-
tests/math1.cfa (modified) (2 diffs)
-
tests/math2.cfa (modified) (2 diffs)
-
tests/math3.cfa (modified) (2 diffs)
-
tests/math4.cfa (modified) (2 diffs)
-
tests/minmax.cfa (modified) (2 diffs)
-
tests/quotedKeyword.cfa (modified) (2 diffs)
-
tests/raii/dtor-early-exit.c (modified) (16 diffs)
-
tests/raii/globals.c (modified) (1 diff)
-
tests/random.cfa (modified) (2 diffs)
-
tests/rational.cfa (modified) (2 diffs)
-
tests/searchsort.cfa (modified) (13 diffs)
-
tests/shortCircuit.cfa (modified) (3 diffs)
-
tests/sum.cfa (modified) (8 diffs)
-
tests/swap.cfa (modified) (2 diffs)
-
tests/time.cfa (modified) (2 diffs)
-
tests/tuple/tupleAssign.c (modified) (4 diffs)
-
tests/userLiterals.cfa (modified) (3 diffs)
-
tests/vector.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/Makefile.in
r85acec94 r90cfc16 724 724 725 725 compile-attributes$(EXEEXT): 726 @$(CFACOMPILE) -fsyntax-only -w $(testdir)/attributes.c fa726 @$(CFACOMPILE) -fsyntax-only -w $(testdir)/attributes.c 727 727 728 728 compile-empty$(EXEEXT): -
benchmark/Monitor.c
r85acec94 r90cfc16 29 29 EndTime = Time(); 30 30 31 sout | ( EndTime - StartTime ) / N ;31 sout | ( EndTime - StartTime ) / N | endl; 32 32 } -
doc/papers/concurrency/Paper.tex
r85acec94 r90cfc16 686 686 Fib f1, f2; 687 687 for ( int i = 1; i <= 10; i += 1 ) { 688 sout | next( f1 ) | next( f2 ) ;688 sout | next( f1 ) | next( f2 ) | endl; 689 689 } 690 690 } … … 772 772 sout | " "; // separator 773 773 } 774 sout | nl;774 sout | endl; 775 775 } 776 776 } 777 777 void ?{}( Format & fmt ) { `resume( fmt );` } 778 778 void ^?{}( Format & fmt ) with( fmt ) { 779 if ( g != 0 || b != 0 ) sout | nl;779 if ( g != 0 || b != 0 ) sout | endl; 780 780 } 781 781 void format( Format & fmt ) { … … 855 855 for ( int i = 0; i < N; i += 1 ) { 856 856 int p1 = random( 100 ), p2 = random( 100 ); 857 sout | p1 | " " | p2 ;857 sout | p1 | " " | p2 | endl; 858 858 int status = delivery( c, p1, p2 ); 859 sout | " $" | money | nl | status;859 sout | " $" | money | endl | status | endl; 860 860 receipt += 1; 861 861 } 862 862 stop( c ); 863 sout | "prod stops" ;863 sout | "prod stops" | endl; 864 864 } 865 865 int payment( Prod & prod, int money ) { … … 895 895 int money = 1, receipt; 896 896 for ( ; ! done; ) { 897 sout | p1 | " " | p2 | nl | " $" | money;897 sout | p1 | " " | p2 | endl | " $" | money | endl; 898 898 status += 1; 899 899 receipt = payment( p, money ); 900 sout | " #" | receipt ;900 sout | " #" | receipt | endl; 901 901 money += 1; 902 902 } 903 sout | "cons stops" ;903 sout | "cons stops" | endl; 904 904 } 905 905 int delivery( Cons & cons, int p1, int p2 ) { … … 1099 1099 1100 1100 void main(foo & this) { 1101 sout | "Hello World!" ;1101 sout | "Hello World!" | endl; 1102 1102 } 1103 1103 \end{cfa} … … 1124 1124 1125 1125 void hello(/*unused*/ int) { 1126 sout | "Hello World!" ;1126 sout | "Hello World!" | endl; 1127 1127 } 1128 1128 … … 1141 1141 thread World {}; 1142 1142 void main( World & this ) { 1143 sout | "World!" ;1143 sout | "World!" | endl; 1144 1144 } 1145 1145 int main() { 1146 1146 World w`[10]`; $\C{// implicit forks after creation}$ 1147 sout | "Hello " ; $\C{// "Hello " and 10 "World!" printed concurrently}$1147 sout | "Hello " | endl; $\C{// "Hello " and 10 "World!" printed concurrently}$ 1148 1148 } $\C{// implicit joins before destruction}$ 1149 1149 \end{cfa} … … 1193 1193 total += subtotals[r]; $\C{// total subtotal}$ 1194 1194 } 1195 sout | total ;1195 sout | total | endl; 1196 1196 } 1197 1197 \end{cfa} … … 2192 2192 BENCH( 2193 2193 for ( size_t i = 0; i < N; i += 1 ) { @resume( c );@ } ) 2194 sout | result`ns ;2194 sout | result`ns | endl; 2195 2195 } 2196 2196 \end{cfa} … … 2205 2205 BENCH( 2206 2206 for ( size_t i = 0; i < N; i += 1 ) { @yield();@ } ) 2207 sout | result`ns ;2207 sout | result`ns | endl; 2208 2208 } 2209 2209 \end{cfa} … … 2244 2244 int main() { 2245 2245 BENCH( for( size_t i = 0; i < N; i += 1 ) { @do_call( m1/*, m2, m3, m4*/ );@ } ) 2246 sout | result`ns ;2246 sout | result`ns | endl; 2247 2247 } 2248 2248 \end{cfa} … … 2305 2305 BENCH( for ( size_t i = 0; i < N; i += 1 ) { @wait( c );@ } ); 2306 2306 go = 0; // stop other thread 2307 sout | result`ns ;2307 sout | result`ns | endl; 2308 2308 } 2309 2309 int main() { … … 2356 2356 BENCH( for ( size_t i = 0; i < N; i += 1 ) { @waitfor( do_call, m );@ } ) 2357 2357 go = 0; // stop other thread 2358 sout | result`ns ;2358 sout | result`ns | endl; 2359 2359 } 2360 2360 int main() { … … 2391 2391 int main() { 2392 2392 BENCH( for ( size_t i = 0; i < N; i += 1 ) { @MyThread m;@ } ) 2393 sout | result`ns ;2393 sout | result`ns | endl; 2394 2394 } 2395 2395 \end{cfa} -
doc/proposals/flags.md
r85acec94 r90cfc16 60 60 ``` 61 61 FunFlags f = some_val(); 62 if ( f ) { sout | "f has some flag(s) set" ; }63 if ( f & FOO ) { sout | "f has FOO set" ; }62 if ( f ) { sout | "f has some flag(s) set" | endl; } 63 if ( f & FOO ) { sout | "f has FOO set" | endl; } 64 64 f |= FOO; // set FOO 65 65 f -= FOO; // unset FOO … … 88 88 ``` 89 89 FunFlags f = some_val(); 90 if ( f.FOO ) { sout | "f has FOO set" ; }90 if ( f.FOO ) { sout | "f has FOO set" | endl; } 91 91 f.FOO = true; // set FOO 92 92 f.FOO = false; // unset FOO -
doc/user/user.tex
r85acec94 r90cfc16 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Tue Dec 11 23:19:26201814 %% Update Count : 3 40013 %% Last Modified On : Wed Nov 7 17:00:49 2018 14 %% Update Count : 3399 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 178 178 int main( void ) { 179 179 int x = 0, y = 1, z = 2; 180 ®sout | x | y | z ;®§\indexc{sout}§180 ®sout | x | y | z | endl;®§\indexc{sout}§ 181 181 } 182 182 \end{cfa} … … 513 513 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative. 514 514 \begin{cfa} 515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) ;515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl; 516 516 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i 517 517 \end{cfa} … … 591 591 & 592 592 \begin{cfa} 593 sout | nl;594 sout | nl;595 sout | nl;596 sout | "zero" | nl;597 sout | nl;598 sout | nl;599 sout | nl;600 sout | nl;601 sout | nl;602 sout | nl;603 sout | nl;604 sout | nl;605 sout | nl;606 sout | nl;607 sout | nl;608 sout | nl;609 sout | nl | nl;610 611 sout | nl;612 sout | nl;613 sout | nl | nl;614 615 sout | nl;593 sout | endl; 594 sout | endl; 595 sout | endl; 596 sout | "zero" | endl; 597 sout | endl; 598 sout | endl; 599 sout | endl; 600 sout | endl; 601 sout | endl; 602 sout | endl; 603 sout | endl; 604 sout | endl; 605 sout | endl; 606 sout | endl; 607 sout | endl; 608 sout | endl; 609 sout | endl | endl; 610 611 sout | endl; 612 sout | endl; 613 sout | endl | endl; 614 615 sout | endl; 616 616 \end{cfa} 617 617 & … … 2459 2459 int bar( int p ) { 2460 2460 ®i® += 1; §\C{// dependent on local variable}§ 2461 sout | ®i® ;2461 sout | ®i® | endl; 2462 2462 } 2463 2463 return bar; §\C{// undefined because of local dependence}§ … … 2465 2465 int main() { 2466 2466 * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§ 2467 sout | fp( 3 ) ;2467 sout | fp( 3 ) | endl; 2468 2468 } 2469 2469 \end{cfa} … … 3231 3231 \begin{cfa} 3232 3232 int x = 1, y = 2, z = 3; 3233 sout | x ®|® y ®|® z ;3233 sout | x ®|® y ®|® z | endl; 3234 3234 \end{cfa} 3235 3235 & … … 3252 3252 \begin{cfa} 3253 3253 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3254 sout | t1 | t2 ;§\C{// print tuples}§3254 sout | t1 | t2 | endl; §\C{// print tuples}§ 3255 3255 \end{cfa} 3256 3256 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3264 3264 & 3265 3265 \begin{cfa} 3266 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) ;3266 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 3267 3267 \end{cfa} 3268 3268 \\ … … 3290 3290 A separator does not appear at the start or end of a line. 3291 3291 \begin{cfa}[belowskip=0pt] 3292 sout | 1 | 2 | 3 ;3292 sout | 1 | 2 | 3 | endl; 3293 3293 \end{cfa} 3294 3294 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3299 3299 A separator does not appear before or after a character literal or variable. 3300 3300 \begin{cfa} 3301 sout | '1' | '2' | '3' ;3301 sout | '1' | '2' | '3' | endl; 3302 3302 123 3303 3303 \end{cfa} … … 3306 3306 A separator does not appear before or after a null (empty) C string. 3307 3307 \begin{cfa} 3308 sout | 1 | "" | 2 | "" | 3 ;3308 sout | 1 | "" | 2 | "" | 3 | endl; 3309 3309 123 3310 3310 \end{cfa} … … 3316 3316 \begin{cfa}[mathescape=off] 3317 3317 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3318 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 ;3318 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl; 3319 3319 \end{cfa} 3320 3320 %$ … … 3330 3330 \begin{cfa}[belowskip=0pt] 3331 3331 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 3332 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" ;3332 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl; 3333 3333 \end{cfa} 3334 3334 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3340 3340 A seperator does not appear before or after a C string begining/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@ 3341 3341 \begin{cfa}[belowskip=0pt] 3342 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" ;3342 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl; 3343 3343 \end{cfa} 3344 3344 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3349 3349 If a space is desired before or after one of the special string start/end characters, simply insert a space. 3350 3350 \begin{cfa}[belowskip=0pt] 3351 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 ;3351 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 | endl; 3352 3352 \end{cfa} 3353 3353 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3366 3366 \begin{cfa}[mathescape=off,belowskip=0pt] 3367 3367 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 3368 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" ;3368 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl; 3369 3369 \end{cfa} 3370 3370 %$ … … 3375 3375 \begin{cfa}[belowskip=0pt] 3376 3376 sepSet( sout, " " ); §\C{// reset separator to " "}§ 3377 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" ;3377 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 3378 3378 \end{cfa} 3379 3379 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3385 3385 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§ 3386 3386 sepSet( sout, "_" ); §\C{// change separator to underscore}§ 3387 sout | 1 | 2 | 3 ;3387 sout | 1 | 2 | 3 | endl; 3388 3388 \end{cfa} 3389 3389 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3392 3392 \begin{cfa}[belowskip=0pt] 3393 3393 sepSet( sout, store ); §\C{// change separator back to original}§ 3394 sout | 1 | 2 | 3 ;3394 sout | 1 | 2 | 3 | endl; 3395 3395 \end{cfa} 3396 3396 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3403 3403 \begin{cfa}[belowskip=0pt] 3404 3404 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 3405 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" ;3405 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl; 3406 3406 \end{cfa} 3407 3407 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3410 3410 \begin{cfa}[belowskip=0pt] 3411 3411 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 3412 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" ;3412 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 3413 3413 \end{cfa} 3414 3414 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3420 3420 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items. 3421 3421 \begin{cfa}[belowskip=0pt] 3422 sout | sepDisable | 1 | 2 | 3 ;§\C{// globally turn off implicit separator}§3422 sout | sepDisable | 1 | 2 | 3 | endl; §\C{// globally turn off implicit separator}§ 3423 3423 \end{cfa} 3424 3424 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3426 3426 \end{cfa} 3427 3427 \begin{cfa}[belowskip=0pt] 3428 sout | sepEnable | 1 | 2 | 3 ; §\C{// globally turn on implicit separator}§3428 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separator}§ 3429 3429 \end{cfa} 3430 3430 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3435 3435 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item. 3436 3436 \begin{cfa}[belowskip=0pt] 3437 sout | 1 | sepOff | 2 | 3 ; §\C{// locally turn off implicit separator}§3437 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§ 3438 3438 \end{cfa} 3439 3439 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3441 3441 \end{cfa} 3442 3442 \begin{cfa}[belowskip=0pt] 3443 sout | sepDisable | 1 | sepOn | 2 | 3 ; §\C{// locally turn on implicit separator}§3443 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§ 3444 3444 \end{cfa} 3445 3445 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3448 3448 The tuple separator also responses to being turned on and off. 3449 3449 \begin{cfa}[belowskip=0pt] 3450 sout | t1 | sepOff | t2 ; §\C{// locally turn on/off implicit separator}§3450 sout | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separator}§ 3451 3451 \end{cfa} 3452 3452 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3456 3456 use ©sep© to accomplish this functionality. 3457 3457 \begin{cfa}[belowskip=0pt] 3458 sout | sepOn | 1 | 2 | 3 | sepOn ; §\C{// sepOn does nothing at start/end of line}§3458 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; §\C{// sepOn does nothing at start/end of line}§ 3459 3459 \end{cfa} 3460 3460 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3462 3462 \end{cfa} 3463 3463 \begin{cfa}[belowskip=0pt] 3464 sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§3464 sout | sep | 1 | 2 | 3 | sep | endl ; §\C{// use sep to print separator at start/end of line}§ 3465 3465 \end{cfa} 3466 3466 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3475 3475 int main( void ) { 3476 3476 int x = 1, y = 2, z = 3; 3477 sout | x | y | z ;3477 sout | x | y | z | endl; 3478 3478 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3479 sout | t1 | t2 ; // print tuples3480 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) ;3481 sout | 1 | 2 | 3 ;3482 sout | '1' | '2' | '3' ;3483 sout | 1 | "" | 2 | "" | 3 ;3479 sout | t1 | t2 | endl; // print tuples 3480 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 3481 sout | 1 | 2 | 3 | endl; 3482 sout | '1' | '2' | '3' | endl; 3483 sout | 1 | "" | 2 | "" | 3 | endl; 3484 3484 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3485 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 ;3485 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl; 3486 3486 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 3487 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" ;3488 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" ;3489 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 ;3487 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl; 3488 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl; 3489 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; 3490 3490 3491 3491 sepSet( sout, ", $" ); // set separator from " " to ", $" 3492 sout | 1 | 2 | 3 | " \"" | sep | "\"" ;3492 sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl; 3493 3493 sepSet( sout, " " ); // reset separator to " " 3494 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" ;3494 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 3495 3495 3496 3496 char store[sepSize]; 3497 3497 strcpy( store, sepGet( sout ) ); 3498 3498 sepSet( sout, "_" ); 3499 sout | 1 | 2 | 3 ;3499 sout | 1 | 2 | 3 | endl; 3500 3500 sepSet( sout, store ); 3501 sout | 1 | 2 | 3 ;3501 sout | 1 | 2 | 3 | endl; 3502 3502 3503 3503 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 3504 sout | t1 | t2 | " \"" | sepTuple | "\"" ;3504 sout | t1 | t2 | " \"" | sepTuple | "\"" | endl; 3505 3505 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 3506 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" ;3507 3508 sout | sepDisable | 1 | 2 | 3 ; // globally turn off implicit separator3509 sout | sepEnable | 1 | 2 | 3 ; // globally turn on implicit separator3510 3511 sout | 1 | sepOff | 2 | 3 ; // locally turn on implicit separator3512 sout | sepDisable | 1 | sepOn | 2 | 3 ; // globally turn off implicit separator3506 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 3507 3508 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separator 3509 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separator 3510 3511 sout | 1 | sepOff | 2 | 3 | endl; // locally turn on implicit separator 3512 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator 3513 3513 sout | sepEnable; 3514 sout | t1 | sepOff | t2 ; // locally turn on/off implicit separator3515 3516 sout | sepOn | 1 | 2 | 3 | sepOn ; // sepOn does nothing at start/end of line3517 sout | sep | 1 | 2 | 3 | sep ; // use sep to print separator at start/end of line3514 sout | t1 | sepOff | t2 | endl; // locally turn on/off implicit separator 3515 3516 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; // sepOn does nothing at start/end of line 3517 sout | sep | 1 | 2 | 3 | sep | endl ; // use sep to print separator at start/end of line 3518 3518 } 3519 3519 … … 4180 4180 Fibonacci f1, f2; 4181 4181 for ( int i = 1; i <= 10; i += 1 ) { 4182 sout | next( &f1 ) | ' ' | next( &f2 ) ;4182 sout | next( &f1 ) | ' ' | next( &f2 ) | endl; 4183 4183 } // for 4184 4184 } … … 4246 4246 MyThread f[4]; 4247 4247 } 4248 sout | global.value ;4248 sout | global.value | endl; 4249 4249 } 4250 4250 \end{cfa} … … 4324 4324 void main( First * this ) { 4325 4325 for ( int i = 0; i < 10; i += 1 ) { 4326 sout | "First : Suspend No." | i + 1 ;4326 sout | "First : Suspend No." | i + 1 | endl; 4327 4327 yield(); 4328 4328 } … … 4333 4333 wait( this->lock ); 4334 4334 for ( int i = 0; i < 10; i += 1 ) { 4335 sout | "Second : Suspend No." | i + 1 ;4335 sout | "Second : Suspend No." | i + 1 | endl; 4336 4336 yield(); 4337 4337 } … … 4340 4340 int main( void ) { 4341 4341 signal_once lock; 4342 sout | "User main begin" ;4342 sout | "User main begin" | endl; 4343 4343 { 4344 4344 processor p; … … 4348 4348 } 4349 4349 } 4350 sout | "User main end" ;4350 sout | "User main end" | endl; 4351 4351 } 4352 4352 \end{cfa} … … 5045 5045 void ?{}( Line * l ) { 5046 5046 l->lnth = 0.0; 5047 sout | "default" ;5047 sout | "default" | endl; 5048 5048 } 5049 5049 … … 5052 5052 void ?{}( Line * l, float lnth ) { 5053 5053 l->lnth = lnth; 5054 sout | "lnth" | l->lnth ;5054 sout | "lnth" | l->lnth | endl; 5055 5055 5056 5056 } … … 5058 5058 // destructor 5059 5059 void ^?() { 5060 sout | "destroyed" ;5060 sout | "destroyed" | endl; 5061 5061 l.lnth = 0.0; 5062 5062 } … … 5804 5804 In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character. 5805 5805 \begin{cfa} 5806 sout | 'x' | " " | (int)'x' ;5806 sout | 'x' | " " | (int)'x' | endl; 5807 5807 x 120 5808 5808 \end{cfa} … … 7034 7034 #include <gmp>§\indexc{gmp}§ 7035 7035 int main( void ) { 7036 sout | "Factorial Numbers" ;7036 sout | "Factorial Numbers" | endl; 7037 7037 Int fact = 1; 7038 7038 7039 sout | 0 | fact ;7039 sout | 0 | fact | endl; 7040 7040 for ( unsigned int i = 1; i <= 40; i += 1 ) { 7041 7041 fact *= i; 7042 sout | i | fact ;7042 sout | i | fact | endl; 7043 7043 } 7044 7044 } -
examples/ArrayN.c
r85acec94 r90cfc16 7 7 8 8 forall(otype index_t) 9 index_t offset_to_index(unsigned offset, index_t size) { 9 index_t offset_to_index(unsigned offset, index_t size) 10 { 10 11 return [offset / size.0, offset % size.1]; 11 12 } 12 13 13 int main(int argc, char* argv[]) { 14 int main(int argc, char* argv[]) 15 { 14 16 unsigned x = 0, y = 0, i = 0; 15 17 unsigned sx = 4, sy = 4; … … 18 20 [x, y] = offset_to_index(6, [sx, sy]); 19 21 20 sout | x | ' ' | y ;22 sout | x | ' ' | y | endl; 21 23 22 24 return 0; -
examples/gc_no_raii/src/internal/collector.c
r85acec94 r90cfc16 38 38 void* gc_allocate(size_t target_size) 39 39 { 40 // sout | "Allocating " | target_size | " bytes" ;40 // sout | "Allocating " | target_size | " bytes" | endl; 41 41 42 42 size_t size = gc_compute_size(target_size + sizeof(gc_object_header)); 43 43 44 // sout | "Object header size: " | sizeof(gc_object_header) | " bytes" ;45 // sout | "Actual allocation size: " | size | " bytes" ;44 // sout | "Object header size: " | sizeof(gc_object_header) | " bytes" | endl; 45 // sout | "Actual allocation size: " | size | " bytes" | endl; 46 46 47 47 check(size < POOL_SIZE_BYTES); -
examples/gc_no_raii/src/internal/state.h
r85acec94 r90cfc16 38 38 static inline bool gc_needs_collect(gc_state* state) 39 39 { 40 // sout | "Used Space: " | state->used_space | " bytes" ;40 // sout | "Used Space: " | state->used_space | " bytes" | endl; 41 41 return state->used_space * 2 > state->total_space; 42 42 } -
examples/gc_no_raii/src/tools/print.h
r85acec94 r90cfc16 5 5 // #include <fstream.hfa> 6 6 // 7 // #define DEBUG_OUT(x) sout | x ;7 // #define DEBUG_OUT(x) sout | x | endl; 8 8 // 9 9 // #else -
examples/multicore.c
r85acec94 r90cfc16 15 15 16 16 int main(int argc, char* argv[]) { 17 // sout | "User main begin" ;17 // sout | "User main begin" | endl; 18 18 { 19 19 processor p; … … 22 22 } 23 23 } 24 // sout | "User main end" ;24 // sout | "User main end" | endl; 25 25 } -
examples/prolog.c
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 23:27:19 201813 // Update Count : 612 // Last Modified On : Tue Mar 8 22:09:39 2016 13 // Update Count : 5 14 14 // 15 15 16 16 #include <fstream.hfa> 17 17 18 void printResult( int x ) { sout | "int" ; }19 void printResult( double x ) { sout | "double" ; }20 void printResult( char * x ) { sout | "char*" ; }18 void printResult( int x ) { sout | "int" | endl; } 19 void printResult( double x ) { sout | "double" | endl; } 20 void printResult( char * x ) { sout | "char*" | endl; } 21 21 22 22 void is_arithmetic( int x ) {} -
examples/quad.c
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 23:26:58 201813 // Update Count : 912 // Last Modified On : Tue Mar 8 22:07:02 2016 13 // Update Count : 8 14 14 // 15 15 … … 28 28 int main() { 29 29 int N = 2; 30 sout | "result of quad of" | N | "is" | quad( N ) ;30 sout | "result of quad of" | N | "is" | quad( N ) | endl; 31 31 } 32 32 -
examples/square.c
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 23:28:24 201813 // Update Count : 2 812 // Last Modified On : Tue Mar 8 22:05:48 2016 13 // Update Count : 27 14 14 // 15 15 … … 23 23 int main() { 24 24 #if 0 25 sout | "result of squaring 9 is " ;25 sout | "result of squaring 9 is " | endl; 26 26 27 27 // char does not have multiplication. … … 30 30 } // ?*? 31 31 char c = 9; 32 sout | "char\t\t\t" | square( c ) ;32 sout | "char\t\t\t" | square( c ) | endl; 33 33 34 sout | square( s ) ;34 sout | square( s ) | endl; 35 35 #endif 36 36 short s = 9; … … 38 38 #if 0 39 39 signed int i = 9; 40 sout | "signed int\t\t" | square( i ) ;40 sout | "signed int\t\t" | square( i ) | endl; 41 41 42 42 unsigned int ui = 9; 43 sout | "unsigned int\t\t" | square( ui ) ;43 sout | "unsigned int\t\t" | square( ui ) | endl; 44 44 45 45 long int li = 9; 46 sout | "signed long int\t\t" | square( li ) ;46 sout | "signed long int\t\t" | square( li ) | endl; 47 47 48 48 unsigned long int uli = 9; 49 sout | "unsigned long int\t" | square( uli ) ;49 sout | "unsigned long int\t" | square( uli ) | endl; 50 50 51 51 signed long long int lli = 9; 52 sout | "signed long long int\t" | square( lli ) ;52 sout | "signed long long int\t" | square( lli ) | endl; 53 53 54 54 unsigned long long int ulli = 9; 55 sout | "unsigned long long int\t" | square( ulli ) ;55 sout | "unsigned long long int\t" | square( ulli ) | endl; 56 56 57 57 float f = 9.0; 58 sout | "float\t\t\t" | square( f ) ;58 sout | "float\t\t\t" | square( f ) | endl; 59 59 60 60 double d = 9.0; 61 sout | "double\t\t\t" | square( d ) ;61 sout | "double\t\t\t" | square( d ) | endl; 62 62 63 63 long double ld = 9.0; 64 sout | "long double\t\t" | square( ld ) ;64 sout | "long double\t\t" | square( ld ) | endl; 65 65 #endif 66 66 } // main -
examples/twice.c
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 23:28:08 201813 // Update Count : 4 712 // Last Modified On : Thu Oct 19 21:52:57 2017 13 // Update Count : 46 14 14 // 15 15 … … 28 28 29 29 int main( void ) { 30 sout | twice( ' ' ) | ' ' | twice( (signed char)0 ) | twice( (int)1 ) | twice( 3.2 ) ;30 sout | twice( ' ' ) | ' ' | twice( (signed char)0 ) | twice( (int)1 ) | twice( 3.2 ) | endl; 31 31 } 32 32 -
examples/wrapper/src/main.c
r85acec94 r90cfc16 1 1 #include "pointer.h" 2 2 3 wrapper_t make_copy(wrapper_t copy) { 3 wrapper_t make_copy(wrapper_t copy) 4 { 4 5 return copy; 5 6 } 6 7 7 int main(int argc, char const *argv[]) { 8 int main(int argc, char const *argv[]) 9 { 8 10 wrapper_t p = wrap(6); 9 sout | nl | "test started"; 11 12 sout | endl | "test started" | endl; 13 10 14 wrapper_t p2 = p; 15 11 16 clear(&p); 17 12 18 p = p2; 19 13 20 wrapper_t p3 = make_copy(p2); 14 sout | nl | "test ended"; 21 22 sout | endl | "test ended" | endl; 23 15 24 return 0; 16 25 } -
examples/wrapper/src/pointer.h
r85acec94 r90cfc16 34 34 void ?{}(content_t* this) 35 35 { 36 sout | "Constructing content" ;36 sout | "Constructing content" | endl; 37 37 this->count = 0; 38 38 } … … 40 40 void ^?{}(content_t* this) 41 41 { 42 sout | "Destroying content" ;42 sout | "Destroying content" | endl; 43 43 } 44 44 … … 53 53 void ?{}(wrapper_t* this) 54 54 { 55 sout | "Constructing empty ref pointer" | nl;55 sout | "Constructing empty ref pointer" | endl | endl; 56 56 this->ptr = NULL; 57 57 } … … 59 59 void ?{}(wrapper_t* this, wrapper_t rhs) 60 60 { 61 sout | "Constructing ref pointer from copy" ;61 sout | "Constructing ref pointer from copy" | endl; 62 62 this->ptr = rhs.ptr; 63 63 this->ptr->count++; 64 sout | "Reference is " | this->ptr->count | nl;64 sout | "Reference is " | this->ptr->count | endl | endl; 65 65 } 66 66 … … 69 69 if(this->ptr) 70 70 { 71 sout | "Destroying ref pointer" ;71 sout | "Destroying ref pointer" | endl; 72 72 this->ptr->count--; 73 sout | "Reference is " | this->ptr->count | nl;73 sout | "Reference is " | this->ptr->count | endl | endl; 74 74 if(!this->ptr->count) delete(this->ptr); 75 75 } 76 76 else 77 77 { 78 sout | "Destroying empty ref pointer" | nl;78 sout | "Destroying empty ref pointer" | endl | endl; 79 79 } 80 80 } … … 82 82 wrapper_t ?=?(wrapper_t* this, wrapper_t rhs) 83 83 { 84 sout | "Setting ref pointer" ;84 sout | "Setting ref pointer" | endl; 85 85 if(this->ptr) 86 86 { 87 87 this->ptr->count--; 88 sout | "Reference is " | this->ptr->count | nl;88 sout | "Reference is " | this->ptr->count | endl | endl; 89 89 if(!this->ptr->count) delete(this->ptr); 90 90 } 91 91 this->ptr = rhs.ptr; 92 92 this->ptr->count++; 93 sout | "Reference is " | this->ptr->count | nl;93 sout | "Reference is " | this->ptr->count | endl | endl; 94 94 } 95 95 … … 98 98 this->ptr = c; 99 99 this->ptr->count++; 100 sout | "Setting ref pointer" ;101 sout | "Reference is " | this->ptr->count | nl;100 sout | "Setting ref pointer" | endl; 101 sout | "Reference is " | this->ptr->count | endl | endl; 102 102 } 103 103 104 104 void clear(wrapper_t* this) 105 105 { 106 sout | "Clearing ref pointer" ;106 sout | "Clearing ref pointer" | endl; 107 107 this->ptr->count--; 108 sout | "Reference is " | this->ptr->count | nl;108 sout | "Reference is " | this->ptr->count | endl | endl; 109 109 if(!this->ptr->count) delete(this->ptr); 110 110 this->ptr = NULL; -
examples/zero_one.c
r85acec94 r90cfc16 3 3 void foo(zero_t o) 4 4 { 5 sout | "It's a Zero!" ;5 sout | "It's a Zero!" | endl; 6 6 } 7 7 8 8 void foo(one_t o) 9 9 { 10 sout | "It's a One!" ;10 sout | "It's a One!" | endl; 11 11 } 12 12 13 13 void foo(int o) 14 14 { 15 sout | "It's a Number!" ;15 sout | "It's a Number!" | endl; 16 16 } 17 17 -
libcfa/src/fstream.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 08:34:28201813 // Update Count : 2 9812 // Last Modified On : Fri Aug 10 18:19:40 2018 13 // Update Count : 284 14 14 // 15 15 … … 20 20 #include <stdarg.h> // varargs 21 21 #include <string.h> // strlen 22 #include <stdbool.h> // true/false 22 23 #include <float.h> // DBL_DIG, LDBL_DIG 23 24 #include <complex.h> // creal, cimag … … 26 27 #define IO_MSG "I/O error: " 27 28 28 void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, bool nlOnOff, bool nonlManip,const char * separator, const char * tupleSeparator ) {29 void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, const char * separator, const char * tupleSeparator ) { 29 30 os.file = file; 30 31 os.sepDefault = sepDefault; 31 32 os.sepOnOff = sepOnOff; 32 os.nlOnOff = nlOnOff;33 os.nonlManip = nonlManip;34 33 sepSet( os, separator ); 35 34 sepSetCur( os, sepGet( os ) ); … … 45 44 bool getNL( ofstream & os ) { return os.sawNL; } 46 45 void setNL( ofstream & os, bool state ) { os.sawNL = state; } 47 bool getANL( ofstream & os ) { return os.nlOnOff; }48 bool getNonl( ofstream & os ) { return os.nonlManip; }49 void setNonl( ofstream & os, bool state ) { os.nonlManip = state; }50 46 51 47 // public … … 76 72 } // sepEnable 77 73 78 void nlOn( ofstream & os ) { os.nlOnOff = true; }79 void nlOff( ofstream & os ) { os.nlOnOff = false; }80 81 74 const char * sepGet( ofstream & os ) { return os.separator; } 82 75 void sepSet( ofstream & os, const char * s ) { … … 110 103 } // if 111 104 #endif // __CFA_DEBUG__ 112 (os){ file, true, false, true, false," ", ", " };105 (os){ file, true, false, " ", ", " }; 113 106 } // open 114 107 … … 154 147 } // fmt 155 148 156 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), true, false, true, false," ", ", " };149 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), true, false, " ", ", " }; 157 150 ofstream & sout = soutFile; 158 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), true, false, true, false," ", ", " };151 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), true, false, " ", ", " }; 159 152 ofstream & serr = serrFile; 160 153 -
libcfa/src/fstream.hfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 07:52:41201813 // Update Count : 1 4312 // Last Modified On : Sat Aug 11 13:54:27 2018 13 // Update Count : 132 14 14 // 15 15 … … 23 23 bool sepDefault; 24 24 bool sepOnOff; 25 bool nlOnOff;26 bool nonlManip;27 25 bool sawNL; 28 26 const char * sepCur; … … 39 37 bool getNL( ofstream & ); 40 38 void setNL( ofstream &, bool ); 41 bool getANL( ofstream & );42 bool getNonl( ofstream & );43 void setNonl( ofstream &, bool );44 39 45 40 // public … … 48 43 bool sepDisable( ofstream & ); 49 44 bool sepEnable( ofstream & ); 50 void nlOn( ofstream & );51 void nlOff( ofstream & );52 45 53 46 const char * sepGet( ofstream & ); -
libcfa/src/gmp.hfa
r85acec94 r90cfc16 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 4 23:25:51 201813 // Update Count : 2 212 // Last Modified On : Thu Dec 7 09:10:41 2017 13 // Update Count : 21 14 14 // 15 15 … … 262 262 } // ?|? 263 263 264 static inline forall( dtype ostype | ostream( ostype ) ) { 265 ostype & ?|?( ostype & os, Int mp ) { 266 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 267 gmp_printf( "%Zd", mp.mpz ); 268 sepOn( os ); 269 return os; 270 } // ?|? 271 272 void ?|?( ostype & os, Int mp ) { 273 (ostype)(os | mp); if ( getANL( os ) ) nl( os ); 274 } // ?|? 275 } // distribution 264 static inline forall( dtype ostype | ostream( ostype ) ) 265 ostype & ?|?( ostype & os, Int mp ) { 266 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 267 gmp_printf( "%Zd", mp.mpz ); 268 sepOn( os ); 269 return os; 270 } // ?|? 276 271 277 272 // Local Variables: // -
libcfa/src/iostream.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:02:03201813 // Update Count : 54612 // Last Modified On : Fri Nov 2 07:17:05 2018 13 // Update Count : 474 14 14 // 15 15 … … 19 19 #include <stdio.h> 20 20 #include <stdbool.h> // true/false 21 //#include <string.h> // strlen, strcmp21 //#include <string.h> // strlen, strcmp 22 22 extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); 23 23 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); … … 32 32 return os; 33 33 } // ?|? 34 void ?|?( ostype & os, bool b ) { 35 (ostype)(os | b); if ( getANL( os ) ) nl( os ); 36 } // ?|? 37 38 ostype & ?|?( ostype & os, char c ) { 39 fmt( os, "%c", c ); 40 if ( c == '\n' ) setNL( os, true ); 41 return sepOff( os ); 42 } // ?|? 43 void ?|?( ostype & os, char c ) { 44 (ostype)(os | c); if ( getANL( os ) ) nl( os ); 45 } // ?|? 46 47 ostype & ?|?( ostype & os, signed char sc ) { 48 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 49 fmt( os, "%hhd", sc ); 50 return os; 51 } // ?|? 52 void ?|?( ostype & os, signed char sc ) { 53 (ostype)(os | sc); if ( getANL( os ) ) nl( os ); 54 } // ?|? 55 56 ostype & ?|?( ostype & os, unsigned char usc ) { 57 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 58 fmt( os, "%hhu", usc ); 59 return os; 60 } // ?|? 61 void ?|?( ostype & os, unsigned char usc ) { 62 (ostype)(os | usc); if ( getANL( os ) ) nl( os ); 34 35 ostype & ?|?( ostype & os, char ch ) { 36 fmt( os, "%c", ch ); 37 if ( ch == '\n' ) setNL( os, true ); 38 sepOff( os ); 39 return os; 40 } // ?|? 41 42 ostype & ?|?( ostype & os, signed char c ) { 43 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 44 fmt( os, "%hhd", c ); 45 return os; 46 } // ?|? 47 48 ostype & ?|?( ostype & os, unsigned char c ) { 49 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 50 fmt( os, "%hhu", c ); 51 return os; 63 52 } // ?|? 64 53 … … 68 57 return os; 69 58 } // ?|? 70 void & ?|?( ostype & os, short int si ) {71 (ostype)(os | si); if ( getANL( os ) ) nl( os );72 } // ?|?73 59 74 60 ostype & ?|?( ostype & os, unsigned short int usi ) { … … 77 63 return os; 78 64 } // ?|? 79 void & ?|?( ostype & os, unsigned short int usi ) {80 (ostype)(os | usi); if ( getANL( os ) ) nl( os );81 } // ?|?82 65 83 66 ostype & ?|?( ostype & os, int i ) { … … 86 69 return os; 87 70 } // ?|? 88 void & ?|?( ostype & os, int i ) {89 (ostype)(os | i); if ( getANL( os ) ) nl( os );90 } // ?|?91 71 92 72 ostype & ?|?( ostype & os, unsigned int ui ) { … … 95 75 return os; 96 76 } // ?|? 97 void & ?|?( ostype & os, unsigned int ui ) {98 (ostype)(os | ui); if ( getANL( os ) ) nl( os );99 } // ?|?100 77 101 78 ostype & ?|?( ostype & os, long int li ) { … … 104 81 return os; 105 82 } // ?|? 106 void & ?|?( ostype & os, long int li ) {107 (ostype)(os | li); if ( getANL( os ) ) nl( os );108 } // ?|?109 83 110 84 ostype & ?|?( ostype & os, unsigned long int uli ) { … … 113 87 return os; 114 88 } // ?|? 115 void & ?|?( ostype & os, unsigned long int uli ) {116 (ostype)(os | uli); if ( getANL( os ) ) nl( os );117 } // ?|?118 89 119 90 ostype & ?|?( ostype & os, long long int lli ) { … … 122 93 return os; 123 94 } // ?|? 124 void & ?|?( ostype & os, long long int lli ) {125 (ostype)(os | lli); if ( getANL( os ) ) nl( os );126 } // ?|?127 95 128 96 ostype & ?|?( ostype & os, unsigned long long int ulli ) { … … 131 99 return os; 132 100 } // ?|? 133 void & ?|?( ostype & os, unsigned long long int ulli ) {134 (ostype)(os | ulli); if ( getANL( os ) ) nl( os );135 } // ?|?136 101 137 102 ostype & ?|?( ostype & os, float f ) { … … 140 105 return os; 141 106 } // ?|? 142 void & ?|?( ostype & os, float f ) {143 (ostype)(os | f); if ( getANL( os ) ) nl( os );144 } // ?|?145 107 146 108 ostype & ?|?( ostype & os, double d ) { … … 149 111 return os; 150 112 } // ?|? 151 void & ?|?( ostype & os, double d ) {152 (ostype)(os | d); if ( getANL( os ) ) nl( os );153 } // ?|?154 113 155 114 ostype & ?|?( ostype & os, long double ld ) { … … 158 117 return os; 159 118 } // ?|? 160 void & ?|?( ostype & os, long double ld ) {161 (ostype)(os | ld); if ( getANL( os ) ) nl( os );162 } // ?|?163 119 164 120 ostype & ?|?( ostype & os, float _Complex fc ) { … … 167 123 return os; 168 124 } // ?|? 169 void & ?|?( ostype & os, float _Complex fc ) {170 (ostype)(os | fc); if ( getANL( os ) ) nl( os );171 } // ?|?172 125 173 126 ostype & ?|?( ostype & os, double _Complex dc ) { … … 176 129 return os; 177 130 } // ?|? 178 void & ?|?( ostype & os, double _Complex dc ) {179 (ostype)(os | dc); if ( getANL( os ) ) nl( os );180 } // ?|?181 131 182 132 ostype & ?|?( ostype & os, long double _Complex ldc ) { … … 184 134 fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) ); 185 135 return os; 186 } // ?|?187 void & ?|?( ostype & os, long double _Complex ldc ) {188 (ostype)(os | ldc); if ( getANL( os ) ) nl( os );189 136 } // ?|? 190 137 … … 227 174 return write( os, str, len ); 228 175 } // ?|? 229 void ?|?( ostype & os, const char * str ) {230 (ostype)(os | str); if ( getANL( os ) ) nl( os );231 } // ?|?232 176 233 177 // ostype & ?|?( ostype & os, const char16_t * str ) { … … 256 200 return os; 257 201 } // ?|? 258 void ?|?( ostype & os, const void * p ) { 259 (ostype)(os | p); if ( getANL( os ) ) nl( os ); 260 } // ?|? 202 261 203 262 204 // manipulators 263 205 ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 264 (ostype)(manip( os )); 265 setNonl( os, false ); // ignore nonl in middle 266 return os; 267 } // ?|? 268 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 269 (ostype)(manip( os )); 270 if ( getANL( os ) && ! getNonl( os ) ) nl( os ); // ignore nl if nonl at end 271 setNonl( os, false ); 206 return manip( os ); 272 207 } // ?|? 273 208 274 209 ostype & sep( ostype & os ) { 275 return (ostype)(os | sepGet( os )); 210 os | sepGet( os ); 211 return os; 276 212 } // sep 277 213 278 214 ostype & sepTuple( ostype & os ) { 279 return os | sepGetTuple( os ); 215 os | sepGetTuple( os ); 216 return os; 280 217 } // sepTuple 281 218 282 ostype & nl( ostype & os ) {283 (ostype)(os | '\n');219 ostype & endl( ostype & os ) { 220 os | '\n'; 284 221 setNL( os, true ); 285 222 flush( os ); 286 return sepOff( os ); // prepare for next line 287 } // nl 288 289 ostype & nonl( ostype & os ) { 290 setNonl( os, true ); // indicate nonl manipulator 291 return os; 292 } // nonl 223 sepOff( os ); // prepare for next line 224 return os; 225 } // endl 293 226 294 227 ostype & sepOn( ostype & os ) { 295 sepOn( os ); // call void returning228 sepOn( os ); 296 229 return os; 297 230 } // sepOn 298 231 299 232 ostype & sepOff( ostype & os ) { 300 sepOff( os ); // call void returning233 sepOff( os ); 301 234 return os; 302 235 } // sepOff 303 236 304 237 ostype & sepEnable( ostype & os ) { 305 sepEnable( os ); // call void returning238 sepEnable( os ); 306 239 return os; 307 240 } // sepEnable 308 241 309 242 ostype & sepDisable( ostype & os ) { 310 sepDisable( os ); // call void returning243 sepDisable( os ); 311 244 return os; 312 245 } // sepDisable 313 314 ostype & nlOn( ostype & os ) {315 nlOn( os ); // call void returning316 return os;317 } // nlOn318 319 ostype & nlOff( ostype & os ) {320 nlOff( os ); // call void returning321 return os;322 } // nlOff323 246 } // distribution 324 247 248 325 249 // tuples 326 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 327 ostype & ?|?( ostype & os, T arg, Params rest ) { 328 (ostype)(os | arg); // print first argument 329 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 330 (ostype)(os | rest); // print remaining arguments 331 sepSetCur( os, sepGet( os ) ); // switch to regular separator 332 return os; 333 } // ?|? 334 void ?|?( ostype & os, T arg, Params rest ) { 335 // (ostype)(?|?( os, arg, rest )); if ( getANL( os ) ) nl( os ); 336 (ostype)(os | arg); // print first argument 337 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 338 (ostype)(os | rest); // print remaining arguments 339 sepSetCur( os, sepGet( os ) ); // switch to regular separator 340 if ( getANL( os ) ) nl( os ); 341 } // ?|? 342 } // distribution 250 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) 251 ostype & ?|?( ostype & os, T arg, Params rest ) { 252 os | arg; // print first argument 253 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 254 os | rest; // print remaining arguments 255 sepSetCur( os, sepGet( os ) ); // switch to regular separator 256 return os; 257 } // ?|? 343 258 344 259 //--------------------------------------- 345 260 346 261 // writes the range [begin, end) to the given stream 347 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {348 void write( iterator_type begin, iterator_type end, ostype & os ) {349 void print( elt_type i ) { os | i; }350 for_each( begin, end, print );351 } // ?|?352 353 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 354 void print( elt_type i ) { os | i; } 355 for_each_reverse( begin, end, print );356 } // ?|?357 } // distribution262 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 263 void write( iterator_type begin, iterator_type end, ostype & os ) { 264 void print( elt_type i ) { os | i; } 265 for_each( begin, end, print ); 266 } // ?|? 267 268 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 269 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 270 void print( elt_type i ) { os | i; } 271 for_each_reverse( begin, end, print ); 272 } // ?|? 358 273 359 274 //--------------------------------------- … … 471 386 } // ?|? 472 387 473 istype & nl( istype & is ) {388 istype & endl( istype & is ) { 474 389 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace 475 390 return is; 476 } // nl391 } // endl 477 392 } // distribution 478 393 -
libcfa/src/iostream.hfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:01:31201813 // Update Count : 21312 // Last Modified On : Sat Aug 11 08:22:49 2018 13 // Update Count : 156 14 14 // 15 15 … … 25 25 const char * sepGetCur( ostype & ); // get current separator string 26 26 void sepSetCur( ostype &, const char * ); // set current separator string 27 bool getNL( ostype & ); // check newline27 bool getNL( ostype & ); // check newline 28 28 void setNL( ostype &, bool ); // saw newline 29 bool getANL( ostype & ); // check auto newline30 bool getNonl( ostype & ); // check nonnl manipulator31 void setNonl( ostype &, bool ); // set nonnl manipulator32 29 // public 33 30 void sepOn( ostype & ); // turn separator state on 34 31 void sepOff( ostype & ); // turn separator state off 35 32 bool sepDisable( ostype & ); // set default state to off, and return previous state 36 bool sepEnable( ostype & ); // set default state to on, and return previous state 37 void nlOn( ostype & ); // turn auto-newline state on 38 void nlOff( ostype & ); // turn auto-newline state off 33 bool sepEnable( ostype & ); // set default state to on, and return previous state 39 34 40 35 const char * sepGet( ostype & ); // get separator string … … 63 58 forall( dtype ostype | ostream( ostype ) ) { 64 59 ostype & ?|?( ostype &, bool ); 65 void & ?|?( ostype &, bool );66 60 67 61 ostype & ?|?( ostype &, char ); 68 void & ?|?( ostype &, char );69 62 ostype & ?|?( ostype &, signed char ); 70 void & ?|?( ostype &, signed char );71 63 ostype & ?|?( ostype &, unsigned char ); 72 void & ?|?( ostype &, unsigned char );73 64 74 65 ostype & ?|?( ostype &, short int ); 75 void & ?|?( ostype &, short int );76 66 ostype & ?|?( ostype &, unsigned short int ); 77 void & ?|?( ostype &, unsigned short int );78 67 ostype & ?|?( ostype &, int ); 79 void & ?|?( ostype &, int );80 68 ostype & ?|?( ostype &, unsigned int ); 81 void & ?|?( ostype &, unsigned int );82 69 ostype & ?|?( ostype &, long int ); 83 void & ?|?( ostype &, long int );84 70 ostype & ?|?( ostype &, long long int ); 85 void & ?|?( ostype &, long long int );86 71 ostype & ?|?( ostype &, unsigned long int ); 87 void & ?|?( ostype &, unsigned long int );88 72 ostype & ?|?( ostype &, unsigned long long int ); 89 void & ?|?( ostype &, unsigned long long int );90 73 91 74 ostype & ?|?( ostype &, float ); // FIX ME: should not be required 92 void & ?|?( ostype &, float ); // FIX ME: should not be required93 75 ostype & ?|?( ostype &, double ); 94 void & ?|?( ostype &, double );95 76 ostype & ?|?( ostype &, long double ); 96 void & ?|?( ostype &, long double );97 77 98 78 ostype & ?|?( ostype &, float _Complex ); 99 void & ?|?( ostype &, float _Complex );100 79 ostype & ?|?( ostype &, double _Complex ); 101 void & ?|?( ostype &, double _Complex );102 80 ostype & ?|?( ostype &, long double _Complex ); 103 void & ?|?( ostype &, long double _Complex );104 81 105 82 ostype & ?|?( ostype &, const char * ); 106 void & ?|?( ostype &, const char * );107 83 // ostype & ?|?( ostype &, const char16_t * ); 108 84 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous … … 111 87 // ostype & ?|?( ostype &, const wchar_t * ); 112 88 ostype & ?|?( ostype &, const void * ); 113 void & ?|?( ostype &, const void * );114 89 115 90 // manipulators 116 91 ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); 117 void ?|?( ostype &, ostype & (*)( ostype & ) ); 118 ostype & nl( ostype & ); 119 ostype & nonl( ostype & ); 92 ostype & endl( ostype & ); 120 93 ostype & sep( ostype & ); 121 94 ostype & sepTuple( ostype & ); … … 124 97 ostype & sepDisable( ostype & ); 125 98 ostype & sepEnable( ostype & ); 126 ostype & nlOn( ostype & );127 ostype & nlOff( ostype & );128 99 } // distribution 129 100 130 101 // tuples 131 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 132 ostype & ?|?( ostype & os, T arg, Params rest ); 133 void ?|?( ostype & os, T arg, Params rest ); 134 } // distribution 102 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) 103 ostype & ?|?( ostype & os, T arg, Params rest ); 135 104 136 105 // writes the range [begin, end) to the given stream 137 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) { 138 void write( iterator_type begin, iterator_type end, ostype & os ); 139 void write_reverse( iterator_type begin, iterator_type end, ostype & os ); 140 } // distribution 106 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 107 void write( iterator_type begin, iterator_type end, ostype & os ); 108 109 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 110 void write_reverse( iterator_type begin, iterator_type end, ostype & os ); 141 111 142 112 //--------------------------------------- … … 182 152 // manipulators 183 153 istype & ?|?( istype &, istype & (*)( istype & ) ); 184 istype & nl( istype & is );154 istype & endl( istype & is ); 185 155 } // distribution 186 156 … … 194 164 195 165 196 #include <time_t.hfa> // Duration (constructors) / Time (constructors)166 #include <time_t.hfa> // Duration (constructors) / Time (constructors) 197 167 198 forall( dtype ostype | ostream( ostype ) ) { 199 ostype & ?|?( ostype & os, Duration dur ); 200 void ?|?( ostype & os, Duration dur ); 201 ostype & ?|?( ostype & os, Time time ); 202 void ?|?( ostype & os, Time time ); 203 } // distribution 168 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur ); 169 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time ); 170 204 171 205 172 // Local Variables: // -
libcfa/src/rational.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:02:29201813 // Update Count : 16 812 // Last Modified On : Sat Jun 2 09:24:33 2018 13 // Update Count : 162 14 14 // 15 15 … … 35 35 static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) { 36 36 if ( d == (RationalImpl){0} ) { 37 serr | "Invalid rational number construction: denominator cannot be equal to 0." ;37 serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl; 38 38 exit( EXIT_FAILURE ); 39 39 } // exit … … 175 175 } // ?|? 176 176 177 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) { 178 ostype & ?|?( ostype & os, Rational(RationalImpl) r ) { 179 return os | r.numerator | '/' | r.denominator; 180 } // ?|? 181 182 void ?|?( ostype & os, Rational(RationalImpl) r ) { 183 (ostype)(os | r); if ( getANL( os ) ) nl( os ); 184 } // ?|? 185 } // distribution 177 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) 178 ostype & ?|?( ostype & os, Rational(RationalImpl ) r ) { 179 return os | r.numerator | '/' | r.denominator; 180 } // ?|? 186 181 } // distribution 187 182 -
libcfa/src/rational.hfa
r85acec94 r90cfc16 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Tue Dec 4 23:07:46201815 // Update Count : 10 614 // Last Modified On : Sat Jun 2 09:10:01 2018 15 // Update Count : 105 16 16 // 17 17 … … 92 92 istype & ?|?( istype &, Rational(RationalImpl) & ); 93 93 94 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) { 95 ostype & ?|?( ostype &, Rational(RationalImpl) ); 96 void ?|?( ostype &, Rational(RationalImpl) ); 97 } // distribution 94 forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) 95 ostype & ?|?( ostype &, Rational(RationalImpl ) ); 98 96 } // distribution 99 97 -
libcfa/src/time.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Mar 27 13:33:14 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:32:15201813 // Update Count : 5312 // Last Modified On : Sun May 6 22:26:00 2018 13 // Update Count : 37 14 14 // 15 15 … … 31 31 32 32 33 forall( dtype ostype | ostream( ostype ) ) { 34 ostype & ?|?( ostype & os, Duration dur ) with( dur ) { 35 (ostype)(os | tv / TIMEGRAN); // print seconds 36 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 37 if ( ns != 0 ) { // some ? 38 char buf[16]; 39 (ostype)(os | nanomsd( ns, buf )); // print nanoseconds 40 } // if 41 return os; 42 } // ?|? 43 44 void ?|?( ostype & os, Duration dur ) with( dur ) { 45 (ostype)(os | dur); if ( getANL( os ) ) nl( os ); 46 } // ?|? 47 } // distribution 33 forall( dtype ostype | ostream( ostype ) ) 34 ostype & ?|?( ostype & os, Duration dur ) with( dur ) { 35 os | tv / TIMEGRAN; // print seconds 36 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 37 if ( ns != 0 ) { // some ? 38 char buf[16]; 39 os | nanomsd( ns, buf ); // print nanoseconds 40 } // if 41 return os; 42 } // ?|? 48 43 49 44 … … 142 137 } // strftime 143 138 144 forall( dtype ostype | ostream( ostype ) ) { 145 ostype & ?|?( ostype & os, Time time ) with( time ) { 146 char buf[32]; // at least 26 147 time_t s = tv / TIMEGRAN; 148 ctime_r( &s, (char *)&buf ); // 26 characters: "Wed Jun 30 21:49:08 1993\n" 149 buf[24] = '\0'; // remove trailing '\n' 150 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 151 if ( ns == 0 ) { // none ? 152 (ostype)(os | buf); // print date/time/year 153 } else { 154 buf[19] = '\0'; // truncate to "Wed Jun 30 21:49:08" 155 char buf2[16]; 156 nanomsd( ns, buf2 ); // compute nanoseconds 157 (ostype)(os | buf | buf2 | ' ' | &buf[20]); // print date/time, nanoseconds and year 158 } // if 159 return os; 160 } // ?|? 161 162 void ?|?( ostype & os, Time time ) with( time ) { 163 (ostype)(os | time); if ( getANL( os ) ) nl( os ); 164 } // ?|? 165 } // distribution 139 forall( dtype ostype | ostream( ostype ) ) 140 ostype & ?|?( ostype & os, Time time ) with( time ) { 141 char buf[32]; // at least 26 142 time_t s = tv / TIMEGRAN; 143 ctime_r( &s, (char *)&buf ); // 26 characters: "Wed Jun 30 21:49:08 1993\n" 144 buf[24] = '\0'; // remove trailing '\n' 145 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 146 if ( ns == 0 ) { // none ? 147 os | buf; // print date/time/year 148 } else { 149 buf[19] = '\0'; // truncate to "Wed Jun 30 21:49:08" 150 os | buf; // print date/time 151 char buf2[16]; 152 nanomsd( ns, buf2 ); // compute nanoseconds 153 os | buf2 | ' ' | &buf[20]; // print nanoseconds and year 154 } // if 155 return os; 156 } // ?|? 166 157 167 158 // Local Variables: // -
tests/abs.cfa
r85acec94 r90cfc16 10 10 // Created On : Thu Jan 28 18:26:16 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:33:15201813 // Update Count : 5 512 // Last Modified On : Tue Nov 6 17:50:44 2018 13 // Update Count : 54 14 14 // 15 15 … … 19 19 int main( void ) { 20 20 signed char ch = -65; 21 sout | "char\t\t\t" | ch | "\tabs " | abs( ch ) ;22 sout | "signed int\t\t" | -65 | "\tabs" | abs( -65 ) ;23 sout | "signed long int\t\t" | -65l | "\tabs" | abs( -65l ) ;24 sout | "signed long long int\t" | -65ll | "\tabs" | abs( -65ll ) ;25 sout | "float\t\t\t" | -65.0f | "\tabs" | abs( -65.0f ) ;26 sout | "double\t\t\t" | -65.0 | "\tabs" | abs( -65.0 ) ;27 sout | "long double\t\t" | -65.0l | "\tabs" | abs( -65.0l ) ;28 sout | "float _Complex\t\t" | -65.0F-2.0iF | "\tabs" | abs( -65.0F-2.0iF ) ;29 sout | "double _Complex\t\t" | -65.0D-2.0iD | "\tabs" | abs( -65.0D-2.0iD ) ;30 sout | "long double _Complex\t" | -65.0L-2.0iL | "\tabs" | abs( -65.0L-2.0iL ) ;21 sout | "char\t\t\t" | ch | "\tabs " | abs( ch ) | endl; 22 sout | "signed int\t\t" | -65 | "\tabs" | abs( -65 ) | endl; 23 sout | "signed long int\t\t" | -65l | "\tabs" | abs( -65l ) | endl; 24 sout | "signed long long int\t" | -65ll | "\tabs" | abs( -65ll ) | endl; 25 sout | "float\t\t\t" | -65.0f | "\tabs" | abs( -65.0f ) | endl; 26 sout | "double\t\t\t" | -65.0 | "\tabs" | abs( -65.0 ) | endl; 27 sout | "long double\t\t" | -65.0l | "\tabs" | abs( -65.0l ) | endl; 28 sout | "float _Complex\t\t" | -65.0F-2.0iF | "\tabs" | abs( -65.0F-2.0iF ) | endl; 29 sout | "double _Complex\t\t" | -65.0D-2.0iD | "\tabs" | abs( -65.0D-2.0iD ) | endl; 30 sout | "long double _Complex\t" | -65.0L-2.0iL | "\tabs" | abs( -65.0L-2.0iL ) | endl; 31 31 } // main 32 32 -
tests/ato.cfa
r85acec94 r90cfc16 10 10 // Created On : Thu Feb 4 08:10:57 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:33:53 201813 // Update Count : 9 212 // Last Modified On : Tue Nov 6 17:51:03 2018 13 // Update Count : 91 14 14 // 15 15 … … 20 20 const char * sptr = "-123"; 21 21 int i = ato( sptr ); 22 sout | i | sptr ;22 sout | i | sptr | endl; 23 23 sptr = "123"; 24 24 unsigned int ui = ato( sptr ); 25 sout | ui | sptr ;25 sout | ui | sptr | endl; 26 26 27 27 sptr = "-123"; 28 28 long int li = ato( sptr ); 29 sout | li | sptr ;29 sout | li | sptr | endl; 30 30 sptr = "123"; 31 31 unsigned long int uli = ato( sptr ); 32 sout | uli | sptr ;32 sout | uli | sptr | endl; 33 33 34 34 sptr = "-123"; 35 35 long long int lli = ato( sptr ); 36 sout | lli | sptr ;36 sout | lli | sptr | endl; 37 37 sptr = "123"; 38 38 unsigned long long int ulli = ato( sptr ); 39 sout | ulli | sptr ;39 sout | ulli | sptr | endl; 40 40 41 41 sptr = "-123.456"; 42 42 float f = ato( sptr ); 43 sout | f | sptr ;43 sout | f | sptr | endl; 44 44 sptr = "-123.4567890123456"; 45 45 double d = ato( sptr ); 46 sout | d | sptr ;46 sout | d | sptr | endl; 47 47 sptr = "-123.45678901234567890123456789"; 48 48 long double ld = ato( sptr ); 49 sout | ld | sptr ;49 sout | ld | sptr | endl; 50 50 51 51 sptr = "-123.456-123.456i"; 52 52 float _Complex fc = ato( sptr ); 53 sout | fc | sptr ;53 sout | fc | sptr | endl; 54 54 sptr = "-123.4567890123456+123.4567890123456i"; 55 55 double _Complex dc = ato( sptr ); 56 sout | dc | sptr ;56 sout | dc | sptr | endl; 57 57 sptr = "123.45678901234567890123456789-123.45678901234567890123456789i"; 58 58 long double _Complex ldc = ato( sptr ); 59 sout | ldc | sptr ;59 sout | ldc | sptr | endl; 60 60 sptr = "123.45678901234-123.4567890i"; 61 61 long double _Complex ldc2 = ato( sptr ); 62 sout | ldc2 | sptr ;62 sout | ldc2 | sptr | endl; 63 63 64 64 65 65 sptr = "-123"; 66 66 i = strto( sptr, 0, 10 ); 67 sout | i | sptr ;67 sout | i | sptr | endl; 68 68 sptr = "123"; 69 69 ui = strto( sptr, 0, 10 ); 70 sout | ui | sptr ;70 sout | ui | sptr | endl; 71 71 72 72 sptr = "-123"; 73 73 li = strto( sptr, 0, 10 ); 74 sout | li | sptr ;74 sout | li | sptr | endl; 75 75 sptr = "123"; 76 76 uli = strto( sptr, 0, 10 ); 77 sout | uli | sptr ;77 sout | uli | sptr | endl; 78 78 79 79 sptr = "-123"; 80 80 lli = strto( sptr, 0, 10 ); 81 sout | lli | sptr ;81 sout | lli | sptr | endl; 82 82 sptr = "123"; 83 83 ulli = strto( sptr, 0, 10 ); 84 sout | ulli | sptr ;84 sout | ulli | sptr | endl; 85 85 86 86 sptr = "-123.456"; 87 87 f = strto( sptr, 0 ); 88 sout | f | sptr ;88 sout | f | sptr | endl; 89 89 sptr = "-123.4567890123456"; 90 90 d = strto( sptr, 0 ); 91 sout | d | sptr ;91 sout | d | sptr | endl; 92 92 sptr = "-123.45678901234567890123456789"; 93 93 ld = strto( sptr, 0 ); 94 sout | ld | sptr ;94 sout | ld | sptr | endl; 95 95 96 96 sptr = "-123.456-123.456i"; 97 97 fc = strto( sptr, 0 ); 98 sout | fc | sptr ;98 sout | fc | sptr | endl; 99 99 100 100 char * eptr = 0; 101 101 // sptr = "2fred"; 102 102 // fc = strto( sptr, &eptr ); 103 // sout | fc | sptr | eptr ;103 // sout | fc | sptr | eptr | endl; 104 104 105 105 sptr = "2 3"; 106 106 fc = strto( sptr, &eptr ); 107 sout | fc | sptr | eptr ;107 sout | fc | sptr | eptr | endl; 108 108 109 109 sptr = "-123.4567890123456+123.4567890123456i"; 110 110 dc = strto( sptr, 0 ); 111 sout | dc | sptr ;111 sout | dc | sptr | endl; 112 112 sptr = "123.45678901234567890123456789-123.45678901234567890123456789i"; 113 113 ldc = strto( sptr, 0 ); 114 sout | ldc | sptr ;114 sout | ldc | sptr | endl; 115 115 sptr = "123.45678901234-123.4567890i"; 116 116 ldc2 = strto( sptr, 0 ); 117 sout | ldc2 | sptr ;117 sout | ldc2 | sptr | endl; 118 118 } // main 119 119 -
tests/complex.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 24 22:07:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:34:21201813 // Update Count : 412 // Last Modified On : Tue Nov 6 17:51:22 2018 13 // Update Count : 3 14 14 // 15 15 … … 25 25 printf( "x:%g+%gi y:%g+%gi z:%g+%gi\n", creal(x), cimag(x), creal(y), cimag(y), creal(z), cimag(z) ); 26 26 #ifdef __CFA__ 27 sout | "x:" | x | "y:" | y | "z:" | z ;27 sout | "x:" | x | "y:" | y | "z:" | z | endl; 28 28 #endif // __CFA 29 29 x = 2.1 + 1.3i; … … 32 32 printf( "x:%g+%gi y:%g+%gi z:%g+%gi\n", creal(x), cimag(x), creal(y), cimag(y), creal(z), cimag(z) ); 33 33 #ifdef __CFA__ 34 sout | "x:" | x | "y:" | y | "z:" | z ;34 sout | "x:" | x | "y:" | y | "z:" | z | endl; 35 35 #endif // __CFA 36 36 } -
tests/concurrent/coroutineYield.c
r85acec94 r90cfc16 27 27 while(true) { 28 28 #if !defined(TEST_FOREVER) 29 sout | "Coroutine 1" ;29 sout | "Coroutine 1" | endl; 30 30 #endif 31 31 yield(); 32 32 #if !defined(TEST_FOREVER) 33 sout | "Coroutine 2" ;33 sout | "Coroutine 2" | endl; 34 34 #endif 35 35 suspend(); … … 42 42 for(int i = 0; TEST(i < N); i++) { 43 43 #if !defined(TEST_FOREVER) 44 sout | "Thread 1" ;44 sout | "Thread 1" | endl; 45 45 #endif 46 46 resume(c); 47 47 #if !defined(TEST_FOREVER) 48 sout | "Thread 2" ;48 sout | "Thread 2" | endl; 49 49 #endif 50 50 yield(); -
tests/concurrent/examples/boundedBufferEXT.c
r85acec94 r90cfc16 8 8 // Created On : Wed Apr 18 22:52:12 2018 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : T ue Dec 11 21:55:02201811 // Update Count : 910 // Last Modified On : Thu Aug 16 08:17:03 2018 11 // Update Count : 8 12 12 // 13 13 … … 115 115 sum += sums[i]; 116 116 } // for 117 sout | "total:" | sum ;117 sout | "total:" | sum | endl; 118 118 } 119 119 -
tests/concurrent/examples/boundedBufferINT.c
r85acec94 r90cfc16 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : T ue Dec 11 21:55:45201811 // Update Count : 8 410 // Last Modified On : Thu Aug 16 08:17:58 2018 11 // Update Count : 83 12 12 // 13 13 … … 116 116 sum += sums[i]; 117 117 } // for 118 sout | "total:" | sum ;118 sout | "total:" | sum | endl; 119 119 } 120 120 -
tests/concurrent/examples/datingService.c
r85acec94 r90cfc16 8 8 // Created On : Mon Oct 30 12:56:20 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Tue Dec 11 21:55:34201811 // Update Count : 2 810 // Last Modified On : Sun May 27 09:05:18 2018 11 // Update Count : 26 12 12 // 13 13 … … 58 58 yield( random( 100 ) ); // don't all start at the same time 59 59 unsigned int partner = girl( TheExchange, id, ccode ); 60 sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode ;60 sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl; 61 61 girlck[id] = partner; 62 62 } // Girl main … … 69 69 70 70 thread Boy { 71 DatingService & TheExchange;71 DatingService &TheExchange; 72 72 unsigned int id, ccode; 73 73 }; // Boy … … 76 76 yield( random( 100 ) ); // don't all start at the same time 77 77 unsigned int partner = boy( TheExchange, id, ccode ); 78 sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode ;78 sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl; 79 79 boyck[id] = partner; 80 80 } // Boy main -
tests/concurrent/examples/matrixSum.c
r85acec94 r90cfc16 11 11 // Created On : Mon Oct 9 08:29:28 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Dec 11 21:54:55201814 // Update Count : 1 513 // Last Modified On : Tue Nov 6 17:51:32 2018 14 // Update Count : 14 15 15 // 16 16 … … 54 54 total += subtotals[r]; // total subtotals 55 55 } // for 56 sout | total ;56 sout | total | endl; 57 57 } 58 58 -
tests/concurrent/examples/quickSort.c
r85acec94 r90cfc16 9 9 // Created On : Wed Dec 6 12:15:52 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : T ue Dec 4 18:00:27201812 // Update Count : 16 711 // Last Modified On : Thu Aug 16 08:17:41 2018 12 // Update Count : 163 13 13 // 14 14 … … 88 88 89 89 void usage( char * argv[] ) { 90 sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )" ;90 sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )" | endl; 91 91 exit( EXIT_FAILURE ); // TERMINATE! 92 92 } // usage … … 114 114 &sortedfile = new( (const char *)argv[2] ); // open the output file 115 115 if ( fail( sortedfile ) ) { 116 serr | "Error! Could not open sorted output file \"" | argv[2] | "\"" ;116 serr | "Error! Could not open sorted output file \"" | argv[2] | "\"" | endl; 117 117 usage( argv ); 118 118 } // if … … 121 121 &unsortedfile = new( (const char *)argv[1] ); // open the input file 122 122 if ( fail( unsortedfile ) ) { 123 serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"" ;123 serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"" | endl; 124 124 usage( argv ); 125 125 } // if … … 127 127 } // if 128 128 } // if 129 sortedfile | nlOff; // turn off auto newline130 129 131 130 enum { ValuesPerLine = 22 }; // number of values printed per line … … 138 137 for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers 139 138 unsortedfile | values[counter]; 140 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " ";139 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " "; 141 140 sortedfile | values[counter]; 142 141 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 143 142 } // for 144 sortedfile | nl;143 sortedfile | endl; 145 144 if ( size > 0 ) { // values to sort ? 146 145 Quicksort QS = { values, size - 1, 0 }; // sort values 147 146 } // wait until sort tasks terminate 148 147 for ( int counter = 0; counter < size; counter += 1 ) { // print sorted list 149 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " ";148 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " "; 150 149 sortedfile | values[counter]; 151 150 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 152 151 } // for 153 sortedfile | nl;152 sortedfile | endl | endl; 154 153 155 154 delete( values ); -
tests/concurrent/monitor.c
r85acec94 r90cfc16 40 40 MyThread f[4]; 41 41 } 42 sout | global.value ;42 sout | global.value | endl; 43 43 } -
tests/concurrent/multi-monitor.c
r85acec94 r90cfc16 52 52 } 53 53 } 54 sout | global12 | global23 | global13 ;54 sout | global12 | global23 | global13 | endl; 55 55 } -
tests/concurrent/signal/block.c
r85acec94 r90cfc16 57 57 58 58 if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) { 59 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread ;59 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl; 60 60 abort(); 61 61 } … … 85 85 86 86 if( ! signal_block( cond ) ) { 87 sout | "ERROR expected to be able to signal" ;87 sout | "ERROR expected to be able to signal" | endl; 88 88 abort(); 89 89 } … … 92 92 93 93 if(a.last_thread != next || b.last_thread != next) { 94 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread ;94 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl; 95 95 abort(); 96 96 } … … 130 130 Signaller s[4]; 131 131 Barger b[13]; 132 sout | "Starting waiters" ;132 sout | "Starting waiters" | endl; 133 133 { 134 134 Waiter w[3]; 135 135 } 136 sout | "Waiters done" ;136 sout | "Waiters done" | endl; 137 137 done = true; 138 138 } -
tests/concurrent/signal/disjoint.c
r85acec94 r90cfc16 66 66 wait( cond ); 67 67 if( d.state != SIGNAL ) { 68 sout | "ERROR barging!" ;68 sout | "ERROR barging!" | endl; 69 69 } 70 70 71 71 #if !defined(TEST_FOREVER) 72 72 d.counter++; 73 if( (d.counter % 1000) == 0 ) sout | d.counter ;73 if( (d.counter % 1000) == 0 ) sout | d.counter | endl; 74 74 #endif 75 75 … … 99 99 bool running = TEST(data.counter < N) && data.counter > 0; 100 100 if( data.state != SIGNAL && running ) { 101 sout | "ERROR Eager signal" | data.state ;101 sout | "ERROR Eager signal" | data.state | endl; 102 102 } 103 103 } … … 124 124 Waiter w[4]; 125 125 } 126 sout | "All waiter done" ;126 sout | "All waiter done" | endl; 127 127 all_done = true; 128 128 } -
tests/concurrent/signal/wait.c
r85acec94 r90cfc16 83 83 break; 84 84 default: 85 sout | "Something went wrong" ;85 sout | "Something went wrong" | endl; 86 86 abort(); 87 87 } … … 140 140 waiter_left = 4; 141 141 processor p[2]; 142 sout | "Starting" ;142 sout | "Starting" | endl; 143 143 { 144 144 Signaler e; … … 150 150 } 151 151 } 152 sout | "Done" ;152 sout | "Done" | endl; 153 153 } -
tests/concurrent/thread.c
r85acec94 r90cfc16 12 12 void main(First& this) { 13 13 for(int i = 0; i < 10; i++) { 14 sout | "First : Suspend No." | i + 1 ;14 sout | "First : Suspend No." | i + 1 | endl; 15 15 yield(); 16 16 } … … 21 21 P(*this.lock); 22 22 for(int i = 0; i < 10; i++) { 23 sout | "Second : Suspend No." | i + 1 ;23 sout | "Second : Suspend No." | i + 1 | endl; 24 24 yield(); 25 25 } … … 29 29 int main(int argc, char* argv[]) { 30 30 semaphore lock = { 0 }; 31 sout | "User main begin" ;31 sout | "User main begin" | endl; 32 32 { 33 33 processor p; … … 37 37 } 38 38 } 39 sout | "User main end" ;39 sout | "User main end" | endl; 40 40 } -
tests/concurrent/waitfor/barge.c
r85acec94 r90cfc16 48 48 yield(random( 10 )); 49 49 if( this.state != WAITFOR && !this.done && this.started ) { 50 serr | "Barging before caller detected" ;50 serr | "Barging before caller detected" | endl; 51 51 } 52 52 … … 66 66 this.state = WAITFOR; 67 67 waitfor(do_call, this) { 68 sout | i ;68 sout | i | endl; 69 69 } 70 70 71 71 if( this.state != CALL ) { 72 serr | "Barging after caller detected" ;72 serr | "Barging after caller detected" | endl; 73 73 } 74 74 } … … 83 83 84 84 int main() { 85 sout | "Starting" ;85 sout | "Starting" | endl; 86 86 { 87 87 barger_t bargers[17]; … … 89 89 waiter_t waiters; 90 90 } 91 sout | "Stopping" ;91 sout | "Stopping" | endl; 92 92 } -
tests/concurrent/waitfor/dtor.c
r85acec94 r90cfc16 29 29 switch(state) { 30 30 case CTOR : break; 31 case MAIN : if( this.state != CTOR ) { serr | "ERROR Expected state to be CTOR" ; abort(); } this.state = state; break;32 case AFTER : if( this.state != MAIN ) { serr | "ERROR Expected state to be MAIN" ; abort(); } this.state = state; break;33 case END : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER" ; abort(); } this.state = state; break;34 case DTOR : if( this.state != END ) { serr | "ERROR Expected state to be END" ; abort(); } this.state = state; break;31 case MAIN : if( this.state != CTOR ) { serr | "ERROR Expected state to be CTOR" | endl; abort(); } this.state = state; break; 32 case AFTER : if( this.state != MAIN ) { serr | "ERROR Expected state to be MAIN" | endl; abort(); } this.state = state; break; 33 case END : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER" | endl; abort(); } this.state = state; break; 34 case DTOR : if( this.state != END ) { serr | "ERROR Expected state to be END" | endl; abort(); } this.state = state; break; 35 35 } 36 36 } … … 54 54 55 55 int main() { 56 sout | "Starting" ;56 sout | "Starting" | endl; 57 57 processor p; 58 58 for( int i = 0; i < N; i++ ){ … … 60 60 yield( random( 100 ) ); 61 61 } 62 sout | "Stopping" ;62 sout | "Stopping" | endl; 63 63 } -
tests/concurrent/waitfor/else.c
r85acec94 r90cfc16 12 12 void test( M & mutex m ) { 13 13 int i = 0; 14 sout | "Starting" ;14 sout | "Starting" | endl; 15 15 16 16 when( false ) waitfor( notcalled, m ); 17 17 18 sout | "Step" | i++ ;18 sout | "Step" | i++ | endl; 19 19 20 20 waitfor( notcalled, m ); or else { 21 sout | "else called" ;21 sout | "else called" | endl; 22 22 } 23 23 24 sout | "Step" | i++ ;24 sout | "Step" | i++ | endl; 25 25 26 26 when( true ) waitfor( notcalled, m ); or when( true ) else { 27 sout | "else called" ;27 sout | "else called" | endl; 28 28 } 29 29 30 sout | "Step" | i++ ;30 sout | "Step" | i++ | endl; 31 31 32 32 when( false ) waitfor( notcalled, m ); or when( true ) else { 33 sout | "else called" ;33 sout | "else called" | endl; 34 34 } 35 35 36 sout | "Step" | i++ ;36 sout | "Step" | i++ | endl; 37 37 38 38 when( false ) waitfor( notcalled, m ); or when( false ) else { 39 sout | "else called" ;39 sout | "else called" | endl; 40 40 } 41 41 42 sout | "Done" ;42 sout | "Done" | endl; 43 43 } 44 44 -
tests/concurrent/waitfor/recurse.c
r85acec94 r90cfc16 95 95 rand_yield(); 96 96 97 sout | "1st" | nl;97 sout | "1st" | endl; 98 98 99 99 return this.counter < N ? (state_t)this.actions[idx] : (state_t)STOP; … … 123 123 case THIRD : while( !global.ready ) { yield(); } this.state = call3( global, this.idx ); break; 124 124 case LAST : while( !global.ready ) { yield(); } this.state = call4( global, this.idx ); break; 125 case STOP : serr | "This should not happen" | nl;125 case STOP : serr | "This should not happen" | endl; 126 126 } 127 127 } … … 132 132 int main() { 133 133 srandom( time(NULL) ); 134 sout | nlOff; // turn off auto newline 135 sout | "Starting" | nl; 134 sout | "Starting" | endl; 136 135 { 137 136 waiter_t waiters[4] = { … … 143 142 the_threads = waiters; 144 143 } 145 sout | "Stopping" | nl;144 sout | "Stopping" | endl; 146 145 } -
tests/concurrent/waitfor/simple.c
r85acec94 r90cfc16 31 31 32 32 void do_wait( global_t * mutex a ) { 33 sout | "Waiting to accept" ;33 sout | "Waiting to accept" | endl; 34 34 yield( random( 10 ) ); 35 35 36 sout | "Accepting" ;36 sout | "Accepting" | endl; 37 37 38 38 __acceptable_t acceptable; … … 43 43 __waitfor_internal( 1, &acceptable ); 44 44 45 sout | "Accepted" ;45 sout | "Accepted" | endl; 46 46 yield( random( 10 ) ); 47 47 } … … 50 50 for( int i = 0; i < N; i++ ) { 51 51 do_wait( &globalA ); 52 sout | i ;52 sout | i | endl; 53 53 } 54 54 … … 76 76 srandom( time( NULL ) ); 77 77 printf("%p\n", &globalA); 78 sout | "Starting" ;78 sout | "Starting" | endl; 79 79 { 80 80 Acceptor r; … … 82 82 83 83 } 84 sout | "Done" ;84 sout | "Done" | endl; 85 85 } -
tests/concurrent/waitfor/statment.c
r85acec94 r90cfc16 84 84 case 7: return call7( m ); 85 85 default : 86 serr | "Incorrect index" | index ;86 serr | "Incorrect index" | index | endl; 87 87 abort(); 88 88 } … … 102 102 while( !done ) { 103 103 waitfor( get_index, this ); 104 or waitfor( call1, this ) { sout | "Statement" ; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val; } }105 or waitfor( call2, this ) { sout | "Statement" ; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val; } }106 or waitfor( call3, this ) { sout | "Statement" ; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val; } }107 or waitfor( call4, this ) { sout | "Statement" ; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val; } }108 or waitfor( call5, this ) { sout | "Statement" ; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val; } }109 or waitfor( call6, this ) { sout | "Statement" ; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val; } }110 or waitfor( call7, this ) { sout | "Statement" ; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val; } }104 or waitfor( call1, this ) { sout | "Statement" | endl; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val | endl; } } 105 or waitfor( call2, this ) { sout | "Statement" | endl; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val | endl; } } 106 or waitfor( call3, this ) { sout | "Statement" | endl; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val | endl; } } 107 or waitfor( call4, this ) { sout | "Statement" | endl; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val | endl; } } 108 or waitfor( call5, this ) { sout | "Statement" | endl; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val | endl; } } 109 or waitfor( call6, this ) { sout | "Statement" | endl; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val | endl; } } 110 or waitfor( call7, this ) { sout | "Statement" | endl; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val | endl; } } 111 111 112 112 done = true; … … 128 128 int main() { 129 129 processor p[2]; 130 sout | "Starting" ;130 sout | "Starting" | endl; 131 131 { 132 132 caller c[7]; 133 133 waiter w; 134 134 } 135 sout | "Stopping" ;135 sout | "Stopping" | endl; 136 136 } -
tests/concurrent/waitfor/when.c
r85acec94 r90cfc16 58 58 void arbiter( global_t & mutex this ) { 59 59 for( int i = 0; i < N; i++ ) { 60 when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call ; } }61 or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call ; } }62 or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call ; } }63 or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call ; } }64 or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call ; } }65 or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call ; } }60 when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call | endl; } } 61 or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call | endl; } } 62 or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call | endl; } } 63 or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call | endl; } } 64 or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call | endl; } } 65 or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call | endl; } } 66 66 67 sout | this.last_call ;67 sout | this.last_call | endl; 68 68 } 69 69 … … 78 78 int main() { 79 79 srandom( time(NULL) ); 80 sout | "Starting" ;80 sout | "Starting" | endl; 81 81 { 82 82 arbiter_t arbiter; … … 84 84 85 85 } 86 sout | "Stopping" ;86 sout | "Stopping" | endl; 87 87 } -
tests/coroutine/.expect/fmtLines.txt
r85acec94 r90cfc16 16 16 difi ed B y : Pete r A. 17 17 Buh r// Last Mod ifie 18 d On : T ue D ec 1 1 2319 :3 1: 12 2 018/ / Up date20 Cou nt : 3 2/ /#in18 d On : M on S ep 1 8 11 19 :35: 57 2 017/ / Up date 20 Cou nt : 31/ /#in 21 21 clud e <f stre am.h fa># 22 22 incl ude <cor outi ne.h … … 34 34 t ) { if ( fm t.g 35 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(); if ( fm 51 t.ch != '\n' ) b reak 52 ; / / ig nore new line 53 } // for sout 54 | f mt.c h; // 55 prin t ch arac ter } 56 // f or sou t | " " 57 ; // prin t bl 58 ock sepa rato r } // 59 for sou t | nl; 60 // p rint gro up s 61 epar ator } / / fo r} / 62 / ma invo id p rt( Form 63 at & fmt , ch ar c h ) 64 { fmt .ch = ch ; 65 res ume( fmt );} // 66 prti nt m ain( ) { Form 67 at f mt; char ch; for 68 ( ; ; ) { s in | ch; 69 // rea d on 70 e ch arac ter if ( e 71 of( sin ) ) brea k; 72 // eof ? p rt( 73 fmt, ch ); } // for} 74 // main // L ocal Var 75 iabl es: //// tab -wid 76 th: 4 // // c ompi le-c 77 omma nd: "cfa fmt Line 78 s.c" /// / En d: / / 36 sou t | endl ;}vo id m 37 ain( For mat & fm t ) 38 { fo r ( ;; ) { 39 // f or a s ma ny c 40 hara cter s f or ( fmt 41 .g = 0; fmt. g < 5; f 42 mt.g += 1 ) { / / gr 43 oups of 5 bl ocks f 44 or ( fmt .b = 0; fmt. 45 b < 4; f mt.b += 1 ) 46 { // blo cks of 4 cha 47 ract ers f or ( ;; 48 ) { // for new 49 line cha ract ers 50 susp end( ); i f ( 51 fmt. ch ! = '\ n' ) bre 52 ak; // igno re n ewli 53 ne } // f or so 54 ut | fmt .ch; / 55 / pr int char acte r 56 } // for s out | " 57 "; / / pr int 58 bloc k se para tor } / 59 / fo r s out | en dl; 60 // p rint gro 61 up s epar ator } / / fo 62 r} / / ma invo id p rt( 63 Form at & fmt , ch ar c 64 h ) { fmt .ch = ch 65 ; res ume( fmt );} 66 // prti nt m ain( ) { 67 Form at f mt; char ch; 68 for ( ; ; ) { s in | 69 ch; // rea 70 d on e ch arac ter if 71 ( e of( sin ) ) brea 72 k; // eof ? p 73 rt( fmt, ch ); } // 74 for} // main // L ocal 75 Var iabl es: //// tab 76 -wid th: 4 // // c ompi 77 le-c omma nd: "cfa fmt 78 Line s.c" /// / En d: / 79 / -
tests/coroutine/.in/fmtLines.txt
r85acec94 r90cfc16 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 23:31:12 201813 // Update Count : 3 212 // Last Modified On : Mon Sep 18 11:35:57 2017 13 // Update Count : 31 14 14 // 15 15 … … 27 27 28 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl;29 if ( fmt.g != 0 || fmt.b != 0 ) sout | endl; 30 30 } 31 31 … … 42 42 sout | " "; // print block separator 43 43 } // for 44 sout | nl; // print group separator44 sout | endl; // print group separator 45 45 } // for 46 46 } // main -
tests/coroutine/fibonacci.c
r85acec94 r90cfc16 10 10 // Created On : Thu Jun 8 07:29:37 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:57:33201813 // Update Count : 2 512 // Last Modified On : Sat Aug 18 11:21:58 2018 13 // Update Count : 24 14 14 // 15 15 … … 39 39 Fibonacci f1, f2; 40 40 for ( 10 ) { // print N Fibonacci values 41 sout | next( f1 ) | next( f2 ) ;41 sout | next( f1 ) | next( f2 ) | endl; 42 42 } // for 43 43 } -
tests/coroutine/fibonacci_1.c
r85acec94 r90cfc16 10 10 // Created On : Thu Apr 26 23:20:08 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:57:54201813 // Update Count : 1 412 // Last Modified On : Sat Aug 18 11:21:02 2018 13 // Update Count : 13 14 14 // 15 15 … … 36 36 Fibonacci f1, f2; 37 37 for ( 10 ) { // print N Fibonacci values 38 sout | next( f1 ) | next( f2 ) ;38 sout | next( f1 ) | next( f2 ) | endl; 39 39 } // for 40 40 } -
tests/coroutine/fmtLines.c
r85acec94 r90cfc16 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 21:58:49201813 // Update Count : 4 712 // Last Modified On : Thu Aug 16 08:20:54 2018 13 // Update Count : 45 14 14 // 15 15 … … 34 34 sout | " "; // print block separator 35 35 } // for 36 sout | nl;// print group separator36 sout | endl; // print group separator 37 37 } // for 38 38 } // main … … 43 43 44 44 void ^?{}( Format & fmt ) with( fmt ) { 45 if ( g != 0 || b != 0 ) sout | nl;45 if ( g != 0 || b != 0 ) sout | endl; 46 46 } 47 47 … … 52 52 int main() { 53 53 Format fmt; 54 sout | nlOff; // turn off auto newline55 54 56 55 eof: for () { // read until end of file -
tests/coroutine/pingpong.c
r85acec94 r90cfc16 10 10 // Created On : Wed Sep 20 11:55:23 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:58:06201813 // Update Count : 2 912 // Last Modified On : Sat Aug 18 11:31:11 2018 13 // Update Count : 28 14 14 // 15 15 … … 40 40 void main( PingPong & pingpong ) { // ping's starter ::main, pong's starter ping 41 41 for ( pingpong.N ) { // N ping-pongs 42 sout | pingpong.name ;42 sout | pingpong.name | endl; 43 43 cycle( *pingpong.part ); 44 44 } // for -
tests/coroutine/prodcons.c
r85acec94 r90cfc16 10 10 // Created On : Mon Sep 18 12:23:39 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:58:25201813 // Update Count : 5 212 // Last Modified On : Sat Aug 18 12:55:10 2018 13 // Update Count : 51 14 14 // 15 15 … … 32 32 int p1 = random( 100 ); 33 33 int p2 = random( 100 ); 34 sout | p1 | " " | p2 ;34 sout | p1 | " " | p2 | endl; 35 35 int status = delivery( *c, p1, p2 ); 36 sout | " $" | money ;37 sout | status ;36 sout | " $" | money | endl; 37 sout | status | endl; 38 38 receipt += 1; 39 39 } 40 40 stop( *c ); 41 sout | "prod stops" ;41 sout | "prod stops" | endl; 42 42 } 43 43 int payment( Prod & prod, int money ) { … … 68 68 int money = 1, receipt; 69 69 for ( ; ! done; ) { 70 sout | p1 | " " | p2 ;71 sout | " $" | money ;70 sout | p1 | " " | p2 | endl; 71 sout | " $" | money | endl; 72 72 status += 1; 73 73 receipt = payment( *p, money ); 74 sout | " #" | receipt ;74 sout | " #" | receipt | endl; 75 75 money += 1; 76 76 } 77 sout | "cons stops" ;77 sout | "cons stops" | endl; 78 78 } 79 79 int delivery( Cons & cons, int p1, int p2 ) { … … 92 92 srandom( /* getpid() */ 103 ); // fixed seed for testing 93 93 start( prod, 5, cons ); 94 sout | "main stops" ;94 sout | "main stops" | endl; 95 95 } 96 96 -
tests/coroutine/runningTotal.c
r85acec94 r90cfc16 10 10 // Created On : Wed Dec 6 08:05:27 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 21:59:00201813 // Update Count : 412 // Last Modified On : Thu Aug 16 08:22:29 2018 13 // Update Count : 3 14 14 // 15 15 … … 42 42 RunTotal rntl; 43 43 for ( i; 10 ) { 44 sout | i | add( rntl, i ) ;44 sout | i | add( rntl, i ) | endl; 45 45 } // for 46 46 } -
tests/div.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Aug 8 16:28:43 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:35:01201813 // Update Count : 2012 // Last Modified On : Tue Nov 6 17:53:10 2018 13 // Update Count : 19 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // div17 #include <stdlib.hfa> // div 18 18 19 19 struct T { int i; }; … … 23 23 24 24 int main( void ) { 25 sout | "div" | div( 13, 5 ) | div( 13L, 5L ) | div( 13LL, 5LL ) ;25 sout | "div" | div( 13, 5 ) | div( 13L, 5L ) | div( 13LL, 5LL ) | endl; 26 26 short s1 = 13, s2 = 5; 27 sout | "div" | div( s1, s2 ) ;27 sout | "div" | div( s1, s2 ) | endl; 28 28 T t1 = { 13 }, t2 = { 5 }; 29 sout | "div" | div( t1, t2 ) ;// polymorphic div29 sout | "div" | div( t1, t2 ) | endl; // polymorphic div 30 30 } // main 31 31 -
tests/except-0.cfa
r85acec94 r90cfc16 25 25 void ^?{}(signal_exit * this) { 26 26 printf("Exiting: %s\n", this->area); 27 // sout | "Exiting:" | this->area ;27 // sout | "Exiting:" | this->area | endl; 28 28 } 29 29 -
tests/fallthrough.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Mar 14 10:06:25 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 4 21:36:14201813 // Update Count : 1 712 // Last Modified On : Thu Nov 8 09:09:09 2018 13 // Update Count : 16 14 14 // 15 15 … … 19 19 choose ( choice ) { 20 20 case 1: 21 sout | "case 1" ;21 sout | "case 1" | endl; 22 22 fallthru; 23 23 case 2: 24 sout | "case 2" ;24 sout | "case 2" | endl; 25 25 fallthru; 26 sout | "did not fallthru" ;26 sout | "did not fallthru" | endl; 27 27 if ( 7 ) fallthru common2; 28 28 fallthru common1; 29 29 case 3: 30 sout | "case 3" ;30 sout | "case 3" | endl; 31 31 fallthru default; 32 32 fallthru common1; 33 33 common1: 34 sout | "common1" ;34 sout | "common1" | endl; 35 35 // break 36 36 case 4: 37 sout | "case 4" ;37 sout | "case 4" | endl; 38 38 fallthru common2; 39 39 case 5: 40 sout | "case 5" ;40 sout | "case 5" | endl; 41 41 fallthru common2; 42 42 fallthru default; 43 43 case 6: 44 sout | "case 6" ;44 sout | "case 6" | endl; 45 45 fallthru common2; 46 46 common2: 47 sout | "common2" ;47 sout | "common2" | endl; 48 48 // break 49 49 default: 50 sout | "default" ;50 sout | "default" | endl; 51 51 fallthru; 52 52 } 53 53 54 sout | nl;54 sout | endl; 55 55 56 56 switch ( choice ) { 57 57 case 1: 58 sout | "case 1" ;58 sout | "case 1" | endl; 59 59 switch ( choice ) { 60 60 case 1: 61 sout | "case 1" ;61 sout | "case 1" | endl; 62 62 for ( int i = 0; i < 4; i += 1 ) { 63 63 printf("%d\n", i); … … 67 67 break; 68 68 case 5: 69 sout | "case 5" ;69 sout | "case 5" | endl; 70 70 if ( choice == 5 ) { 71 71 if ( choice != 5 ) { 72 sout | "error" ;72 sout | "error" | endl; 73 73 } else { 74 sout | "check" ;74 sout | "check" | endl; 75 75 fallthru common; 76 76 } // if … … 117 117 int main() { 118 118 test( 1 ); 119 sout | nl;119 sout | endl; 120 120 test( 5 ); 121 121 } -
tests/fstream_test.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:36:34201813 // Update Count : 6 712 // Last Modified On : Tue Nov 6 17:53:56 2018 13 // Update Count : 66 14 14 // 15 15 … … 18 18 int main( void ) { 19 19 int nombre; 20 sout | "Entrez un nombre, s'il vous plaît:" ;20 sout | "Entrez un nombre, s'il vous plaît:" | endl; 21 21 sin | nombre; 22 sout | "Vous avez entré" | nombre ;22 sout | "Vous avez entré" | nombre | endl; 23 23 sout | "le nombre" | nombre | "est" 24 | (nombre > 0 ? "positif" : nombre == 0 ? "zéro" : "négatif") ;24 | (nombre > 0 ? "positif" : nombre == 0 ? "zéro" : "négatif") | endl; 25 25 26 sout | "Entrez trois nombres, s'il vous plaît: " ;26 sout | "Entrez trois nombres, s'il vous plaît: " | endl; 27 27 int i, j, k; 28 28 sin | i | j | k; 29 sout | "Vous avez entré" | "i:" | "" | i | "j:" | "" | j | "k:" | "" | k ;29 sout | "Vous avez entré" | "i:" | "" | i | "j:" | "" | j | "k:" | "" | k | endl; 30 30 } 31 31 -
tests/function-operator.cfa
r85acec94 r90cfc16 10 10 // Created On : Fri Aug 25 15:21:11 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 4 21:37:09201813 // Update Count : 912 // Last Modified On : Thu Aug 2 09:27:53 2018 13 // Update Count : 8 14 14 // 15 15 … … 83 83 // TODO: abstract over (os, T) 84 84 os_wrapper ?=?(os_wrapper & wrapper, int x) { 85 *wrapper.out | x ;85 *wrapper.out | x | endl; 86 86 return wrapper; 87 87 } -
tests/gmp.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Apr 19 08:55:51 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:37:29201813 // Update Count : 55 812 // Last Modified On : Tue Nov 6 17:54:34 2018 13 // Update Count : 557 14 14 // 15 15 … … 19 19 20 20 int main( void ) { 21 sout | "constructors" ;21 sout | "constructors" | endl; 22 22 short int si = 3; 23 23 Int x = { "50000000000000000000" }, y = { si }, z = x + y; 24 sout | x | y | z ;25 sout | "x:" | x | "y:" | y | "z:" | z ;24 sout | x | y | z | endl; 25 sout | "x:" | x | "y:" | y | "z:" | z | endl; 26 26 27 sout | "conversions" ;27 sout | "conversions" | endl; 28 28 y = 'a'; 29 sout | "y:" | y ;29 sout | "y:" | y | endl; 30 30 y = "12345678901234567890123456789"; 31 sout | "y:" | y ;31 sout | "y:" | y | endl; 32 32 y = 100`mp + 100`mp; 33 sout | "y:" | y ;33 sout | "y:" | y | endl; 34 34 y = -200u`mp + -200u`mp; 35 sout | "y:" | y ;35 sout | "y:" | y | endl; 36 36 y = "12345678901234567890123456789"`mp + "12345678901234567890123456789"`mp; 37 sout | "y:" | y ;37 sout | "y:" | y | endl; 38 38 y = si; 39 sout | "y:" | y ;39 sout | "y:" | y | endl; 40 40 y = -3; 41 sout | "y:" | y ;41 sout | "y:" | y | endl; 42 42 y += 7; 43 sout | "y:" | y ;43 sout | "y:" | y | endl; 44 44 y -= 1; 45 sout | "y:" | y ;45 sout | "y:" | y | endl; 46 46 int b; 47 47 b = y; 48 48 si = y; 49 sout | "y:" | y | "b:" | b | "si:" | si ;49 sout | "y:" | y | "b:" | b | "si:" | si | endl; 50 50 51 sout | "comparison" ;52 sout | x == x ;53 sout | x != x ;54 sout | x < x ;55 sout | x <= x ;56 sout | x > x ;57 sout | x >= x ;51 sout | "comparison" | endl; 52 sout | x == x | endl; 53 sout | x != x | endl; 54 sout | x < x | endl; 55 sout | x <= x | endl; 56 sout | x > x | endl; 57 sout | x >= x | endl; 58 58 59 sout | "arithmetic" ;59 sout | "arithmetic" | endl; 60 60 z = x + y + z; 61 sout | "z:" | z ;61 sout | "z:" | z | endl; 62 62 z = z = x; 63 sout | "z:" | z ;63 sout | "z:" | z | endl; 64 64 z = x - y - z; 65 sout | "z:" | z ;65 sout | "z:" | z | endl; 66 66 z = x * y * z; 67 sout | "z:" | z ;67 sout | "z:" | z | endl; 68 68 z = x * 3; 69 sout | "z:" | z ;69 sout | "z:" | z | endl; 70 70 z = 3 * x; 71 sout | "z:" | z ;71 sout | "z:" | z | endl; 72 72 z = x / 3; 73 sout | "z:" | z ;74 sout | div( x, 3 ) | x / 3 | "," | x % 3 ;73 sout | "z:" | z | endl; 74 sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl; 75 75 [ x, y ] = div( x, 3 ); 76 sout | "x:" | x | "y:" | y ;76 sout | "x:" | x | "y:" | y | endl; 77 77 78 sout ;78 sout | endl; 79 79 80 80 sin | x | y | z; 81 sout | x | y | z ;81 sout | x | y | z | endl; 82 82 83 sout ;83 sout | endl; 84 84 85 sout | "Fibonacci Numbers" ;85 sout | "Fibonacci Numbers" | endl; 86 86 Int fn, fn1, fn2; 87 87 fn = (Int){0}; fn1 = fn; // 1st case 88 sout | (int)0 | fn ;88 sout | (int)0 | fn | endl; 89 89 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 90 sout | 1 | fn ;90 sout | 1 | fn | endl; 91 91 for ( i; 2u ~= 200 ) { 92 92 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 93 sout | i | fn ;93 sout | i | fn | endl; 94 94 } // for 95 95 96 sout ;96 sout | endl; 97 97 98 sout | "Factorial Numbers" ;98 sout | "Factorial Numbers" | endl; 99 99 Int fact = 1; // 1st case 100 sout | (int)0 | fact ;100 sout | (int)0 | fact | endl; 101 101 for ( i; 1u ~= 40u ) { 102 102 fact *= i; // general case 103 sout | i | fact ;103 sout | i | fact | endl; 104 104 } // for 105 105 } // main -
tests/heap.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Nov 6 17:54:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 21:52:40201813 // Update Count : 1 812 // Last Modified On : Thu Nov 8 09:03:54 2018 13 // Update Count : 17 14 14 // 15 15 … … 45 45 for ( i; NoOfAllocs ) { 46 46 locns[i] = alloc( i ); 47 //sout | (void *)locns[i] ;47 //sout | (void *)locns[i] | endl; 48 48 for ( k; i ) locns[i][k] = '\345'; 49 49 } // for 50 //sout | (char *)sbrk(0) - start | " bytes" ;50 //sout | (char *)sbrk(0) - start | " bytes" | endl; 51 51 52 52 for ( i; NoOfAllocs ) { 53 //sout | (void *)locns[i] ;53 //sout | (void *)locns[i] | endl; 54 54 for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" ); 55 55 free( locns[i] ); 56 56 } // for 57 //sout | (char *)sbrk(0) - start | " bytes" ;57 //sout | (char *)sbrk(0) - start | " bytes" | endl; 58 58 59 59 for ( i; NoOfAllocs ) { 60 60 locns[i] = alloc( i ); 61 //sout | (void *)locns[i] ;61 //sout | (void *)locns[i] | endl; 62 62 for ( k; i ) locns[i][k] = '\345'; 63 63 } // for 64 64 for ( i; NoOfAllocs - 1 -~= 0 ) { 65 //sout | (void *)locns[i] ;65 //sout | (void *)locns[i] | endl; 66 66 for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" ); 67 67 free( locns[i] ); … … 186 186 187 187 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 188 //sout | alignments[a] ;188 //sout | alignments[a] | endl; 189 189 for ( s; 1 ~ NoOfAllocs ) { // allocation of size 0 can return null 190 190 char * area = (char *)memalign( a, s ); 191 191 if ( area == 0 ) abort( "memalign/free out of memory" ); 192 //sout | i | " " | area ;192 //sout | i | " " | area | endl; 193 193 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 194 194 abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, s, area ); … … 203 203 204 204 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 205 //sout | alignments[a] ;205 //sout | alignments[a] | endl; 206 206 for ( i; 1 ~ NoOfMmaps ) { 207 207 size_t s = i + default_mmap_start(); // cross over point 208 208 char * area = (char *)memalign( a, s ); 209 209 if ( area == 0 ) abort( "memalign/free out of memory" ); 210 //sout | i | " " | area ;210 //sout | i | " " | area | endl; 211 211 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 212 212 abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)s, area ); … … 268 268 char * area = (char *)memalign( a, amount ); // aligned N-byte allocation 269 269 if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ? 270 //sout | alignments[a] | " " | area ;270 //sout | alignments[a] | " " | area | endl; 271 271 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 272 272 abort( "memalign/realloc/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)amount, area ); … … 279 279 area = (char *)realloc( area, s ); // attempt to reuse storage 280 280 if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ? 281 //sout | i | " " | area ;281 //sout | i | " " | area | endl; 282 282 if ( (size_t)area % a != 0 ) { // check for initial alignment 283 283 abort( "memalign/realloc/free bad alignment %p", area ); … … 291 291 292 292 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 293 //sout | alignments[a] ;293 //sout | alignments[a] | endl; 294 294 for ( s; 1 ~ limit ) { // allocation of size 0 can return null 295 295 char * area = (char *)cmemalign( a, 1, s ); 296 296 if ( area == 0 ) abort( "cmemalign/free out of memory" ); 297 //sout | i | " " | area ;297 //sout | i | " " | area | endl; 298 298 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 299 299 abort( "cmemalign/free bad alignment : cmemalign(%d,%d) = %p", (int)a, s, area ); … … 314 314 char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation 315 315 if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ? 316 //sout | alignments[a] | " " | area ;316 //sout | alignments[a] | " " | area | endl; 317 317 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 318 318 abort( "cmemalign/realloc/free bad alignment : cmemalign(%d,%d) = %p", (int)a, (int)amount, area ); … … 328 328 area = (char *)realloc( area, s ); // attempt to reuse storage 329 329 if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ? 330 //sout | i | " " | area ;330 //sout | i | " " | area | endl; 331 331 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 332 332 abort( "cmemalign/realloc/free bad alignment %p", area ); … … 339 339 free( area ); 340 340 } // for 341 //sout | "worker" | thisTask() | "successful completion" ;341 //sout | "worker" | thisTask() | "successful completion" | endl; 342 342 } // Worker main 343 343 -
tests/hello.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:38:39201813 // Update Count : 1 712 // Last Modified On : Tue Nov 6 17:56:22 2018 13 // Update Count : 16 14 14 // 15 15 … … 17 17 18 18 int main() { 19 sout | "Hello world!" ;20 sout | "Bonjour le monde!" ;21 sout | "Hola Mundo!" ;22 sout | "Hallo Welt!" ;23 sout | "Kaixo Mundua!" ;24 sout | "Chào thế giới!" ;25 sout | "Привет мир!" ;26 sout | "שלום עולם!" ;27 sout | "你好,世界!" ;28 sout | "こんにちは世界!" ;29 sout | "안녕하세요 세계!" ;30 sout | "नमस्ते दुनिया!" ;19 sout | "Hello world!" | endl; 20 sout | "Bonjour le monde!" | endl; 21 sout | "Hola Mundo!" | endl; 22 sout | "Hallo Welt!" | endl; 23 sout | "Kaixo Mundua!" | endl; 24 sout | "Chào thế giới!" | endl; 25 sout | "Привет мир!" | endl; 26 sout | "שלום עולם!" | endl; 27 sout | "你好,世界!" | endl; 28 sout | "こんにちは世界!" | endl; 29 sout | "안녕하세요 세계!" | endl; 30 sout | "नमस्ते दुनिया!" | endl; 31 31 } 32 32 -
tests/identity.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:38:59201813 // Update Count : 2012 // Last Modified On : Tue Nov 6 17:56:54 2018 13 // Update Count : 19 14 14 // 15 15 … … 22 22 23 23 int main() { 24 sout | "char\t\t\t" | identity( 'z' ) ;25 sout | "signed int\t\t" | identity( 4 ) ;26 sout | "unsigned int\t\t" | identity( 4u ) ;27 sout | "signed long int\t\t" | identity( 4l ) ;28 sout | "unsigned long int\t" | identity( 4ul ) ;29 sout | "signed long long int\t" | identity( 4ll ) ;30 sout | "unsigned long long int\t" | identity( 4ull ) ;31 sout | "float\t\t\t" | identity( 4.1f ) ;32 sout | "double\t\t\t" | identity( 4.1 ) ;33 sout | "long double\t\t" | identity( 4.1l ) ;34 sout | "float _Complex\t\t" | identity( -4.1F-2.0iF ) ;35 sout | "double _Complex\t\t" | identity( -4.1D-2.0iD ) ;36 sout | "long double _Complex\t" | identity( -4.1L-2.0iL ) ;24 sout | "char\t\t\t" | identity( 'z' ) | endl; 25 sout | "signed int\t\t" | identity( 4 ) | endl; 26 sout | "unsigned int\t\t" | identity( 4u ) | endl; 27 sout | "signed long int\t\t" | identity( 4l ) | endl; 28 sout | "unsigned long int\t" | identity( 4ul ) | endl; 29 sout | "signed long long int\t" | identity( 4ll ) | endl; 30 sout | "unsigned long long int\t" | identity( 4ull ) | endl; 31 sout | "float\t\t\t" | identity( 4.1f ) | endl; 32 sout | "double\t\t\t" | identity( 4.1 ) | endl; 33 sout | "long double\t\t" | identity( 4.1l ) | endl; 34 sout | "float _Complex\t\t" | identity( -4.1F-2.0iF ) | endl; 35 sout | "double _Complex\t\t" | identity( -4.1D-2.0iD ) | endl; 36 sout | "long double _Complex\t" | identity( -4.1L-2.0iL ) | endl; 37 37 } 38 38 -
tests/ifwhileCtl.cfa
r85acec94 r90cfc16 10 10 // Created On : Sat Aug 26 10:13:11 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:39:18201813 // Update Count : 2 312 // Last Modified On : Tue Nov 6 17:57:07 2018 13 // Update Count : 22 14 14 // 15 15 … … 22 22 23 23 if ( int x = 1 ) { 24 sout | "x != 0 correct" ;24 sout | "x != 0 correct" | endl; 25 25 } else { 26 sout | "x == 0 incorrect" ;26 sout | "x == 0 incorrect" | endl; 27 27 } // if 28 28 29 29 if ( int x = 4, y = 0 ) { 30 sout | "x != 0 && y != 0 incorrect" ;30 sout | "x != 0 && y != 0 incorrect" | endl; 31 31 } else if ( int x = 4, y = 1 ) { 32 sout | "x != 0 && y != 0 correct" ;32 sout | "x != 0 && y != 0 correct" | endl; 33 33 } else { 34 sout | "x == 0 || y == 0 incorrect" ;34 sout | "x == 0 || y == 0 incorrect" | endl; 35 35 } // if 36 36 37 37 if ( int x = 5, y = f( x ); x == y ) { 38 sout | "x == y correct" ;38 sout | "x == y correct" | endl; 39 39 } else { 40 sout | "x != y incorrect" ;40 sout | "x != y incorrect" | endl; 41 41 } // if 42 42 43 43 if ( struct S { int i; } s = { 3 }; s.i < 4 ) { 44 44 S s1; 45 sout | "s.i < 4 correct" ;45 sout | "s.i < 4 correct" | endl; 46 46 } else { 47 47 S s1; 48 sout | "s.i >= 4 incorrect" ;48 sout | "s.i >= 4 incorrect" | endl; 49 49 } // if 50 50 51 51 while ( int x = 1 ) { 52 sout | "x != 0 correct" ;52 sout | "x != 0 correct" | endl; 53 53 break; 54 54 } // while 55 55 56 56 while ( int x = 4, y = 0 ) { 57 sout | "x != 0 && y != 0 incorrect" ;57 sout | "x != 0 && y != 0 incorrect" | endl; 58 58 } // while 59 59 60 60 while ( int x = 5, y = f( x ); x == y ) { 61 sout | "x == y correct" ;61 sout | "x == y correct" | endl; 62 62 break; 63 63 } // while … … 65 65 while ( struct S { int i; } s = { 3 }; s.i < 4 ) { 66 66 S s1; 67 sout | "s.i < 4 correct" ;67 sout | "s.i < 4 correct" | endl; 68 68 break; 69 69 } // while -
tests/io1.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:40:28201813 // Update Count : 10 612 // Last Modified On : Tue Nov 6 17:57:17 2018 13 // Update Count : 105 14 14 // 15 15 … … 18 18 int main() { 19 19 int x = 3, y = 5, z = 7; 20 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) ;21 sout | 1 | 2 | 3 ;22 sout | '1' | '2' | '3' ;23 sout | 1 | "" | 2 | "" | 3 ;24 sout ;20 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 21 sout | 1 | 2 | 3 | endl; 22 sout | '1' | '2' | '3' | endl; 23 sout | 1 | "" | 2 | "" | 3 | endl; 24 sout | endl; 25 25 26 sout | "opening delimiters" ;26 sout | "opening delimiters" | endl; 27 27 sout 28 28 | "x (" | 1 … … 36 36 | "x ¿" | 9 37 37 | "x «" | 10 38 | nl;38 | endl | endl; 39 39 40 sout | "closing delimiters" ;40 sout | "closing delimiters" | endl; 41 41 sout 42 42 | 1 | ", x" … … 51 51 | 10 | "] x" 52 52 | 11 | "} x" 53 | nl;53 | endl | endl; 54 54 55 sout | "opening/closing delimiters" ;55 sout | "opening/closing delimiters" | endl; 56 56 sout 57 57 | "x`" | 1 | "`x'" | 2 … … 61 61 | "\vx\n" | 9 | "\nx\r" | 10 62 62 | "\rx" 63 | nl;63 | endl | endl; 64 64 65 sout | "override opening/closing delimiters" ;66 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 ;67 sout ;65 sout | "override opening/closing delimiters" | endl; 66 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; 67 sout | endl; 68 68 } 69 69 -
tests/io2.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:51:52201813 // Update Count : 10 912 // Last Modified On : Tue Nov 6 17:57:28 2018 13 // Update Count : 104 14 14 // 15 15 16 16 #include <fstream.hfa> 17 17 18 #define xstr(s) str(s)18 #define xstr(s) str(s) 19 19 #define str(s) #s 20 20 … … 41 41 char s1[size], s2[size]; 42 42 43 ifstream in = { xstr(IN_DIR) "io.data" }; // create / open file43 ifstream in = { xstr(IN_DIR) "io.data" }; // create / open file 44 44 45 sout | "input bacis types" ;45 sout | "input bacis types" | endl; 46 46 in | b // boolean 47 47 | c | sc | usc // character … … 50 50 | fc | dc | ldc // floating-point complex 51 51 | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked 52 sout | nl;52 sout | endl; 53 53 54 sout | "output basic types" ;55 sout | b | nl // boolean56 | c | ' ' | sc | ' ' | usc | nl // character57 | si | usi | i | ui | li | uli | lli | ulli | nl // integral58 | f | d | ld | nl// floating point59 | fc | dc | ldc ;// complex60 sout | nl;54 sout | "output basic types" | endl; 55 sout | b | endl // boolean 56 | c | ' ' | sc | ' ' | usc | endl // character 57 | si | usi | i | ui | li | uli | lli | ulli | endl // integral 58 | f | d | ld | endl // floating point 59 | fc | dc | ldc | endl; // complex 60 sout | endl; 61 61 62 sout | "tuples" ;62 sout | "tuples" | endl; 63 63 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 64 sout | t1 | t2 ;// print tuple65 sout | nl;64 sout | t1 | t2 | endl; // print tuple 65 sout | endl; 66 66 67 sout | "toggle separator" ;68 sout | f | "" | d | "" | ld | nl // floating point without separator69 | sepDisable | fc | dc | ldc | nl// complex without separator70 | fc | sepOn | dc | ldc | nl // local separator add71 | sepEnable | fc | dc | ldc | nl // complex with separator72 | fc | sepOff | dc | ldc | nl// local separator removal73 | s1 | sepOff | s2 | nl // local separator removal74 | s1 | "" | s2 ;// local separator removal75 sout | nl;67 sout | "toggle separator" | endl; 68 sout | f | "" | d | "" | ld | endl // floating point without separator 69 | sepDisable | fc | dc | ldc | endl // complex without separator 70 | fc | sepOn | dc | ldc | endl // local separator add 71 | sepEnable | fc | dc | ldc | endl // complex with separator 72 | fc | sepOff | dc | ldc | endl // local separator removal 73 | s1 | sepOff | s2 | endl // local separator removal 74 | s1 | "" | s2 | endl; // local separator removal 75 sout | endl; 76 76 77 sout | "change separator" ;78 sout | "from \"" | sep | "\"" | nonl;77 sout | "change separator" | endl; 78 sout | "from \"" | sep | "\""; 79 79 sepSet( sout, ", $" ); // change separator, maximum of 15 characters 80 sout | " to \"" | sep | "\"" ;81 sout | f | d | ld | nl82 | fc | dc | ldc | nl83 | s1 | s2 | nl84 | t1 | t2 ;// print tuple85 sout | nl;86 sout | "from \"" | sep | "\" " | nonl;80 sout | " to \"" | sep | "\"" | endl; 81 sout | f | d | ld | endl 82 | fc | dc | ldc | endl 83 | s1 | s2 | endl 84 | t1 | t2 | endl; // print tuple 85 sout | endl; 86 sout | "from \"" | sep | "\" "; 87 87 sepSet( sout, " " ); // restore separator 88 sout | "to \"" | sep | "\"" ;89 sout | f | d | ld | nl90 | fc | dc | ldc | nl91 | s1 | s2 | nl92 | t1 | t2 ;// print tuple93 sout | nl;88 sout | "to \"" | sep | "\"" | endl; 89 sout | f | d | ld | endl 90 | fc | dc | ldc | endl 91 | s1 | s2 | endl 92 | t1 | t2 | endl; // print tuple 93 sout | endl; 94 94 95 sout | "check sepOn/sepOff" ;96 sout | sepOn | 1 | 2 | 3 | sepOn ;// no separator at start/end of line97 sout | 1 | sepOff | 2 | 3 ;// locally turn off implicit separator95 sout | "check sepOn/sepOff" | endl; 96 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line 97 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 98 98 sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line 99 99 sout | 1 | 2 | 3 | "\n\n" | sepOn; // no separator at start of next line 100 sout | 1 | 2 | 3 ;101 sout | nl;100 sout | 1 | 2 | 3 | endl; 101 sout | endl; 102 102 103 sout | "check enable/disable" ;104 sout | sepDisable | 1 | 2 | 3 ;// globally turn off implicit separation105 sout | 1 | sepOn | 2 | 3 ;// locally turn on implicit separator106 sout | sepEnable | 1 | 2 | 3 | sepDisable;// globally turn on/off implicit separation107 sout | 1 | 2 | 3 | sepEnable;// globally turn on implicit separation108 sout | 1 | 2 | 3 | sepOn | sepDisable ;// ignore seperate at end of line109 sout | 1 | 2 | 3 | sepOn | sepEnable ;// separator at end of line110 sout | 1 | 2 | 3 ;111 sout | nl;103 sout | "check enable/disable" | endl; 104 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 105 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator 106 sout | sepEnable | 1 | 2 | 3 | endl | sepDisable; // globally turn on/off implicit separation 107 sout | 1 | 2 | 3 | endl | sepEnable; // globally turn on implicit separation 108 sout | 1 | 2 | 3 | sepOn | sepDisable | endl; // ignore seperate at end of line 109 sout | 1 | 2 | 3 | sepOn | sepEnable | endl; // separator at end of line 110 sout | 1 | 2 | 3 | endl; 111 sout | endl; 112 112 113 // sout | fmt( d, "%8.3f" ); 113 // sout | fmt( d, "%8.3f" ) || endl; 114 // sout | endl; 114 115 115 116 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 116 sout | t1 | t2 | " \"" | sep | "\"" ;117 sout | t1 | t2 | " \"" | sep | "\"" | endl; 117 118 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 118 sout | t1 | t2 | " \"" | sep | "\"" ;119 sout | t1 | t2 ;// print tuple120 sout | nl;119 sout | t1 | t2 | " \"" | sep | "\"" | endl; 120 sout | t1 | t2 | endl; // print tuple 121 sout | endl; 121 122 122 123 [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; 123 sout | [ 3, 4, "a", 7.2 ] ;124 sout | t3 ;124 sout | [ 3, 4, "a", 7.2 ] | endl; 125 sout | t3 | endl; 125 126 sepSetTuple( sout, " " ); 126 sout | t3 ;127 sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 ;127 sout | t3 | endl; 128 sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl; 128 129 sepSet( sout, "^" ); 129 130 sepSetTuple( sout, "-" ); 130 sout | t3 | 3 | 4 | t3 ;131 sout | t3 | 3 | 4 | t3 | endl; 131 132 } 132 133 -
tests/literals.cfa
r85acec94 r90cfc16 10 10 // Created On : Sat Sep 9 16:34:38 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:44:01201813 // Update Count : 13 912 // Last Modified On : Tue Nov 6 17:58:07 2018 13 // Update Count : 138 14 14 // 15 15 … … 18 18 #include <fstream.hfa> 19 19 20 void f( char v ) { sout | "char " | v ; }21 void f( signed char v ) { sout | "signed char " | v ; }22 void f( unsigned char v ) { sout | "unsigned char " | v ; }23 void f( signed short v ) { sout | "signed short int" | v ; }24 void f( unsigned short v ) { sout | "unsigned short int" | v ; }25 void f( size_t v ) { sout | "size_t" | v ; }20 void f( char v ) { sout | "char " | v | endl; } 21 void f( signed char v ) { sout | "signed char " | v | endl; } 22 void f( unsigned char v ) { sout | "unsigned char " | v | endl; } 23 void f( signed short v ) { sout | "signed short int" | v | endl; } 24 void f( unsigned short v ) { sout | "unsigned short int" | v | endl; } 25 void f( size_t v ) { sout | "size_t" | v | endl; } 26 26 #endif // __CFA__ 27 27 -
tests/loopctrl.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Aug 8 18:32:59 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 08:14:44201813 // Update Count : 7612 // Last Modified On : Wed Nov 7 16:54:11 2018 13 // Update Count : 62 14 14 // 15 15 … … 32 32 S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; } 33 33 ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; } 34 void & ?|?( ofstream & os, S v ) { (ofstream)(os | v); if ( getANL( os ) ) nl( os ); }35 34 36 35 int main() { 37 sout | nlOff; // turn off auto newline 38 while () { sout | "empty"; break; } sout | nl; 39 do { sout | "empty"; break; } while (); sout | nl; 40 for () { sout | "empty"; break; } sout | nl; 36 while () { sout | "empty"; break; } sout | endl; 37 do { sout | "empty"; break; } while (); sout | endl; 38 for () { sout | "empty"; break; } sout | endl | endl; 41 39 42 for ( 0 ) { sout | "A"; } sout | "zero" | nl;43 for ( 1 ) { sout | "A"; } sout | nl;44 for ( 10 ) { sout | "A"; } sout | nl;45 for ( 1 ~= 10 ~ 2 ) { sout | "B"; } sout | nl;46 for ( 10 -~= 1 ~ 2 ) { sout | "C"; } sout | nl;47 for ( 0.5 ~ 5.5 ) { sout | "D"; } sout | nl;48 for ( 5.5 -~ 0.5 ) { sout | "E"; } sout | nl | nl;40 for ( 0 ) { sout | "A"; } sout | "zero" | endl; 41 for ( 1 ) { sout | "A"; } sout | endl; 42 for ( 10 ) { sout | "A"; } sout | endl; 43 for ( 1 ~= 10 ~ 2 ) { sout | "B"; } sout | endl; 44 for ( 10 -~= 1 ~ 2 ) { sout | "C"; } sout | endl; 45 for ( 0.5 ~ 5.5 ) { sout | "D"; } sout | endl; 46 for ( 5.5 -~ 0.5 ) { sout | "E"; } sout | endl | endl; 49 47 50 for ( i; 10 ) { sout | i; } sout | nl;51 for ( i; 1 ~= 10 ~ 2 ) { sout | i; } sout | nl;52 for ( i; 10 -~= 1 ~ 2 ) { sout | i; } sout | nl;53 for ( i; 0.5 ~ 5.5 ) { sout | i; } sout | nl;54 for ( i; 5.5 -~ 0.5 ) { sout | i; } sout | nl;55 for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; } sout | nl;56 for ( ui; 10u -~= 2u ~ 2u ) { sout | ui; } sout | nl | nl | nl;48 for ( i; 10 ) { sout | i; } sout | endl; 49 for ( i; 1 ~= 10 ~ 2 ) { sout | i; } sout | endl; 50 for ( i; 10 -~= 1 ~ 2 ) { sout | i; } sout | endl; 51 for ( i; 0.5 ~ 5.5 ) { sout | i; } sout | endl; 52 for ( i; 5.5 -~ 0.5 ) { sout | i; } sout | endl; 53 for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; } sout | endl; 54 for ( ui; 10u -~= 2u ~ 2u ) { sout | ui; } sout | endl | endl | endl; 57 55 58 56 enum { N = 10 }; 59 for ( N ) { sout | "N"; } sout | nl;60 for ( i; N ) { sout | i; } sout | nl;61 for ( i; N -~ 0 ) { sout | i; } sout | nl | nl | nl;57 for ( N ) { sout | "N"; } sout | endl; 58 for ( i; N ) { sout | i; } sout | endl; 59 for ( i; N -~ 0 ) { sout | i; } sout | endl | endl | endl; 62 60 63 61 const int start = 3, comp = 10, inc = 2; 64 for ( i; start ~ comp ~ inc + 1 ) { sout | i; } sout | nl | nl;62 for ( i; start ~ comp ~ inc + 1 ) { sout | i; } sout | endl | endl; 65 63 66 sout | nl;67 for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl;68 for ( s; (S){10,10} ) { sout | s; } sout | nl;69 sout | nl;70 for ( s; (S){0} ~ (S){10,10} ) { sout | s; } sout | nl;71 for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } sout | nl;72 for ( s; (S){0} ~= (S){10,10} ) { sout | s; } sout | nl;73 for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl;74 sout | nl;75 for ( s; (S){10,10} -~ (S){0} ) { sout | s; } sout | nl;76 for ( s; (S){10,10} -~ (S){0} ~ (S){1} ) { sout | s; } sout | nl;77 for ( s; (S){10,10} -~= (S){0} ) { sout | s; } sout | nl;78 for ( s; (S){10,10} -~= (S){0} ~ (S){1} ) { sout | s; } sout | nl;64 sout | endl; 65 for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | endl; 66 for ( s; (S){10,10} ) { sout | s; } sout | endl; 67 sout | endl; 68 for ( s; (S){0} ~ (S){10,10} ) { sout | s; } sout | endl; 69 for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } sout | endl; 70 for ( s; (S){0} ~= (S){10,10} ) { sout | s; } sout | endl; 71 for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } sout | endl; 72 sout | endl; 73 for ( s; (S){10,10} -~ (S){0} ) { sout | s; } sout | endl; 74 for ( s; (S){10,10} -~ (S){0} ~ (S){1} ) { sout | s; } sout | endl; 75 for ( s; (S){10,10} -~= (S){0} ) { sout | s; } sout | endl; 76 for ( s; (S){10,10} -~= (S){0} ~ (S){1} ) { sout | s; } sout | endl; 79 77 } 80 78 -
tests/math1.cfa
r85acec94 r90cfc16 10 10 // Created On : Fri Apr 22 14:59:21 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 10:24:31201813 // Update Count : 8 812 // Last Modified On : Tue Nov 6 17:58:37 2018 13 // Update Count : 86 14 14 // 15 15 … … 22 22 long double l; 23 23 24 sout | "fmod:" | 5.0F % -2.0F | fmod( 5.0F, -2.0F ) | 5.0D % -2.0D | fmod( 5.0D, -2.0D ) | 5.0L % -2.0L | fmod( 5.0L, -2.0L ) ;25 sout | "remainder:" | remainder( 2.0F, 3.0F ) | remainder( 2.0D, 3.0D ) | remainder( 2.0L, 3.0L ) ;24 sout | "fmod:" | 5.0F % -2.0F | fmod( 5.0F, -2.0F ) | 5.0D % -2.0D | fmod( 5.0D, -2.0D ) | 5.0L % -2.0L | fmod( 5.0L, -2.0L ) | endl; 25 sout | "remainder:" | remainder( 2.0F, 3.0F ) | remainder( 2.0D, 3.0D ) | remainder( 2.0L, 3.0L ) | endl; 26 26 int quot; 27 27 f = remquo( 3.6F, 0.5F, " ); 28 sout | "remquo:" | quot | f | nonl;28 sout | "remquo:" | quot | f; 29 29 d = remquo( 3.6D, 0.5F, " ); 30 sout | quot | d | nonl;30 sout | quot | d; 31 31 l = remquo( 3.6L, 0.5L, " ); 32 sout | quot | l ;33 sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ) ;34 sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) ;35 sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) ;36 sout | "nan:" | (float)nan( "" ) | (double)nan( "" ) | (long double)nan( "" ) ;32 sout | quot | l | endl; 33 sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ) | endl; 34 sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) | endl; 35 sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) | endl; 36 sout | "nan:" | (float)nan( "" ) | (double)nan( "" ) | (long double)nan( "" ) | endl; 37 37 38 38 //---------------------- Exponential ---------------------- 39 39 40 sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI ) ;41 sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ) ;42 sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ) ;43 sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5DL+1.5LI, 1.5DL+1.5LI ) ;40 sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI ) | endl; 41 sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ) | endl; 42 sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ) | endl; 43 sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5DL+1.5LI, 1.5DL+1.5LI ) | endl; 44 44 45 45 int b = 4; 46 46 unsigned int e = 2; 47 47 b \= e; 48 sout | "\\" | b | b \ e ;49 sout | "\\" | 'a' \ 3u | 2 \ 8u | 4 \ 3u | -4 \ 3u | 4 \ -3 | -4 \ -3 | 4.0 \ 2.1 | (1.0f+2.0fi) \ (3.0f+2.0fi) ;48 sout | "\\" | b | b \ e | endl; 49 sout | "\\" | 'a' \ 3u | 2 \ 8u | 4 \ 3u | -4 \ 3u | 4 \ -3 | -4 \ -3 | 4.0 \ 2.1 | (1.0f+2.0fi) \ (3.0f+2.0fi) | endl; 50 50 } // main 51 51 -
tests/math2.cfa
r85acec94 r90cfc16 10 10 // Created On : Fri Apr 22 14:59:21 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 23:11:12201813 // Update Count : 8 512 // Last Modified On : Tue Nov 6 17:58:55 2018 13 // Update Count : 83 14 14 // 15 15 … … 24 24 //---------------------- Logarithm ---------------------- 25 25 26 sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI ) ;27 sout | "log2:" | log2( 8.0F ) | log2( 8.0D ) | log2( 8.0L ) ;28 sout | "log10:" | log10( 100.0F ) | log10( 100.0D ) | log10( 100.0L ) ;29 sout | "log1p:" | log1p( 1.0F ) | log1p( 1.0D ) | log1p( 1.0L ) ;30 sout | "ilogb:" | ilogb( 1.0F ) | ilogb( 1.0D ) | ilogb( 1.0L ) ;31 sout | "logb:" | logb( 8.0F ) | logb( 8.0D ) | logb( 8.0L ) ;26 sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI ) | endl; 27 sout | "log2:" | log2( 8.0F ) | log2( 8.0D ) | log2( 8.0L ) | endl; 28 sout | "log10:" | log10( 100.0F ) | log10( 100.0D ) | log10( 100.0L ) | endl; 29 sout | "log1p:" | log1p( 1.0F ) | log1p( 1.0D ) | log1p( 1.0L ) | endl; 30 sout | "ilogb:" | ilogb( 1.0F ) | ilogb( 1.0D ) | ilogb( 1.0L ) | endl; 31 sout | "logb:" | logb( 8.0F ) | logb( 8.0D ) | logb( 8.0L ) | endl; 32 32 33 sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI ) ;34 sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L ) ;35 sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L ) ;33 sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI ) | endl; 34 sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L ) | endl; 35 sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L ) | endl; 36 36 37 37 //---------------------- Trigonometric ---------------------- 38 38 39 sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI ) ;40 sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI ) ;41 sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI ) ;42 sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI ) ;43 sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI ) ;44 sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI ) ;45 sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L ) | nonl;46 sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L ) ;39 sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI ) | endl; 40 sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI ) | endl; 41 sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI ) | endl; 42 sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI ) | endl; 43 sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI ) | endl; 44 sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI ) | endl; 45 sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L ); 46 sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L ) | endl; 47 47 } // main 48 48 -
tests/math3.cfa
r85acec94 r90cfc16 10 10 // Created On : Fri Apr 22 14:59:21 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 10:15:49201813 // Update Count : 8 512 // Last Modified On : Tue Nov 6 17:59:05 2018 13 // Update Count : 83 14 14 // 15 15 … … 24 24 //---------------------- Hyperbolic ---------------------- 25 25 26 sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI ) ;27 sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI ) ;28 sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI ) ;29 sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI ) ;30 sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI ) ;31 sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI ) ;26 sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI ) | endl; 27 sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI ) | endl; 28 sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI ) | endl; 29 sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI ) | endl; 30 sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI ) | endl; 31 sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI ) | endl; 32 32 33 33 //---------------------- Error / Gamma ---------------------- 34 34 35 sout | "erf:" | erf( 1.0F ) | erf( 1.0D ) | erf( 1.0L ) ;36 sout | "erfc:" | erfc( 1.0F ) | erfc( 1.0D ) | erfc( 1.0L ) ;37 sout | "lgamma:" | lgamma( 4.0F ) | lgamma( 4.0D ) | lgamma( 4.0L ) ;35 sout | "erf:" | erf( 1.0F ) | erf( 1.0D ) | erf( 1.0L ) | endl; 36 sout | "erfc:" | erfc( 1.0F ) | erfc( 1.0D ) | erfc( 1.0L ) | endl; 37 sout | "lgamma:" | lgamma( 4.0F ) | lgamma( 4.0D ) | lgamma( 4.0L ) | endl; 38 38 int sign; 39 39 f = lgamma( 4.0F, &sign ); 40 sout | "lgamma:" | f | sign | nonl;40 sout | "lgamma:" | f | sign; 41 41 d = lgamma( 4.0D, &sign ); 42 sout | d | sign | nonl;42 sout | d | sign; 43 43 l = lgamma( 4.0L, &sign ); 44 sout | l | sign ;45 sout | "tgamma:" | tgamma( 4.0F ) | tgamma( 4.0D ) | tgamma( 4.0L ) ;44 sout | l | sign | endl; 45 sout | "tgamma:" | tgamma( 4.0F ) | tgamma( 4.0D ) | tgamma( 4.0L ) | endl; 46 46 } // main 47 47 -
tests/math4.cfa
r85acec94 r90cfc16 10 10 // Created On : Thu May 24 20:56:54 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 18:15:01201813 // Update Count : 412 // Last Modified On : Tue Nov 6 17:59:14 2018 13 // Update Count : 3 14 14 // 15 15 … … 24 24 //---------------------- Nearest Integer ---------------------- 25 25 26 sout | "floor:" | floor( 1.2F ) | floor( 1.2D ) | floor( 1.2L ) ;27 sout | "ceil:" | ceil( 1.6F ) | ceil( 1.6D ) | ceil( 1.6L ) ;28 sout | "trunc:" | trunc( 3.5F ) | trunc( 3.5D ) | trunc( 3.5L ) ;29 sout | "rint:" | (float)rint( 1.5F ) | (double)rint( 1.5D ) | (long double)rint( 1.5L ) ;30 sout | "rint:" | (long int)rint( 1.5F ) | (long int)rint( 1.5D ) | (long int)rint( 1.5L ) ;31 sout | "rint:" | (long long int)rint( 1.5F ) | (long long int)rint( 1.5D ) | (long long int)rint( 1.5L ) ;32 sout | "lrint:" | lrint( 1.5F ) | lrint( 1.5D ) | lrint( 1.5L ) ;33 sout | "llrint:" | llrint( 1.5F ) | llrint( 1.5D ) | llrint( 1.5L ) ;34 sout | "nearbyint:" | nearbyint( 3.5F ) | nearbyint( 3.5D ) | nearbyint( 3.5L ) ;35 sout | "round:" | (float)round( 1.5F ) | (double)round( 1.5D ) | (long double)round( 1.5L ) ;36 sout | "round:" | (long int)round( 1.5F ) | (long int)round( 1.5D ) | (long int)round( 1.5L ) ;37 sout | "round:" | (long long int)round( 1.5F ) | (long long int)round( 1.5D ) | (long long int)round( 1.5L ) ;38 sout | "lround:" | lround( 1.5F ) | lround( 1.5D ) | lround( 1.5L ) ;39 sout | "llround:" | llround( 1.5F ) | llround( 1.5D ) | llround( 1.5L ) ;26 sout | "floor:" | floor( 1.2F ) | floor( 1.2D ) | floor( 1.2L ) | endl; 27 sout | "ceil:" | ceil( 1.6F ) | ceil( 1.6D ) | ceil( 1.6L ) | endl; 28 sout | "trunc:" | trunc( 3.5F ) | trunc( 3.5D ) | trunc( 3.5L ) | endl; 29 sout | "rint:" | (float)rint( 1.5F ) | (double)rint( 1.5D ) | (long double)rint( 1.5L ) | endl; 30 sout | "rint:" | (long int)rint( 1.5F ) | (long int)rint( 1.5D ) | (long int)rint( 1.5L ) | endl; 31 sout | "rint:" | (long long int)rint( 1.5F ) | (long long int)rint( 1.5D ) | (long long int)rint( 1.5L ) | endl; 32 sout | "lrint:" | lrint( 1.5F ) | lrint( 1.5D ) | lrint( 1.5L ) | endl; 33 sout | "llrint:" | llrint( 1.5F ) | llrint( 1.5D ) | llrint( 1.5L ) | endl; 34 sout | "nearbyint:" | nearbyint( 3.5F ) | nearbyint( 3.5D ) | nearbyint( 3.5L ) | endl; 35 sout | "round:" | (float)round( 1.5F ) | (double)round( 1.5D ) | (long double)round( 1.5L ) | endl; 36 sout | "round:" | (long int)round( 1.5F ) | (long int)round( 1.5D ) | (long int)round( 1.5L ) | endl; 37 sout | "round:" | (long long int)round( 1.5F ) | (long long int)round( 1.5D ) | (long long int)round( 1.5L ) | endl; 38 sout | "lround:" | lround( 1.5F ) | lround( 1.5D ) | lround( 1.5L ) | endl; 39 sout | "llround:" | llround( 1.5F ) | llround( 1.5D ) | llround( 1.5L ) | endl; 40 40 41 41 //---------------------- Manipulation ---------------------- 42 42 43 sout | "copysign:" | copysign( 1.0F, -1.0F ) | copysign( 1.0D, -1.0D ) | copysign( 1.0L, -1.0L ) ;43 sout | "copysign:" | copysign( 1.0F, -1.0F ) | copysign( 1.0D, -1.0D ) | copysign( 1.0L, -1.0L ) | endl; 44 44 int exp; 45 45 f = frexp( 4.0F, &exp ); 46 sout | "frexp:" | f | exp | nonl;46 sout | "frexp:" | f | exp; 47 47 d = frexp( 4.0D, &exp ); 48 sout | d | exp | nonl;48 sout | d | exp; 49 49 l = frexp( 4.0L, &exp ); 50 sout | l | exp ;51 sout | "ldexp:" | ldexp( 2.0F, 2 ) | ldexp( 2.0D, 2 ) | ldexp( 2.0L, 2 ) ;50 sout | l | exp | endl; 51 sout | "ldexp:" | ldexp( 2.0F, 2 ) | ldexp( 2.0D, 2 ) | ldexp( 2.0L, 2 ) | endl; 52 52 float fi; 53 53 double di; 54 54 long double ldi; 55 55 f = modf( 2.3F, &fi ); 56 sout | "modf:" | fi | f | nonl;56 sout | "modf:" | fi | f; 57 57 d = modf( 2.3D, &di ); 58 sout | di | d | nonl;58 sout | di | d; 59 59 l = modf( 2.3L, &ldi ); 60 sout | ldi | l ;61 sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ) ;62 sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) ;63 sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) ;60 sout | ldi | l | endl; 61 sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ) | endl; 62 sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) | endl; 63 sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) | endl; 64 64 65 sout | "scalbn:" | scalbn( 2.0F, 3 ) | scalbn( 2.0D, 3 ) | scalbn( 2.0L, 3 ) ;66 sout | "scalbln:" | scalbln( 2.0F, 3L ) | scalbln( 2.0D, 3L ) | scalbln( 2.0L, 3L ) ;65 sout | "scalbn:" | scalbn( 2.0F, 3 ) | scalbn( 2.0D, 3 ) | scalbn( 2.0L, 3 ) | endl; 66 sout | "scalbln:" | scalbln( 2.0F, 3L ) | scalbln( 2.0D, 3L ) | scalbln( 2.0L, 3L ) | endl; 67 67 } // main 68 68 -
tests/minmax.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:45:31201813 // Update Count : 5 212 // Last Modified On : Tue Nov 6 17:59:26 2018 13 // Update Count : 51 14 14 // 15 15 … … 22 22 int ?>?( char op1, char op2 ) { return (int)op1 > (int)op2; } 23 23 24 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' ) ;25 sout | "signed int\t\t" | 4 | 3 | "\tmin" | min( 4, 3 ) ;26 sout | "unsigned int\t\t" | 4u | 3u | "\tmin" | min( 4u, 3u ) ;27 sout | "signed long int\t\t" | 4l | 3l | "\tmin" | min( 4l, 3l ) ;28 sout | "unsigned long int\t" | 4ul | 3ul | "\tmin" | min( 4ul, 3ul ) ;29 sout | "signed long long int\t" | 4ll | 3ll | "\tmin" | min( 4ll, 3ll ) ;30 sout | "unsigned long long int\t" | 4ull | 3ull | "\tmin" | min( 4ull, 3ull ) ;31 sout | "float\t\t\t" | 4.0f | 3.1f | "\tmin" | min( 4.0f, 3.1f ) ;32 sout | "double\t\t\t" | 4.0 | 3.1 | "\tmin" | min( 4.0, 3.1 ) ;33 sout | "long double\t\t" | 4.0l | 3.1l | "\tmin" | min( 4.0l, 3.1l ) ;24 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' ) | endl; 25 sout | "signed int\t\t" | 4 | 3 | "\tmin" | min( 4, 3 ) | endl; 26 sout | "unsigned int\t\t" | 4u | 3u | "\tmin" | min( 4u, 3u ) | endl; 27 sout | "signed long int\t\t" | 4l | 3l | "\tmin" | min( 4l, 3l ) | endl; 28 sout | "unsigned long int\t" | 4ul | 3ul | "\tmin" | min( 4ul, 3ul ) | endl; 29 sout | "signed long long int\t" | 4ll | 3ll | "\tmin" | min( 4ll, 3ll ) | endl; 30 sout | "unsigned long long int\t" | 4ull | 3ull | "\tmin" | min( 4ull, 3ull ) | endl; 31 sout | "float\t\t\t" | 4.0f | 3.1f | "\tmin" | min( 4.0f, 3.1f ) | endl; 32 sout | "double\t\t\t" | 4.0 | 3.1 | "\tmin" | min( 4.0, 3.1 ) | endl; 33 sout | "long double\t\t" | 4.0l | 3.1l | "\tmin" | min( 4.0l, 3.1l ) | endl; 34 34 35 sout | nl;35 sout | endl; 36 36 37 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' ) ;38 sout | "signed int\t\t" | 4 | 3 | "\tmax" | max( 4, 3 ) ;39 sout | "unsigned int\t\t" | 4u | 3u | "\tmax" | max( 4u, 3u ) ;40 sout | "signed long int\t\t" | 4l | 3l | "\tmax" | max( 4l, 3l ) ;41 sout | "unsigned long int\t" | 4ul | 3ul | "\tmax" | max( 4ul, 3ul ) ;42 sout | "signed long long int\t" | 4ll | 3ll | "\tmax" | max( 4ll, 3ll ) ;43 sout | "unsigned long long int\t" | 4ull | 3ull | "\tmax" | max( 4ull, 3ull ) ;44 sout | "float\t\t\t" | 4.0f | 3.1f | "\tmax" | max( 4.0f, 3.1f ) ;45 sout | "double\t\t\t" | 4.0 | 3.1 | "\tmax" | max( 4.0, 3.1 ) ;46 sout | "long double\t\t" | 4.0l | 3.1l | "\tmax" | max( 4.0l, 3.1l ) ;37 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' ) | endl; 38 sout | "signed int\t\t" | 4 | 3 | "\tmax" | max( 4, 3 ) | endl; 39 sout | "unsigned int\t\t" | 4u | 3u | "\tmax" | max( 4u, 3u ) | endl; 40 sout | "signed long int\t\t" | 4l | 3l | "\tmax" | max( 4l, 3l ) | endl; 41 sout | "unsigned long int\t" | 4ul | 3ul | "\tmax" | max( 4ul, 3ul ) | endl; 42 sout | "signed long long int\t" | 4ll | 3ll | "\tmax" | max( 4ll, 3ll ) | endl; 43 sout | "unsigned long long int\t" | 4ull | 3ull | "\tmax" | max( 4ull, 3ull ) | endl; 44 sout | "float\t\t\t" | 4.0f | 3.1f | "\tmax" | max( 4.0f, 3.1f ) | endl; 45 sout | "double\t\t\t" | 4.0 | 3.1 | "\tmax" | max( 4.0, 3.1 ) | endl; 46 sout | "long double\t\t" | 4.0l | 3.1l | "\tmax" | max( 4.0l, 3.1l ) | endl; 47 47 } // main 48 48 -
tests/quotedKeyword.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:45:53201813 // Update Count : 2 312 // Last Modified On : Tue Nov 6 17:46:20 2018 13 // Update Count : 22 14 14 // 15 15 … … 41 41 st.`struct` = 3; 42 42 `throw` = 4; 43 sout | `catch` + st.`otype` + st.`struct` + `throw` ;43 sout | `catch` + st.`otype` + st.`struct` + `throw` | endl; 44 44 } 45 45 -
tests/raii/dtor-early-exit.c
r85acec94 r90cfc16 10 10 // Created On : Wed Aug 17 08:26:25 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:05:24201813 // Update Count : 912 // Last Modified On : Sat Aug 11 07:58:39 2018 13 // Update Count : 8 14 14 // 15 15 … … 25 25 // don't want these called 26 26 void ?{}(A & a) { assert( false ); } 27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name ; a.x = (int*)malloc(); }27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); } 28 28 void ?{}(A & a, const char * name, int * ptr) { assert( false ); } 29 29 30 30 A ?=?(A & a, A b) { sout | "assign " | a.name | " " | b.name; return a; } 31 void ?{}(A & a, A b) { sout | "copy construct " | b.name ; a.x = (int*)malloc(); }32 void ^?{}(A & a) { sout | "destruct " | a.name ; free(a.x); }31 void ?{}(A & a, A b) { sout | "copy construct " | b.name | endl; a.x = (int*)malloc(); } 32 void ^?{}(A & a) { sout | "destruct " | a.name | endl; free(a.x); } 33 33 34 34 // test returns 35 35 void f(int i) { 36 sout | "f i=" | i ;36 sout | "f i=" | i | endl; 37 37 A x = { "x" }; // construct x 38 38 { … … 55 55 void g() { 56 56 for (int i = 0; i < 10; i++) { 57 sout | "g for i=" | i ;57 sout | "g for i=" | i | endl; 58 58 A x = { "x" }; 59 59 // construct x 60 60 // destruct x 61 61 } 62 sout | nl;62 sout | endl; 63 63 { 64 64 int i = 0; 65 65 while (i < 10) { 66 sout | "g while i=" | i ;66 sout | "g while i=" | i | endl; 67 67 A x = { "x" }; 68 68 // construct x … … 71 71 } 72 72 } 73 sout ;73 sout | endl; 74 74 for (int i = 0; i < 10; i++) { 75 75 switch(10) { … … 78 78 case 10: { 79 79 A y = { "y" }; 80 sout | "g switch i=" | i ;80 sout | "g switch i=" | i | endl; 81 81 // construct y 82 82 break; // destruct y 83 83 } 84 84 default: { 85 sout | "g switch i=" | i ;85 sout | "g switch i=" | i | endl; 86 86 A x = { "x" }; 87 87 // construct x … … 90 90 } 91 91 } 92 sout | nl;92 sout | endl; 93 93 for (int k = 0; k < 2; k++) { 94 sout | "g for k=" | k ;94 sout | "g for k=" | k | endl; 95 95 L1: for (int i = 0; i < 10; i++) { 96 sout | "g for i=" | i ;96 sout | "g for i=" | i | endl; 97 97 98 98 A x = { "x" }; 99 99 if (i == 2) { 100 sout | "continue L1" ;100 sout | "continue L1" | endl; 101 101 continue; // destruct x 102 102 } else if (i == 3) { 103 sout | "break L1" ;103 sout | "break L1" | endl; 104 104 break; // destruct x 105 105 } 106 106 107 107 L2: for (int j = 0; j < 10; j++) { 108 sout | "g for j=" | j ;108 sout | "g for j=" | j | endl; 109 109 A y = { "y" }; 110 110 if (j == 0) { 111 sout | "continue L2" ;111 sout | "continue L2" | endl; 112 112 continue; // destruct y - missing because object that needs to be destructed is not a part of this block, it's a part of the for's block 113 113 } else if (j == 1) { 114 sout | "break L2" ;114 sout | "break L2" | endl; 115 115 break; // destruct y 116 116 } else if (i == 1) { 117 sout | "continue L1" ;117 sout | "continue L1" | endl; 118 118 continue L1; // destruct x,y - note: continue takes you to destructors for block, so only generate destructor for y 119 119 } else if (k == 1) { 120 sout | "break L1" ;120 sout | "break L1" | endl; 121 121 break L1; // destruct x,y 122 122 } … … 125 125 } 126 126 127 sout | nl;127 sout | endl; 128 128 L3: if( 3 ) { 129 129 A w = { "w" }; 130 130 if( 4 ) { 131 131 A v = { "v" }; 132 sout | "break L3" ;132 sout | "break L3" | endl; 133 133 break L3; 134 134 } … … 144 144 // * if S_L-S_G is non-empty, error 145 145 // * emit destructors for all variables in S_G-S_L 146 sout | "h" ;146 sout | "h" | endl; 147 147 { 148 148 L0: ; … … 152 152 A y = { "y" }; 153 153 // S_L1 = { y } 154 L1: sout | "L1" ;154 L1: sout | "L1" | endl; 155 155 A x = { "x" }; 156 156 // S_L2 = { y, x } 157 L2: sout | "L2" ;157 L2: sout | "L2" | endl; 158 158 if (i == 0) { 159 159 ++i; 160 sout | "goto L1" ;160 sout | "goto L1" | endl; 161 161 // S_G = { y, x } 162 162 goto L1; // jump back, destruct b/c before x definition … … 165 165 } else if (i == 1) { 166 166 ++i; 167 sout | "goto L2" ;167 sout | "goto L2" | endl; 168 168 // S_G = { y, x } 169 169 goto L2; // jump back, do not destruct … … 172 172 } else if (i == 2) { 173 173 ++i; 174 sout | "goto L3" ;174 sout | "goto L3" | endl; 175 175 // S_G = { y, x } 176 176 goto L3; // jump ahead, do not destruct … … 180 180 ++i; 181 181 A z = { "z" }; 182 sout | "goto L3-2" ;182 sout | "goto L3-2" | endl; 183 183 // S_G = { z, y, x } 184 184 goto L3; … … 187 187 } else { 188 188 ++i; 189 sout | "goto L4" ;189 sout | "goto L4" | endl; 190 190 // S_G = { y, x } 191 191 goto L4; // jump ahead, destruct b/c left block x was defined in … … 194 194 } 195 195 // S_L3 = { y, x } 196 L3: sout | "L3" ;197 sout | "goto L2-2" ;196 L3: sout | "L3" | endl; 197 sout | "goto L2-2" | endl; 198 198 // S_G = { y, x } 199 199 goto L2; // jump back, do not destruct … … 202 202 } 203 203 // S_L4 = {} 204 L4: sout | "L4" ;204 L4: sout | "L4" | endl; 205 205 if (i == 4) { 206 sout | "goto L0" ;206 sout | "goto L0" | endl; 207 207 // S_G = {} 208 208 goto L0; … … 240 240 f(i); 241 241 } 242 sout | nl;242 sout | endl; 243 243 g(); 244 sout | nl;244 sout | endl; 245 245 h(); 246 246 -
tests/raii/globals.c
r85acec94 r90cfc16 70 70 71 71 int main() { 72 sout | "static\t\tinline\t\tautogen\t\tvalue" ;72 sout | "static\t\tinline\t\tautogen\t\tvalue" | endl; 73 73 74 sout | "no \t\tno \t\tno \t\t" | g.val.value ;75 sout | "no \t\tno \t\tyes\t\t" | ga.val.value ;76 sout | "no \t\tyes\t\tno \t\t" | gi.val.value ;77 sout | "no \t\tyes\t\tyes\t\t" | gia.val.value ;78 sout | "yes\t\tno \t\tno \t\t" | gs.val.value ;79 sout | "yes\t\tno \t\tyes\t\t" | gsa.val.value ;80 sout | "yes\t\tyes\t\tno \t\t" | gsi.val.value ;81 sout | "yes\t\tyes\t\tyes\t\t" | gsia.val.value ;74 sout | "no \t\tno \t\tno \t\t" | g.val.value | endl; 75 sout | "no \t\tno \t\tyes\t\t" | ga.val.value | endl; 76 sout | "no \t\tyes\t\tno \t\t" | gi.val.value | endl; 77 sout | "no \t\tyes\t\tyes\t\t" | gia.val.value | endl; 78 sout | "yes\t\tno \t\tno \t\t" | gs.val.value | endl; 79 sout | "yes\t\tno \t\tyes\t\t" | gsa.val.value | endl; 80 sout | "yes\t\tyes\t\tno \t\t" | gsi.val.value | endl; 81 sout | "yes\t\tyes\t\tyes\t\t" | gsia.val.value | endl; 82 82 83 83 } -
tests/random.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Jul 5 21:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:46:25 201813 // Update Count : 2 212 // Last Modified On : Tue Nov 6 18:00:15 2018 13 // Update Count : 20 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // random17 #include <stdlib.hfa> // random 18 18 #include <unistd.h> // getpid 19 19 … … 24 24 // test polymorphic calls to random and stream 25 25 char c = random(); 26 sout | c ;26 sout | c | endl; 27 27 c = random( 'A' ); 28 sout | c ;28 sout | c | endl; 29 29 c = random( 'A', 'Z' ); 30 sout | c ;30 sout | c | endl; 31 31 32 32 int i = random(); 33 sout | i ;33 sout | i | endl; 34 34 i = random( 10 ); 35 sout | i ;35 sout | i | endl; 36 36 i = random( -10, 20 ); 37 sout | i ;37 sout | i | endl; 38 38 39 39 unsigned int ui = random(); 40 sout | ui ;40 sout | ui | endl; 41 41 ui = random( 10u ); 42 sout | ui ;42 sout | ui | endl; 43 43 ui = random( 10u, 20u ); 44 sout | ui ;44 sout | ui | endl; 45 45 46 46 long int li = random(); 47 sout | li ;47 sout | li | endl; 48 48 li = random( 10l ); 49 sout | li ;49 sout | li | endl; 50 50 li = random( -10l, 20l ); 51 sout | li ;51 sout | li | endl; 52 52 53 53 unsigned long int uli = random(); 54 sout | uli ;54 sout | uli | endl; 55 55 uli = random( 10ul ); 56 sout | uli ;56 sout | uli | endl; 57 57 uli = random( 10ul, 20ul ); 58 sout | uli ;58 sout | uli | endl; 59 59 60 60 float f = random(); 61 sout | f ;61 sout | f | endl; 62 62 63 63 double d = random(); 64 sout | d ;64 sout | d | endl; 65 65 66 66 float _Complex fc = random(); 67 sout | fc ;67 sout | fc | endl; 68 68 69 69 double _Complex dc = random(); 70 sout | dc ;70 sout | dc | endl; 71 71 72 72 long double _Complex ldc = random(); 73 sout | ldc ;73 sout | ldc | endl; 74 74 } // main 75 75 -
tests/rational.cfa
r85acec94 r90cfc16 10 10 // Created On : Mon Mar 28 08:43:12 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:46:42201813 // Update Count : 6 912 // Last Modified On : Tue Nov 6 18:00:27 2018 13 // Update Count : 68 14 14 // 15 15 … … 27 27 28 28 int main() { 29 sout | "constructor" ;29 sout | "constructor" | endl; 30 30 Rational(int) a = { 3 }, b = { 4 }, c; 31 sout | a | b | c ;31 sout | a | b | c | endl; 32 32 33 33 a = (Rational(int)){ 4, 8 }; 34 34 b = (Rational(int)){ 5, 7 }; 35 sout | a | b ;35 sout | a | b | endl; 36 36 a = (Rational(int)){ -2, -3 }; 37 37 b = (Rational(int)){ 3, -2 }; 38 sout | a | b ;38 sout | a | b | endl; 39 39 a = (Rational(int)){ -2, 3 }; 40 40 b = (Rational(int)){ 3, 2 }; 41 sout | a | b ;41 sout | a | b | endl; 42 42 43 sout | "logical" ;43 sout | "logical" | endl; 44 44 a = (Rational(int)){ -2 }; 45 45 b = (Rational(int)){ -3, 2 }; 46 sout | a | b ;47 // sout | a == 1 ; // FIX ME48 sout | a != b ;49 sout | a < b ;50 sout | a <= b ;51 sout | a > b ;52 sout | a >= b ;46 sout | a | b | endl; 47 // sout | a == 1 | endl; // FIX ME 48 sout | a != b | endl; 49 sout | a < b | endl; 50 sout | a <= b | endl; 51 sout | a > b | endl; 52 sout | a >= b | endl; 53 53 54 sout | "arithmetic" ;55 sout | a | b ;56 sout | a + b ;57 sout | a - b ;58 sout | a * b ;59 sout | a / b ;54 sout | "arithmetic" | endl; 55 sout | a | b | endl; 56 sout | a + b | endl; 57 sout | a - b | endl; 58 sout | a * b | endl; 59 sout | a / b | endl; 60 60 61 sout | "conversion" ;61 sout | "conversion" | endl; 62 62 a = (Rational(int)){ 3, 4 }; 63 sout | widen( a ) ;63 sout | widen( a ) | endl; 64 64 a = (Rational(int)){ 1, 7 }; 65 sout | widen( a ) ;65 sout | widen( a ) | endl; 66 66 a = (Rational(int)){ 355, 113 }; 67 sout | widen( a ) ;68 sout | narrow( 0.75, 4 ) ;69 sout | narrow( 0.14285714285714, 16 ) ;70 sout | narrow( 3.14159265358979, 256 ) ;67 sout | widen( a ) | endl; 68 sout | narrow( 0.75, 4 ) | endl; 69 sout | narrow( 0.14285714285714, 16 ) | endl; 70 sout | narrow( 3.14159265358979, 256 ) | endl; 71 71 72 sout | "decompose" ;72 sout | "decompose" | endl; 73 73 int n, d; 74 74 // [n, d] = a; 75 // sout | a | n | d ;75 // sout | a | n | d | endl; 76 76 77 sout | "more tests" ;77 sout | "more tests" | endl; 78 78 Rational(int) x = { 1, 2 }, y = { 2 }; 79 sout | x - y ;80 sout | x > y ;81 sout | x | numerator( x, 2 ) | x ;82 sout | y | denominator( y, -2 ) | y ;79 sout | x - y | endl; 80 sout | x > y | endl; 81 sout | x | numerator( x, 2 ) | x | endl; 82 sout | y | denominator( y, -2 ) | y | endl; 83 83 84 84 Rational(int) z = { 0, 5 }; 85 sout | z ;85 sout | z | endl; 86 86 87 sout | x | numerator( x, 0 ) | x ;87 sout | x | numerator( x, 0 ) | x | endl; 88 88 89 89 x = (Rational(int)){ 1, MAX } + (Rational(int)){ 1, MAX }; 90 sout | x ;90 sout | x | endl; 91 91 x = (Rational(int)){ 3, MAX } + (Rational(int)){ 2, MAX }; 92 sout | x ;92 sout | x | endl; 93 93 94 94 sin | a | b; 95 sout | a | b ;95 sout | a | b | endl; 96 96 } // main 97 97 -
tests/searchsort.cfa
r85acec94 r90cfc16 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 5 08:18:42201813 // Update Count : 10 612 // Last Modified On : Tue Nov 6 18:00:38 2018 13 // Update Count : 102 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <stdlib.hfa> // bsearch, qsort17 #include <stdlib.hfa> // bsearch, qsort 18 18 #include <stdlib.h> // C version of bsearch 19 19 … … 24 24 int iarr[size]; 25 25 26 sout | nlOff; // turn off auto newline27 28 26 for ( i; 0u ~ size ) { 29 27 iarr[i] = size - i; 30 28 sout | iarr[i] | ", "; 31 29 } // for 32 sout | nl;30 sout | endl | endl; 33 31 34 32 // ascending sort/search by changing < to > … … 37 35 sout | iarr[i] | ", "; 38 36 } // for 39 sout | nl;37 sout | endl; 40 38 for ( i; 0u ~ size ) { // C version 41 39 int key = size - i; … … 43 41 sout | key | ':' | *v | ", "; 44 42 } // for 45 sout | nl;43 sout | endl; 46 44 47 45 for ( i; 0u ~ size ) { … … 49 47 sout | size - i | ':' | *v | ", "; 50 48 } // for 51 sout | nl;49 sout | endl; 52 50 for ( i; 0u ~ size ) { 53 51 unsigned int posn = bsearch( size - i, iarr, size ); 54 52 sout | size - i | ':' | iarr[posn] | ", "; 55 53 } // for 56 sout | nl;54 sout | endl | endl; 57 55 58 56 // descending sort/search by changing < to > … … 61 59 sout | iarr[i] | ", "; 62 60 } // for 63 sout | nl;61 sout | endl; 64 62 { 65 63 int ?<?( int x, int y ) { return x > y; } … … 68 66 sout | iarr[i] | ", "; 69 67 } // for 70 sout | nl;68 sout | endl; 71 69 for ( i; 0u ~ size ) { 72 70 int * v = bsearch( size - i, iarr, size ); 73 71 sout | size - i | ':' | *v | ", "; 74 72 } // for 75 sout | nl;73 sout | endl; 76 74 for ( i; 0u ~ size ) { 77 75 unsigned int posn = bsearch( size - i, iarr, size ); … … 79 77 } // for 80 78 } 81 sout | nl;79 sout | endl | endl; 82 80 83 81 double darr[size]; … … 86 84 sout | darr[i] | ", "; 87 85 } // for 88 sout | nl;86 sout | endl; 89 87 qsort( darr, size ); 90 88 for ( i; 0u ~ size ) { 91 89 sout | darr[i] | ", "; 92 90 } // for 93 sout | nl;91 sout | endl; 94 92 for ( i; 0u ~ size ) { 95 93 double * v = bsearch( size - i + 0.5, darr, size ); 96 94 sout | size - i + 0.5 | ':' | *v | ", "; 97 95 } // for 98 sout | nl;96 sout | endl; 99 97 for ( i; 0u ~ size ) { 100 98 unsigned int posn = bsearch( size - i + 0.5, darr, size ); 101 99 sout | size - i + 0.5 | ':' | darr[posn] | ", "; 102 100 } // for 103 sout | nl;101 sout | endl | endl; 104 102 105 103 struct S { int i, j; } sarr[size]; … … 111 109 sout | sarr[i] | ", "; 112 110 } // for 113 sout | nl;111 sout | endl; 114 112 qsort( sarr, size ); 115 113 for ( i; 0u ~ size ) { 116 114 sout | sarr[i] | ", "; 117 115 } // for 118 sout | nl;116 sout | endl; 119 117 for ( i; 0u ~ size ) { 120 118 S temp = { size - i, size - i + 1 }; … … 122 120 sout | temp | ':' | *v | ", "; 123 121 } // for 124 sout | nl;122 sout | endl; 125 123 for ( i; 0u ~ size ) { 126 124 S temp = { size - i, size - i + 1 }; … … 128 126 sout | temp | ':' | sarr[posn] | ", "; 129 127 } // for 130 sout | nl;128 sout | endl | endl; 131 129 { 132 130 unsigned int getKey( const S & s ) { return s.j; } … … 134 132 sout | sarr[i] | ", "; 135 133 } // for 136 sout | nl;134 sout | endl; 137 135 for ( i; 0u ~ size ) { 138 136 S * v = bsearch( size - i + 1, sarr, size ); 139 137 sout | size - i + 1 | ':' | *v | ", "; 140 138 } // for 141 sout | nl;139 sout | endl; 142 140 for ( i; 0u ~ size ) { 143 141 unsigned int posn = bsearch( size - i + 1, sarr, size ); 144 142 sout | size - i + 1 | ':' | sarr[posn] | ", "; 145 143 } // for 146 sout | nl;144 sout | endl | endl; 147 145 } 148 146 } // main -
tests/shortCircuit.cfa
r85acec94 r90cfc16 1 //2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // shortCircuit.cfa --8 //9 // Author : Peter A. Buhr10 // Created On : Thu Jan 28 18:26:16 201611 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Dec 4 18:26:05 201813 // Update Count : 414 //15 16 1 void g( float f ) {} 17 2 void g( int i ) {} … … 48 33 } 49 34 50 int main( int argc, char const *argv[] ) { 51 sout | nlOff; 35 36 int main(int argc, char const *argv[]) 37 { 52 38 test_t true_val, false_val; 53 39 true_val.x = 1; … … 55 41 56 42 true_val && false_val; 57 sout | nl;43 sout | endl; 58 44 59 45 true_val || false_val; 60 sout | nl;46 sout | endl; 61 47 62 48 false_val && true_val; 63 sout | nl;49 sout | endl; 64 50 65 51 false_val || true_val; 66 sout | nl;52 sout | endl; 67 53 68 54 return 0; 69 55 } 70 71 // Local Variables: //72 // tab-width: 4 //73 // compile-command: "cfa abs.cfa" //74 // End: // -
tests/sum.cfa
r85acec94 r90cfc16 11 11 // Created On : Wed May 27 17:56:53 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Dec 11 21:50:41201814 // Update Count : 28 513 // Last Modified On : Tue Nov 6 18:01:10 2018 14 // Update Count : 280 15 15 // 16 16 … … 56 56 } // for 57 57 sout | "sum from" | low | "to" | High | "is" 58 | sum( size, (unsigned char *)a ) | ", check" | (int)s ;58 | sum( size, (unsigned char *)a ) | ", check" | (int)s | endl; 59 59 60 60 int s = 0, a[size], v = low; … … 64 64 } // for 65 65 sout | "sum from" | low | "to" | High | "is" 66 | sum( size, (int *)a ) | ", check" | (int)s ;66 | sum( size, (int *)a ) | ", check" | (int)s | endl; 67 67 68 68 float s = 0.0f, a[size], v = low / 10.0f; … … 72 72 } // for 73 73 sout | "sum from" | low / 10.0f | "to" | High / 10.0f | "is" 74 | sum( size, (float *)a ) | ", check" | (float)s ;74 | sum( size, (float *)a ) | ", check" | (float)s | endl; 75 75 76 76 double s = 0.0, a[size], v = low / 10.0; … … 80 80 } // for 81 81 sout | "sum from" | low / 10.0 | "to" | High / 10.0 | "is" 82 | sum( size, (double *)a ) | ", check" | (double)s ;82 | sum( size, (double *)a ) | ", check" | (double)s | endl; 83 83 84 84 struct S { int i, j; }; … … 93 93 S ?++( S & t ) { S temp = t; t += (S){1}; return temp; } 94 94 ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; } 95 void ?|?( ofstream & os, S v ) { (ofstream)(os | v); if ( getANL( os ) ) nl( os ); }96 95 97 96 S s = (S){0}, a[size], v = { low, low }; … … 101 100 } // for 102 101 sout | "sum from" | low | "to" | High | "is" 103 | sum( size, (S *)a ) | ", check" | (S)s ;102 | sum( size, (S *)a ) | ", check" | (S)s | endl; 104 103 105 104 forall( otype Impl | sumable( Impl ) ) … … 115 114 } // for 116 115 sout | "sum from" | low | "to" | High | "is" 117 | sum( size, gs.x ) | ", check" | (int)s ;// add field array in generic type116 | sum( size, gs.x ) | ", check" | (int)s | endl; // add field array in generic type 118 117 delete( gs.x ); 119 118 } // main -
tests/swap.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 10:17:40201813 // Update Count : 7 412 // Last Modified On : Tue Nov 6 18:01:23 2018 13 // Update Count : 72 14 14 // 15 15 … … 19 19 int main( void ) { 20 20 char c1 = 'a', c2 = 'b'; 21 sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap " | nonl;21 sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap "; 22 22 swap( c1, c2 ); 23 sout | '\t' | c1 | ' ' | c2 ;23 sout | '\t' | c1 | ' ' | c2 | endl; 24 24 25 25 signed int i1 = -1, i2 = -2; 26 sout | "signed int\t\t" | i1 | i2 | "\t\t\tswap " | nonl;26 sout | "signed int\t\t" | i1 | i2 | "\t\t\tswap "; 27 27 swap( i1, i2 ); 28 sout | '\t' | i1 | i2 ;28 sout | '\t' | i1 | i2 | endl; 29 29 30 30 unsigned int ui1 = 1, ui2 = 2; 31 sout | "unsigned int\t\t" | ui1 | ui2 | "\t\t\tswap " | nonl;31 sout | "unsigned int\t\t" | ui1 | ui2 | "\t\t\tswap "; 32 32 swap( ui1, ui2 ); 33 sout | '\t' | ui1 | ui2 ;33 sout | '\t' | ui1 | ui2 | endl; 34 34 35 35 signed long int li1 = -1, li2 = -2; 36 sout | "signed long int\t\t" | li1 | li2 | "\t\t\tswap " | nonl;36 sout | "signed long int\t\t" | li1 | li2 | "\t\t\tswap "; 37 37 swap( li1, li2 ); 38 sout | '\t' | li1 | li2 ;38 sout | '\t' | li1 | li2 | endl; 39 39 40 40 unsigned long int uli1 = 1, uli2 = 2; 41 sout | "unsigned long int\t" | uli1 | uli2 | "\t\t\tswap " | nonl;41 sout | "unsigned long int\t" | uli1 | uli2 | "\t\t\tswap "; 42 42 swap( uli1, uli2 ); 43 sout | '\t' | uli1 | uli2 ;43 sout | '\t' | uli1 | uli2 | endl; 44 44 45 45 signed long long int lli1 = -1, lli2 = -2; 46 sout | "signed long long int\t" | lli1 | lli2 | "\t\t\tswap " | nonl;46 sout | "signed long long int\t" | lli1 | lli2 | "\t\t\tswap "; 47 47 swap( lli1, lli2 ); 48 sout | '\t' | lli1 | lli2 ;48 sout | '\t' | lli1 | lli2 | endl; 49 49 50 50 unsigned long long int ulli1 = 1, ulli2 = 2; 51 sout | "unsigned long long int\t" | ulli1 | ulli2 | "\t\t\tswap " | nonl;51 sout | "unsigned long long int\t" | ulli1 | ulli2 | "\t\t\tswap "; 52 52 swap( ulli1, ulli2 ); 53 sout | '\t' | ulli1 | ulli2 ;53 sout | '\t' | ulli1 | ulli2 | endl; 54 54 55 55 float f1 = 1.5, f2 = 2.5; 56 sout | "float\t\t\t" | f1 | f2 | "\t\t\tswap " | nonl;56 sout | "float\t\t\t" | f1 | f2 | "\t\t\tswap "; 57 57 swap( f1, f2 ); 58 sout | '\t' | f1 | f2 ;58 sout | '\t' | f1 | f2 | endl; 59 59 60 60 double d1 = 1.5, d2 = 2.5; 61 sout | "double\t\t\t" | d1 | d2 | "\t\t\tswap " | nonl;61 sout | "double\t\t\t" | d1 | d2 | "\t\t\tswap "; 62 62 swap( d1, d2 ); 63 sout | '\t' | d1 | d2 ;63 sout | '\t' | d1 | d2 | endl; 64 64 65 65 long double ld1 = 1.5, ld2 = 2.5; 66 sout | "long double\t\t" | ld1 | ld2 | "\t\t\tswap " | nonl;66 sout | "long double\t\t" | ld1 | ld2 | "\t\t\tswap "; 67 67 swap( ld1, ld2 ); 68 sout | '\t' | ld1 | ld2 ;68 sout | '\t' | ld1 | ld2 | endl; 69 69 70 70 float _Complex fc1 = 1.5f+1.5if, fc2 = 2.5f+2.5if; 71 sout | "float _Complex\t\t" | fc1 | fc2 | "\tswap " | nonl;71 sout | "float _Complex\t\t" | fc1 | fc2 | "\tswap "; 72 72 swap( fc1, fc2 ); 73 sout | '\t' | fc1 | fc2 ;73 sout | '\t' | fc1 | fc2 | endl; 74 74 75 75 double _Complex dc1 = 1.5d+1.5id, dc2 = 2.5d+2.5id; 76 sout | "double _Complex\t\t" | dc1 | dc2 | "\tswap " | nonl;76 sout | "double _Complex\t\t" | dc1 | dc2 | "\tswap "; 77 77 swap( dc1, dc2 ); 78 sout | '\t' | dc1 | dc2 ;78 sout | '\t' | dc1 | dc2 | endl; 79 79 80 80 long double _Complex ldc1 = 1.5d+1.5il, ldc2 = 2.5d+2.5il; 81 sout | "long double _Complex\t" | ldc1 | ldc2 | "\tswap " | nonl;81 sout | "long double _Complex\t" | ldc1 | ldc2 | "\tswap "; 82 82 swap( ldc1, ldc2 ); 83 sout | '\t' | ldc1 | ldc2 ;83 sout | '\t' | ldc1 | ldc2 | endl; 84 84 85 85 struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 }; 86 86 ofstream & ?|?( ofstream & os, S s ) { return os | s.i | s.j; } 87 sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap " | nonl;87 sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap "; 88 88 swap( s1, s2 ); 89 sout | '\t' | s1 | "," | s2 ;89 sout | '\t' | s1 | "," | s2 | endl; 90 90 } // main 91 91 -
tests/time.cfa
r85acec94 r90cfc16 10 10 // Created On : Tue Mar 27 17:24:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:44:03201813 // Update Count : 2212 // Last Modified On : Tue Nov 6 18:01:45 2018 13 // Update Count : 17 14 14 // 15 15 … … 19 19 int main() { 20 20 Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns; 21 sout | d1 | d2 | d3 | d4 | d5 ;21 sout | d1 | d2 | d3 | d4 | d5 | endl; 22 22 int i; 23 23 d1 = 0; 24 sout | d1 | d2 | d3 ;24 sout | d1 | d2 | d3 | endl; 25 25 d1 = 7`s; 26 26 d3 = d2 = d1; 27 sout | d1 | d2 | d3 ;27 sout | d1 | d2 | d3 | endl; 28 28 d1 = d1 + d2; 29 sout | d1; 30 sout | d1 == 7`s | d1 == d2 | d1 == 0; 31 sout | div( 7`s, 2`s ); 29 sout | d1 | endl; 30 sout | d1 == 7`s | d1 == d2 | d1 == 0 | endl; 31 sout | div( 7`s, 2`s ) | endl; 32 sout | endl; 32 33 33 34 Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 }; 34 sout | t ;35 sout | t | endl; 35 36 t = t + d1; 36 sout | t | t.tv ;37 sout | t | t.tv | endl; 37 38 Time t1 = (timespec){ 104_414, 10_000_000 }; 38 sout | t1 | t1.tv ;39 sout | t - t | t + d5 | t.tv ;39 sout | t1 | t1.tv | endl; 40 sout | t - t | t + d5 | t.tv | endl; 40 41 char buf[16]; 41 sout | "yy/mm/dd" | [t, buf]`ymd | nonl;// shared buf => separate calls42 sout | "mm/dd/yy" | mm_dd_yy( t, buf ) | nonl;42 sout | "yy/mm/dd" | [t, buf]`ymd; // shared buf => separate calls 43 sout | "mm/dd/yy" | mm_dd_yy( t, buf ); 43 44 strftime( buf, 16, "%D", t ); // %D => mm/dd/yy 44 sout | "mm/dd/yy" | buf | nonl;45 sout | "dd/yy/mm" | [t, buf]`dmy ;45 sout | "mm/dd/yy" | buf; 46 sout | "dd/yy/mm" | [t, buf]`dmy | endl; 46 47 Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 }; 47 sout | t2 | t2.tv | nl | t3 | t3.tv; 48 sout | t2 | t2.tv | endl | t3 | t3.tv | endl; 49 sout | endl; 48 50 49 51 // Clock Newfoundland = { -3.5`h }, PST = { -8`h }; // distance from GMT (UTC) 50 // sout | "Clock Resolution" | getRes() 51 // | "Newfoundland" | getTime( Newfoundland ) 52 // | "local" | getTime() 53 // | "local nsec" | getTimeNsec() 54 // | "PST" | PST() ;// getTime short form55 // sout ;52 // sout | "Clock Resolution" | getRes() | endl 53 // | "Newfoundland" | getTime( Newfoundland ) | endl 54 // | "local" | getTime() | endl 55 // | "local nsec" | getTimeNsec() | endl 56 // | "PST" | PST() | endl; // getTime short form 57 // sout | endl; 56 58 57 59 // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4 58 60 Duration s = 1`h + 2 * 10`m + 70`s / 10; 59 sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds" ;60 sout | "Dividing that by 2 minutes gives" | s / 2`m ;61 sout | "Dividing that by 2 gives" | s / 2 | "seconds ";62 sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds" ;61 sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds" | endl; 62 sout | "Dividing that by 2 minutes gives" | s / 2`m | endl; 63 sout | "Dividing that by 2 gives" | s / 2 | "seconds\n"; 64 sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds" | endl; 63 65 } // main 64 66 -
tests/tuple/tupleAssign.c
r85acec94 r90cfc16 10 10 // Created On : Tue Nov 15 17:24:32 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 22:03:48 201813 // Update Count : 3 512 // Last Modified On : Mon Mar 6 21:23:58 2017 13 // Update Count : 34 14 14 // 15 15 … … 24 24 // swap x, y and store the new [x, y] in [u, v] and in z; 25 25 printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z ); 26 sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" ;26 sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" | endl; 27 27 z = [u, v] = [x, y] = [y, x]; 28 28 printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z ); 29 sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" ;29 sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" | endl; 30 30 31 31 // shuffle elements -- v = z.0, z.0 = z.1, z.1 = u, u = v 32 32 [v, z, u] = [z, u, v]; 33 33 printf( "u=%d v=%d z=[%d, %d]\n", u, v, z ); 34 sout | "u=" | u | "v=" | v | "z=[" | z | "]" ;34 sout | "u=" | u | "v=" | v | "z=[" | z | "]" | endl; 35 35 36 36 // multiple assignment with tuple expression on right … … 38 38 [u, v] = [123, 456]; 39 39 printf( "u=%d v=%d z=[%d, %d]\n", u, v, z ); 40 sout | "u=" | u | "v=" | v | "z=[" | z | "]" ;40 sout | "u=" | u | "v=" | v | "z=[" | z | "]" | endl; 41 41 } 42 42 { … … 55 55 [t, x, d, i, c, x] = (double)94.12; 56 56 printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, (int)c, t ); 57 sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" ;57 sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" | endl; 58 58 [x, c, i, d, x, t] = (double)-94.12; 59 59 printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, c, t ); 60 sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" ;60 sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" | endl; 61 61 } 62 62 } -
tests/userLiterals.cfa
r85acec94 r90cfc16 10 10 // Created On : Wed Sep 6 21:40:50 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 22:03:10201813 // Update Count : 5 612 // Last Modified On : Tue Nov 6 18:02:03 2018 13 // Update Count : 55 14 14 // 15 15 … … 18 18 #include <uchar.h> 19 19 20 int ?`s( int s ) { sout | "secs" | s ; return s; }21 int ?`m( int m ) { sout | "mins" | m ; return m * 60; }22 int ?`h( int h ) { sout | "hours" | h ; return h * 3600; }23 int ?`_A_( int x ) { sout | "_A_" | x ; return x; }24 int ?`__thingy_( int x ) { sout | "_thingy_" | x ; return x; }20 int ?`s( int s ) { sout | "secs" | s | endl; return s; } 21 int ?`m( int m ) { sout | "mins" | m | endl; return m * 60; } 22 int ?`h( int h ) { sout | "hours" | h | endl; return h * 3600; } 23 int ?`_A_( int x ) { sout | "_A_" | x | endl; return x; } 24 int ?`__thingy_( int x ) { sout | "_thingy_" | x | endl; return x; } 25 25 26 int ?`s( const char * s ) { sout | "secs" | s ; return 0; }27 int ?`m( const char16_t * m ) { sout | "mins" | m ; return 0;}28 int ?`h( const char32_t * h ) { sout | "hours" | h ; return 0; }29 int ?`_A_( const wchar_t * str ) { sout | "_A_" | str ; return 0; }30 int ?`__thingy_( const char * str ) { sout | "_thingy_" | str ; return 0; }26 int ?`s( const char * s ) { sout | "secs" | s | endl; return 0; } 27 int ?`m( const char16_t * m ) { sout | "mins" | m | endl; return 0;} 28 int ?`h( const char32_t * h ) { sout | "hours" | h | endl; return 0; } 29 int ?`_A_( const wchar_t * str ) { sout | "_A_" | str | endl; return 0; } 30 int ?`__thingy_( const char * str ) { sout | "_thingy_" | str | endl; return 0; } 31 31 32 32 … … 46 46 Weight w, heavy = { 20 }; // 20 stone 47 47 w = 155`lb; 48 sout | w ;48 sout | w | endl; 49 49 w = 0b_1111`st; 50 sout | w ;50 sout | w | endl; 51 51 w = 0_233`lb; // octal weight (155) 52 sout | w ;52 sout | w | endl; 53 53 w = 0x_9b_u`kg; 54 sout | w ;54 sout | w | endl; 55 55 w = 70.3`kg; 56 sout | w ;56 sout | w | endl; 57 57 w = 11`st + 1`lb; 58 sout | w ;58 sout | w | endl; 59 59 w = 5`st + 8`kg + 25`lb + heavy; 60 sout | w ;60 sout | w | endl; 61 61 62 62 // 0`secs; -
tests/vector.cfa
r85acec94 r90cfc16 10 10 // Created On : Mon Jul 4 23:36:19 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 22:02:39201813 // Update Count : 2 912 // Last Modified On : Tue Nov 6 18:02:26 2018 13 // Update Count : 28 14 14 // 15 15 … … 21 21 do { \ 22 22 if ( !(x) ) { \ 23 sout | "CHECK failed :" | #x | "at" | __FILE__ | " :" | __LINE__ ; \23 sout | "CHECK failed :" | #x | "at" | __FILE__ | " :" | __LINE__ | endl; \ 24 24 abort(); \ 25 25 } \ … … 31 31 assert( empty( &iv ) ); 32 32 assert( size( &iv ) == 0 ); 33 sout | size( &iv ) ;33 sout | size( &iv ) | endl; 34 34 35 35 push_back( &iv, 1 ); 36 36 assert( size( &iv ) == 1 ); 37 sout | size( &iv ) ;37 sout | size( &iv ) | endl; 38 38 39 39 push_back( &iv, 2 ); 40 40 assert( size( &iv ) == 2 ); 41 sout | size( &iv ) ;41 sout | size( &iv ) | endl; 42 42 43 43 push_back( &iv, 3 ); 44 44 assert( size( &iv ) == 3 ); 45 sout | size( &iv ) ;45 sout | size( &iv ) | endl; 46 46 47 47 assert( !empty( &iv ) ); … … 58 58 assert( empty( &iv ) ); 59 59 assert( size( &iv ) == 0 ); 60 sout | size( &iv ) ;60 sout | size( &iv ) | endl; 61 61 } 62 62
Note:
See TracChangeset
for help on using the changeset viewer.