Changeset 25cdca5 for tests


Ignore:
Timestamp:
Jan 8, 2019, 11:31:21 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
08222c7, 274da98
Parents:
84b4d607 (diff), d5b2ac8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/examples/quickSort.cfa

    r84b4d607 r25cdca5  
    99// Created On       : Wed Dec  6 12:15:52 2017
    1010// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Tue Dec  4 18:00:27 2018
    12 // Update Count     : 167
     11// Last Modified On : Sat Dec 22 08:44:27 2018
     12// Update Count     : 168
    1313//
    1414
     
    151151                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    152152                        } // for
    153                         sortedfile | nl;
     153                        sortedfile | nl | nl;
    154154
    155155                        delete( values );
  • tests/coroutine/fmtLines.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 12 22:45:36 2018
    13 // Update Count     : 48
     12// Last Modified On : Sat Dec 22 18:27:00 2018
     13// Update Count     : 57
    1414//
    1515
     
    2424void main( Format & fmt ) with( fmt ) {
    2525        for () {                                                                                        // for as many characters
    26                 for ( g; 5 ) {                                                                  // groups of 5 blocks
    27                         for ( b; 4 ) {                                                          // blocks of 4 characters
     26                for ( g = 0; g < 5; g += 1 ) {                                  // groups of 5 blocks
     27                        for ( b = 0; b < 4; b += 1 ) {                          // blocks of 4 characters
    2828                                for () {                                                                // for newline characters
    2929                                        suspend();
    30                                         if ( ch != '\n' ) break;                        // ignore newline
     30                                  if ( ch != '\n' ) break;                              // ignore newline
    3131                                } // for
    3232                                sout | ch;                                                              // print character
  • tests/fallthrough.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed Mar 14 10:06:25 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  4 21:36:14 2018
    13 // Update Count     : 17
     12// Last Modified On : Mon Dec 24 11:24:35 2018
     13// Update Count     : 22
    1414//
    1515
     
    1818void test(int choice) {
    1919        choose ( choice ) {
    20                 case 1:
    21                         sout | "case 1";
    22                         fallthru;
    23                 case 2:
    24                         sout | "case 2";
    25                         fallthru;
    26                         sout | "did not fallthru";
    27                         if ( 7 ) fallthru common2;
    28                         fallthru common1;
    29                 case 3:
    30                         sout | "case 3";
    31                         fallthru default;
    32                         fallthru common1;
    33                 common1:
    34                         sout | "common1";
     20          case 1:
     21                sout | "case 1";
     22                fallthru;
     23          case 2:
     24                sout | "case 2";
     25                fallthru;
     26                sout | "did not fallthru";
     27                if ( 7 ) fallthru common2;
     28                fallthru common1;
     29          case 3:
     30                sout | "case 3";
     31                fallthru default;
     32                fallthru common1;
     33          common1:
     34                sout | "common1";
    3535                // break
    36                 case 4:
    37                         sout | "case 4";
    38                         fallthru common2;
    39                 case 5:
    40                         sout | "case 5";
    41                         fallthru common2;
    42                         fallthru default;
    43                 case 6:
    44                         sout | "case 6";
    45                         fallthru common2;
    46                 common2:
    47                         sout | "common2";
     36          case 4:
     37                sout | "case 4";
     38                fallthru common2;
     39          case 5:
     40                sout | "case 5";
     41                fallthru common2;
     42                fallthru default;
     43          case 6:
     44                sout | "case 6";
     45                fallthru common2;
     46          common2:
     47                sout | "common2";
    4848                // break
    49                 default:
    50                         sout | "default";
    51                         fallthru;
    52         }
     49          default:
     50                sout | "default";
     51                fallthru;
     52        } // choose
    5353
    5454        sout | nl;
     
    6161                        sout | "case 1";
    6262                        for ( int i = 0; i < 4; i += 1 ) {
    63                                 printf("%d\n", i);
     63                                sout | i;
    6464                                if ( i == 2 ) fallthru common;
    6565                        } // for
     
    7777                } // if
    7878          common:
    79                 printf( "common\n" );
     79                sout | "common";
    8080                fallthru;
    8181                break;
    8282          default:
    83                 printf( "default\n" );
     83                sout | "default";
    8484                fallthru;
    8585        } // switch
     
    9393        fallthru default;
    9494        choose ( 3 ) {
    95                 case 2:
    96                         for () {
    97                                 choose ( 2 ) {
    98                                         case 1:
    99                                                 // ERROR: default is later, but in a different switch
    100                                                 fallthru default;
    101                                                 // ERROR: common3 is later, but not at the same level as a case clause
    102                                                 fallthru common3;
    103                                 }
    104                                 common3: ;
     95          case 2:
     96                for () {
     97                        choose ( 2 ) {
     98                          case 1:
     99                                // ERROR: default is later, but in a different switch
     100                                fallthru default;
     101                                // ERROR: common3 is later, but not at the same level as a case clause
     102                                fallthru common3;
    105103                        }
    106                 default:
    107                 case 1:
    108                 common4:
    109                         // ERROR: attempt to jump up with fallthrough
    110                         if ( 7 ) fallthru common4;
    111                         // ERROR: attempt to jump up with fallthrough
    112                         fallthru default;
    113         }
     104                  common3: ;
     105                } // for
     106          default:
     107          case 1:
     108          common4:
     109                // ERROR: attempt to jump up with fallthrough
     110                if ( 7 ) fallthru common4;
     111                // ERROR: attempt to jump up with fallthrough
     112                fallthru default;
     113        } // choose
    114114#endif
    115115}
  • tests/fstream_test.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  4 21:36:34 2018
    13 // Update Count     : 67
     12// Last Modified On : Sat Dec 22 09:47:44 2018
     13// Update Count     : 68
    1414//
    1515
     
    2424                 | (nombre > 0 ? "positif" : nombre == 0 ? "zéro" : "négatif");
    2525
    26         sout | "Entrez trois nombres, s'il vous plaît: ";
     26        sout | "Entrez trois nombres, s'il vous plaît:";
    2727        int i, j, k;
    2828        sin  | i | j | k;
  • tests/genericUnion.cfa

    r84b4d607 r25cdca5  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// genericUnion.cfa --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Tue Dec 25 14:42:46 2018
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 25 14:46:33 2018
     13// Update Count     : 2
     14//
     15
    116#include <limits.hfa>
    217
     
    419union ByteView {
    520        T val;
    6         char bytes[(sizeof(int))]; // want to change to sizeof(T)
     21        char bytes[(sizeof(int))];                                                      // want to change to sizeof(T)
    722};
    823
    924forall(otype T)
    1025void print(ByteView(T) x) {
    11         for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T)
     26        for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
    1227                printf("%02x", x.bytes[i] & 0xff);
    1328        }
     
    2944        f(i, -1);
    3045}
     46
     47// Local Variables: //
     48// tab-width: 4 //
     49// compile-command: "cfa genericUnion.cfa" //
     50// End: //
  • tests/gmp.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Tue Apr 19 08:55:51 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  4 21:37:29 2018
    13 // Update Count     : 558
     12// Last Modified On : Thu Dec 20 22:41:47 2018
     13// Update Count     : 559
    1414//
    1515
     
    7676        sout | "x:" | x | "y:" | y;
    7777
    78         sout;
     78        sout | nl;
    7979
    8080        sin | x | y | z;
    8181        sout | x | y | z;
    8282
    83         sout;
     83        sout | nl;
    8484
    8585        sout | "Fibonacci Numbers";
     
    9494        } // for
    9595
    96         sout;
     96        sout | nl;
    9797
    9898        sout | "Factorial Numbers";
  • tests/io1.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 12 18:23:44 2018
    13 // Update Count     : 110
     12// Last Modified On : Fri Dec 21 16:02:55 2018
     13// Update Count     : 114
    1414//
    1515
     
    2222        sout | '1' | '2' | '3';
    2323        sout | 1 | "" | 2 | "" | 3;
    24         sout;
     24        sout | nl;
    2525
    26         sout | "opening delimiters";
    27         sout | "x (" | 1 | nonl;
    28         sout | "x [" | 2 | nonl;
    29         sout | "x {" | 3 | nonl;
    30         sout | "x =" | 4 | nonl;
    31         sout | "x $" | 5 | nonl;
    32         sout | "x £" | 6 | nonl;
    33         sout | "x ¥" | 7 | nonl;
    34         sout | "x ¡" | 8 | nonl;
    35         sout | "x ¿" | 9 | nonl;
     26        sout | nlOff;
     27        sout | "opening delimiters" | nl;
     28        sout | "x (" | 1;
     29        sout | "x [" | 2;
     30        sout | "x {" | 3;
     31        sout | "x =" | 4;
     32        sout | "x $" | 5;
     33        sout | "x £" | 6;
     34        sout | "x ¥" | 7;
     35        sout | "x ¡" | 8;
     36        sout | "x ¿" | 9;
    3637        sout | "x «" | 10;
     38        sout | nl | nl;
    3739
    38         sout | "closing delimiters";
    39         sout | 1 | ", x" | nonl;
    40         sout | 2 | ". x" | nonl;
    41         sout | 3 | "; x" | nonl;
    42         sout | 4 | "! x" | nonl;
    43         sout | 5 | "? x" | nonl;
    44         sout | 6 | "% x" | nonl;
    45         sout | 7 | "¢ x" | nonl;
    46         sout | 8 | "» x" | nonl;
    47         sout | 9 | ") x" | nonl;
    48         sout | 10 | "] x" | nonl;
     40        sout | "closing delimiters" | nl;
     41        sout | 1 | ", x";
     42        sout | 2 | ". x";
     43        sout | 3 | "; x";
     44        sout | 4 | "! x";
     45        sout | 5 | "? x";
     46        sout | 6 | "% x";
     47        sout | 7 | "¢ x";
     48        sout | 8 | "» x";
     49        sout | 9 | ") x";
     50        sout | 10 | "] x";
    4951        sout | 11 | "} x";
     52        sout | nl | nl;
    5053
    51         sout | "opening/closing delimiters";
    52         sout | "x`" | 1 | "`x'" | 2 | nonl;
    53         sout | "'x\"" | 3 | "\"x:" | 4 | nonl;
    54         sout | ":x " | 5 | " x\t" | 6 | nonl;
    55         sout | "\tx\f" | 7 | "\fx\v" | 8 | nonl;
    56         sout | "\vx\n" | 9 | "\nx\r" | 10 | nonl;
     54        sout | "opening/closing delimiters" | nl;
     55        sout | "x`" | 1 | "`x'" | 2;
     56        sout | "'x\"" | 3 | "\"x:" | 4;
     57        sout | ":x " | 5 | " x\t" | 6;
     58        sout | "\tx\f" | 7 | "\fx\v" | 8;
     59        sout | "\vx\n" | 9 | "\nx\r" | 10;
    5760        sout | "\rx";
     61        sout | nl | nl;
    5862
     63        sout | nlOn;
    5964        sout | "override opening/closing delimiters";
    6065        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4;
    61         sout;
     66        sout | nl;
    6267}
    6368
  • tests/io2.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 12 16:19:15 2018
    13 // Update Count     : 110
     12// Last Modified On : Fri Dec 21 08:20:14 2018
     13// Update Count     : 112
    1414//
    1515
     
    9696        sout | sepOn | 1 | 2 | 3 | sepOn;                                       // no separator at start/end of line
    9797        sout | 1 | sepOff | 2 | 3;                                                      // locally turn off implicit separator
    98         sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
    99         sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
     98        sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n' | nonl; // no separator at start/end of line
     99        sout | 1 | 2 | 3 | "\n\n" | sepOn | nonl;                                       // no separator at start of next line
    100100        sout | 1 | 2 | 3;
    101101        sout | nl;
     
    133133// Local Variables: //
    134134// tab-width: 4 //
    135 // compile-command: "cfa io2.cfa" //
     135// compile-command: "cfa -DIN_DIR=".in/" io2.cfa" //
    136136// End: //
  • tests/loopctrl.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed Aug  8 18:32:59 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 12 08:14:44 2018
    13 // Update Count     : 76
     12// Last Modified On : Sun Dec 23 23:00:29 2018
     13// Update Count     : 79
    1414//
    1515
     
    3232S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; }
    3333ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; }
    34 void & ?|?( ofstream & os, S v ) { (ofstream)(os | v); if ( getANL( os ) ) nl( os ); }
     34void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
    3535
    3636int main() {
     
    3838        while () { sout | "empty"; break; }                                     sout | nl;
    3939        do { sout | "empty"; break; } while ();                         sout | nl;
    40         for () { sout | "empty"; break; }                                       sout | nl;
     40        for () { sout | "empty"; break; }                                       sout | nl | nl;
    4141
    4242        for ( 0 ) { sout | "A"; }                                                       sout | "zero" | nl;
  • tests/polymorphism.cfa

    r84b4d607 r25cdca5  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Oct 17 12:19:48 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Oct 17 12:21:07 2017
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 25 14:40:24 2018
     13// Update Count     : 3
    1414//
    1515
    1616#include <assert.h>
    1717#include <inttypes.h>
     18#include <fstream.hfa>
    1819
    1920forall(otype T)
     
    6162                int y = 456;
    6263                int z = f(x, y);
    63                 printf("%d %d %d\n", x, y, z);
     64                sout | x | y | z;
    6465        }
    65 
    6666        {
    6767                // explicitly specialize function
    6868                int (*f)(int) = ident;
    6969                ((int(*)(int))ident);
    70                 printf("%d %d\n", f(5), ((int(*)(int))ident)(5));
     70                sout | f(5) | ((int(*)(int))ident)(5);
    7171        }
    72 
    7372        {
    7473                // test aggregates with polymorphic members
     
    10099
    101100                void print(x_type x) {
    102                         printf("%"PRIu32"\n", x);
     101                        sout | x;
    103102                }
    104103
    105104                void print(y_type y) {
    106                         printf("%"PRIu64"\n", y);
     105                        sout | y;
    107106                }
    108107
  • tests/pybin/tools.py

    r84b4d607 r25cdca5  
    7979def diff( lhs, rhs ):
    8080        # diff the output of the files
    81         diff_cmd = ("diff --ignore-all-space --text "
    82                                 "--ignore-blank-lines "
     81        diff_cmd = ("diff --text "
     82#                               "--ignore-all-space "
     83#                               "--ignore-blank-lines "
    8384                                "--old-group-format='\t\tmissing lines :\n"
    8485                                "%%<' \\\n"
  • tests/raii/dtor-early-exit.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed Aug 17 08:26:25 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 22:05:24 2018
    13 // Update Count     : 9
     12// Last Modified On : Fri Dec 21 08:45:19 2018
     13// Update Count     : 10
    1414//
    1515
     
    7171                }
    7272        }
    73         sout;
     73        sout | nl;
    7474        for (int i = 0; i < 10; i++) {
    7575                switch(10) {
  • tests/references.cfa

    r84b4d607 r25cdca5  
    99// Author           : Rob Schluntz
    1010// Created On       : Wed Aug 23 16:11:50 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 23 16:12:03
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 25 14:31:48 2018
     13// Update Count     : 11
    1414//
    1515
     16#include <fstream.hfa>
     17
    1618struct Y { int i; };
    17 void ?{}(Y & y) { printf("Default constructing a Y\n"); }
    18 void ?{}(Y & y, Y other) { printf("Copy constructing a Y\n"); }
    19 void ^?{}(Y & y) { printf("Destructing a Y\n"); }
    20 Y ?=?(Y & y, Y other) { printf("Assigning a Y\n"); return y; }
    21 void ?{}(Y & y, int i) { printf("Value constructing a Y %d\n", i); y.i = i; }
     19void ?{}( Y & y ) { sout | "Default constructing a Y"; }
     20void ?{}( Y & y, Y other ) { sout | "Copy constructing a Y"; }
     21void ^?{}( Y & y ) { sout | "Destructing a Y"; }
     22Y ?=?( Y & y, Y other ) { sout | "Assigning a Y"; return y; }
     23void ?{}( Y & y, int i ) { sout | "Value constructing a Y" | i; y.i = i; }
    2224
    2325struct X { Y & r; Y y; };
    24 void ?{}(X & x) {
     26void ?{}( X & x ) {
    2527        // ensure that r is not implicitly constructed
    2628}
    27 void ?{}(X & x, X other) {
     29void ?{}( X & x, X other ) {
    2830        // ensure that r is not implicitly constructed
    2931}
    30 void ^?{}(X & x) {
     32void ^?{}( X & x ) {
    3133        // ensure that r is not implicitly destructed
    3234}
    33 X ?=?(X & x, X other) { return x; }
     35X ?=?( X & x, X other ) { return x; }
    3436
    3537// ensure that generated functions do not implicitly operate on references
     
    4850        int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    4951                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    50         ***p3 = 3;                          // change x
    51         **p3 = &x;                          // change p1
    52         *p3 = &p1;                          // change p2
    53         int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
    54         // &ar[1] = &z;                        // change reference array element
    55         // typeof( ar[1] ) p = 3;              // is int, i.e., the type of referenced object
    56         // typeof( &ar[1] ) q = &x;            // is int *, i.e., the type of pointer
     52        ***p3 = 3;                                                                                      // change x
     53        **p3 = &x;                                                                                      // change p1
     54        *p3 = &p1;                                                                                      // change p2
     55        int y = 0, z = 11, & ar[3] = { x, y, z };                       // initialize array of references
     56                                                                                                                // &ar[1] = &z;                        // change reference array element
     57                                                                                                                // typeof( ar[1] ) p = 3;              // is int, i.e., the type of referenced object
     58                                                                                                                // typeof( &ar[1] ) q = &x;            // is int *, i.e., the type of pointer
    5759        // _Static_assert( sizeof( ar[1] ) == sizeof( int ), "Array type should be int." );   // is true, i.e., the size of referenced object
    5860        // _Static_assert( sizeof( &ar[1] ) == sizeof( int *), "Address of array should be int *." ); // is true, i.e., the size of a reference
    5961
    60         ((int*&)&r3) = &x;                  // change r1, (&*)**r3
     62        ((int*&)&r3) = &x;                                                                      // change r1, (&*)**r3
    6163        x = 3;
    6264        // test that basic reference properties are true - r1 should be an alias for x
    63         printf("%d %d %d\n", x, r1, &x == &r1);
     65        sout | x | r1 | &x == &r1;
    6466        r1 = 12;
    65         printf("%d %d %d\n", x, r1, &x == &r1);
     67        sout | x | r1 | &x == &r1;
    6668
    6769        // test that functions using basic references work
    68         printf("%d %d %d %d\n", toref(&x), toref(p1), toptr(r1) == toptr(x), toptr(r1) == &x);
     70        sout | toref( &x ) | toref( p1 ) | toptr( r1 ) == toptr( x ) | toptr( r1 ) == &x;
    6971
    7072        changeRef( x );
    7173        changeRef( y );
    7274        changeRef( z );
    73         printf("%d %d %d\n", x, y, z);
     75        sout | x | y | z;
    7476        changeRef( r1 );
    75         printf("%d %d\n", r1, x);
     77        sout | r1 | x;
    7678
    77         r3 = 6;                               // change x, ***r3
    78         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    79         &r3 = &x2;                            // change r1 to refer to x2, (&*)**r3
    80         r3 = 999;                             // modify x2
    81         printf("x = %d ; x2 = %d\n", x, x2);  // check that x2 was changed
    82         ((int**&)&&r3) = p2;                  // change r2, (&(&*)*)*r3, ensure explicit cast to reference works
    83         r3 = 12345;                           // modify x
    84         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    85         &&&r3 = p3;                           // change r3 to p3, (&(&(&*)*)*)r3
    86         ((int&)r3) = 22222;                   // modify x, ensure explicit cast to reference works
    87         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
     79        r3 = 6;                                                                                         // change x, ***r3
     80        sout | "x = " | x | " ; x2 = " | x2;                            // check that x was changed
     81        &r3 = &x2;                                                                                      // change r1 to refer to x2, (&*)**r3
     82        r3 = 999;                                                                                       // modify x2
     83        sout | "x = " | x | " ; x2 = " | x2;                            // check that x2 was changed
     84        ((int**&)&&r3) = p2;                                                            // change r2, (&(&*)*)*r3, ensure explicit cast to reference works
     85        r3 = 12345;                                                                                     // modify x
     86        sout | "x = " | x | " ; x2 = " | x2;                            // check that x was changed
     87        &&&r3 = p3;                                                                                     // change r3 to p3, (&(&(&*)*)*)r3
     88        ((int&)r3) = 22222;                                                                     // modify x, ensure explicit cast to reference works
     89        sout | "x = " | x | " ; x2 = " | x2;                                    // check that x was changed
    8890
    8991        // test that reference members are not implicitly constructed/destructed/assigned
     
    102104                struct S { double x, y; };
    103105                void f( int & i, int & j, S & s, int v[] ) {
    104                         printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]);
     106                        sout | i | j | "{ " | s.[x, y] | " }," | "[" | v[0] | "," | v[1] | "," | v[2] | "]";
    105107                }
    106                 void g(int & i) { printf("%d\n", i); }
    107                 void h(int &&& i) { printf("%d\n", i); }
     108                void g(int & i) { sout | i; }
     109                void h(int &&& i) { sout | i; }
    108110
    109                 int &&& r = 3;  // rvalue to reference
     111                int &&& r = 3;                                                                  // rvalue to reference
    110112                int i = r;
    111                 printf("%d %d\n", i, r);  // both 3
     113                sout | i | r;                                                                   // both 3
    112114
    113                 g( 3 );          // rvalue to reference
    114                 h( (int &&&)3 ); // rvalue to reference
     115                g( 3 );                                                                                 // rvalue to reference
     116                h( (int &&&)3 );                                                                // rvalue to reference
    115117
    116118                int a = 5, b = 4;
  • tests/searchsort.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Thu Feb  4 18:17:50 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec  5 08:18:42 2018
    13 // Update Count     : 106
     12// Last Modified On : Thu Dec 20 22:49:46 2018
     13// Update Count     : 108
    1414//
    1515
     
    2121
    2222int main( void ) {
    23         const unsigned int size = 10;
     23        const int size = 10;
    2424        int iarr[size];
    2525
    2626        sout | nlOff;                                                                           // turn off auto newline
    2727
    28         for ( i; 0u ~ size ) {
     28        for ( i; 0 ~ size ) {
    2929                iarr[i] = size - i;
    3030                sout | iarr[i] | ", ";
    3131        } // for
    32         sout | nl;
     32        sout | nl | nl;
    3333
    3434        // ascending sort/search by changing < to >
    3535        qsort( iarr, size );
    36         for ( i; 0u ~ size ) {
     36        for ( i; 0 ~ size ) {
    3737                sout | iarr[i] | ", ";
    3838        } // for
    3939        sout | nl;
    40         for ( i; 0u ~ size ) {          // C version
     40        for ( i; 0 ~ size ) {           // C version
    4141                int key = size - i;
    4242                int * v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp );
     
    4545        sout | nl;
    4646
    47         for ( i; 0u ~ size ) {
     47        for ( i; 0 ~ size ) {
    4848                int * v = bsearch( size - i, iarr, size );
    4949                sout | size - i | ':' | *v | ", ";
    5050        } // for
    5151        sout | nl;
    52         for ( i; 0u ~ size ) {
     52        for ( i; 0 ~ size ) {
    5353                unsigned int posn = bsearch( size - i, iarr, size );
    5454                sout | size - i | ':' | iarr[posn] | ", ";
    5555        } // for
    56         sout | nl;
     56        sout | nl | nl;
    5757
    5858        // descending sort/search by changing < to >
     
    6363        sout | nl;
    6464        {
    65                 int ?<?( int x, int y ) { return x > y; }
    66                 qsort( iarr, size );
    67                 for ( i; 0u ~ size ) {
     65                // redefinition of ?<? can't overlap the loop controls:
     66                {
     67                        int (*?<?)(int, int) = ?>?;
     68                        qsort( iarr, size );
     69                }
     70                for ( i; 0 ~ size ) {
    6871                        sout | iarr[i] | ", ";
    6972                } // for
    7073                sout | nl;
    71                 for ( i; 0u ~ size ) {
     74                for ( i; 0 ~ size ) {
     75                        int (*?<?)(int, int) = ?>?;
    7276                        int * v = bsearch( size - i, iarr, size );
    7377                        sout | size - i | ':' | *v | ", ";
    7478                } // for
    7579                sout | nl;
    76                 for ( i; 0u ~ size ) {
     80                for ( i; 0 ~ size ) {
     81                        int (*?<?)(int, int) = ?>?;
    7782                        unsigned int posn = bsearch( size - i, iarr, size );
    7883                        sout | size - i | ':' | iarr[posn] | ", ";
    7984                } // for
    8085        }
    81         sout | nl;
     86        sout | nl | nl;
    8287
    8388        double darr[size];
    84         for ( i; 0u ~ size ) {
     89        for ( i; 0 ~ size ) {
    8590                darr[i] = size - i + 0.5;
    8691                sout | darr[i] | ", ";
     
    8893        sout | nl;
    8994        qsort( darr, size );
    90         for ( i; 0u ~ size ) {
     95        for ( i; 0 ~ size ) {
    9196                sout | darr[i] | ", ";
    9297        } // for
    9398        sout | nl;
    94         for ( i; 0u ~ size ) {
     99        for ( i; 0 ~ size ) {
    95100                double * v = bsearch( size - i + 0.5, darr, size );
    96101                sout | size - i + 0.5 | ':' | *v | ", ";
    97102        } // for
    98103        sout | nl;
    99         for ( i; 0u ~ size ) {
     104        for ( i; 0 ~ size ) {
    100105                unsigned int posn = bsearch( size - i + 0.5, darr, size );
    101106                sout | size - i + 0.5 | ':' | darr[posn] | ", ";
    102107        } // for
    103         sout | nl;
     108        sout | nl | nl;
    104109
    105110        struct S { int i, j; } sarr[size];
    106111        int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; }
    107112        ofstream & ?|?( ofstream & os, S v ) { return os | v.i | ' ' | v.j; }
    108         for ( i; 0u ~ size ) {
     113        for ( i; 0 ~ size ) {
    109114                sarr[i].i = size - i;
    110115                sarr[i].j = size - i + 1;
     
    113118        sout | nl;
    114119        qsort( sarr, size );
    115         for ( i; 0u ~ size ) {
     120        for ( i; 0 ~ size ) {
    116121                sout | sarr[i] | ", ";
    117122        } // for
    118123        sout | nl;
    119         for ( i; 0u ~ size ) {
     124        for ( i; 0 ~ size ) {
    120125                S temp = { size - i, size - i + 1 };
    121126                S * v = bsearch( temp, sarr, size );
     
    123128        } // for
    124129        sout | nl;
    125         for ( i; 0u ~ size ) {
     130        for ( i; 0 ~ size ) {
    126131                S temp = { size - i, size - i + 1 };
    127132                unsigned int posn = bsearch( temp, sarr, size );
    128133                sout | temp | ':' | sarr[posn] | ", ";
    129134        } // for
    130         sout | nl;
     135        sout | nl | nl;
    131136        {
    132                 unsigned int getKey( const S & s ) { return s.j; }
    133                 for ( i; 0u ~ size ) {
     137                int getKey( const S & s ) { return s.j; }
     138                for ( i; 0 ~ size ) {
    134139                        sout | sarr[i] | ", ";
    135140                } // for
    136141                sout | nl;
    137                 for ( i; 0u ~ size ) {
     142                for ( i; 0 ~ size ) {
    138143                        S * v = bsearch( size - i + 1, sarr, size );
    139144                        sout | size - i + 1 | ':' | *v | ", ";
    140145                } // for
    141146                sout | nl;
    142                 for ( i; 0u ~ size ) {
     147                for ( i; 0 ~ size ) {
    143148                        unsigned int posn = bsearch( size - i + 1, sarr, size );
    144149                        sout | size - i + 1 | ':' | sarr[posn] | ", ";
    145150                } // for
    146                 sout | nl;
     151                sout | nl | nl;
    147152        }
    148153} // main
  • tests/sum.cfa

    r84b4d607 r25cdca5  
    1111// Created On       : Wed May 27 17:56:53 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Tue Dec 11 21:50:41 2018
    14 // Update Count     : 285
     13// Last Modified On : Sun Dec 23 23:00:38 2018
     14// Update Count     : 287
    1515//
    1616
     
    9393        S ?++( S & t ) { S temp = t; t += (S){1}; return temp; }
    9494        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 ); }
     95        void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
    9696
    9797        S s = (S){0}, a[size], v = { low, low };
  • tests/swap.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 10:17:40 2018
    13 // Update Count     : 74
     12// Last Modified On : Sun Dec 23 23:00:49 2018
     13// Update Count     : 77
    1414//
    1515
     
    8585        struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 };
    8686        ofstream & ?|?( ofstream & os, S s ) { return os | s.i | s.j; }
     87        void ?|?( ofstream & os, S s ) { (ofstream &)(os | s.i | s.j); nl( os ); }
    8788        sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap " | nonl;
    8889        swap( s1, s2 );
  • tests/time.cfa

    r84b4d607 r25cdca5  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 21:44:03 2018
    13 // Update Count     : 22
     12// Last Modified On : Thu Dec 20 23:09:21 2018
     13// Update Count     : 23
    1414//
    1515
     
    3030        sout | d1 == 7`s | d1 == d2 | d1 == 0;
    3131        sout | div( 7`s, 2`s );
     32        sout | nl;
    3233
    3334        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
     
    4647        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
    4748        sout | t2 | t2.tv | nl | t3 | t3.tv;
     49        sout | nl;
    4850
    4951        // Clock Newfoundland = { -3.5`h }, PST = { -8`h };     // distance from GMT (UTC)
     
    5355        //       | "local nsec" | getTimeNsec()
    5456        //       | "PST" | PST();                                                               // getTime short form
    55         // sout;
     57        // sout | nl;
    5658
    5759        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
  • tests/withStatement.cfa

    r84b4d607 r25cdca5  
    99// Author           : Rob Schluntz
    1010// Created On       : Mon Dec 04 17:41:45 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Dec 04 17:45:07 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 24 19:08:18 2018
     13// Update Count     : 5
    1414//
    1515
     16#include <fstream.hfa>
     17
    1618struct S {
    17   int i;
    18   // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
    19   int * ptr;
     19        int i;
     20        // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
     21        int * ptr;
    2022};
    2123
    2224// with clause on reference parameter
    23 void ?{}(S & this, int n) with(this) {
    24   i = n;
    25   ptr = (int *)malloc(sizeof(int));
     25void ?{}( S & this, int n ) with( this ) {
     26        i = n;
     27        ptr = (int *)malloc( sizeof(int) );
    2628}
    2729
    28 void ?{}(S & this) {
    29   this{ 0 };
     30void ?{}( S & this ) {
     31        this{ 0 };
    3032}
    3133
    32 void ?{}(S & this, S other) {
    33   this{ other.i };
     34void ?{}( S & this, S other ) {
     35        this{ other.i };
    3436}
    3537
    36 S ?=?(S & this, S other) with(this) {
    37   i = other.i;
    38   *ptr = *other.ptr;
    39   return this;
     38S ?=?( S & this, S other ) with( this ) {
     39        i = other.i;
     40        *ptr = *other.ptr;
     41        return this;
    4042}
    4143
    42 void ^?{}(S & this) with(this) {
    43   free(ptr);
     44void ^?{}( S & this ) with( this ) {
     45        free( ptr );
    4446}
    4547
    4648struct S2 {
    47   S s;
     49        S s;
    4850};
    4951
    50 void ?{}(S2 & this, int n) {
    51   (this.s){ n };
     52void ?{}( S2 & this, int n ) {
     53        (this.s){ n };
    5254}
    5355
    54 forall(otype T)
     56forall( otype T )
    5557struct Box {
    56   T x;
     58        T x;
    5759};
    5860
    59 forall(otype T)
    60 void ?{}(Box(T) & this) with(this) { // with clause in polymorphic function
    61   x{};
     61forall( otype T )
     62void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function
     63        x{};
    6264}
    6365
    64 void print(int i) { printf("%d", i); }
     66void print( int i ) { sout | i; }
    6567
    66 forall(otype T | { void print(T); })
    67 void foo(T t) {
    68   Box(T) b = { t };
    69   with(b) {  // with statement in polymorphic function
    70     print(x);
    71     printf("\n");
    72   }
     68forall( otype T | { void print( T ); })
     69void foo( T t ) {
     70        Box( T ) b = { t };
     71        with( b ) {  // with statement in polymorphic function
     72                print( x );
     73        }
    7374}
    7475
    7576// ensure with-statement temporary generation works correctly
    7677S mk() {
    77   printf("called mk\n");
    78   return (S) { 444 };
     78        sout | "called mk";
     79        return (S){ 444 };
    7980}
    8081
    8182// ensure with-statement temporary generation with reference-returning functions works correctly
    8283S & ref() {
    83   static S var = { 123456789 };
    84   return var;
     84        static S var = { 123456789 };
     85        return var;
    8586}
    8687
    8788int main() {
    88   S2 s2 = { 12345 };
    89   with (s2) {
    90     with(s) { // with s2.s
    91       printf("%d %d %d\n", i, s.i, s2.s.i);
    92       foo(i);  // s.i
    93       with(mk()) {
    94         printf("%d %d %d\n", i, i, i);
    95         with(ref()) {
    96           printf("%d %d %d\n", i, i, i);
    97         } // with ref()
    98         with(ref()) {
    99           printf("%d %d %d\n", i, i, i);
    100         } // with ref()
    101       } // with mk()
    102     } // with s
    103   } // with s2
     89        S2 s2 = { 12345 };
     90        with ( s2) {
     91                with( s ) { // with s2.s
     92                        sout | i | s.i | s2.s.i;
     93                        foo( i );  // s.i
     94                        with( mk()) {
     95                                sout | i | i | i;
     96                                with( ref()) {
     97                                        sout | i | i | i;
     98                                } // with ref()
     99                                with( ref()) {
     100                                        sout | i | i | i;
     101                                } // with ref()
     102                        } // with mk()
     103                } // with s
     104        } // with s2
    104105}
    105106
Note: See TracChangeset for help on using the changeset viewer.