Changeset 35d1de5 for tests/forall.cfa


Ignore:
Timestamp:
Feb 5, 2023, 9:31:04 AM (15 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
6d2af204, ccb29b4
Parents:
21a2a7d
Message:

change test forall.cfa from compilation only to execution

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/forall.cfa

    r21a2a7d r35d1de5  
    1010// Created On       : Wed May  9 08:48:15 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 15:28:45 2023
    13 // Update Count     : 38
    14 //
     12// Last Modified On : Sun Feb  5 07:54:43 2023
     13// Update Count     : 90
     14//
     15
     16#include <fstream.hfa>
    1517
    1618void g1() {
    17         forall( T ) T f( T ) {};
    18         void f( int ) {};
    19         void h( void (*p)(void) ) {};
    20 
    21         int x;
    22         void (*y)(void);
    23         char z;
    24         float w;
     19        forall( T ) T f( T p ) { sout | 'f'; return p;  };
     20        void f( int p ) { sout | p; };
     21        void g( void ) { sout | 'g'; };
     22        void h( void (*p)(void) ) { p(); };
     23
     24        int x = 1;
     25        void (*y)(void) = g;
     26        char z = 'a';
     27        float w = 3.5;
    2528
    2629        f( x );
     
    2831        f( z );
    2932        f( w );
     33        h( y );
     34        f( y );
    3035        h( f( y ) );
    3136}
    3237
    3338void g2() {
    34         forall( T ) void f( T, T ) {}
    35         forall( T, U ) void f( T, U ) {}
     39        forall( T ) void f( T, T ) { sout | "fT"; }
     40        forall( T, U ) void f( T, U ) { sout | "fTU"; }
    3641
    3742        int x;
    3843        float y;
    39         int *z;
    40         float *w;
    41 
     44        int * z;
     45        float * w;
     46
     47        f( x, x );
     48        f( y, y );
     49        f( w, w );
    4250        f( x, y );
    4351        f( z, w );
     
    5058
    5159forall( T )
    52 void swap( T left, T right ) {
    53         T temp = left;
    54         left = right;
    55         right = temp;
     60void swap( T & left, T & right ) {                                              // by reference
     61    T temp = left;
     62    left = right;
     63    right = temp;
     64}
     65
     66forall( T )
     67[ T, T ] swap( T i, T j ) {                                                             // by value
     68    return [ j, i ];
    5669}
    5770
     
    7285} // sum
    7386
    74 forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
     87forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &, T ); } )
    7588T twice( T t ) {
    7689        return t + t;
     
    8295}
    8396
    84 int fred() {
    85         int x = 1, y = 2, a[10];
     97void fred() {
     98        int x = 1, y = 2, a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    8699        float f;
    87100
     101        sout | x | y;
    88102        swap( x, y );
    89         twice( x );
     103        sout | x | y | nl | swap( x, y );
     104        // [ x, y ] = swap( y, x );
     105        sout | twice( ' ' ) | ' ' | twice( 0hh ) | twice( 1h ) | twice( 0n ) | twice( 2 )
     106                 | twice( 3.2f ) | twice( 3.2 ) | twice( 3.2d ) | twice( 3.2+1.5i ) | twice( x );
    90107        f = min( 4.0, 3.0 );
    91         sum( 10, a );
     108        sout | f | min( 4.0, 3.0 );
     109        sout | sum( 10, a );
    92110}
    93111
     
    186204
    187205forall( T ) {
    188         extern "C" {
     206//      extern "C" {
    189207                struct SS { T t; };
    190                 T foo( T ) {}
    191         }
     208                T foo( T p ) { return p; }
     209//      }
    192210}
    193211
     
    195213W(int,int) w;
    196214
    197 int jane() {
     215void jane() {
    198216//      int j = bar( 3, 4 );
    199217        int k = baz( 3, 4, 5 );
    200218        int i = foo( 3 );
     219        sout | k | i;
    201220}
    202221
     
    211230        T t;
    212231        T t2 = t;
     232        sout | &tr | tp;
    213233}
    214234
     
    242262
    243263int main( void ) {
    244     #pragma GCC warning "Compiled"                      // force non-empty .expect file, NO TABS!!!
     264        g1();
     265        g2();
     266        fred();
     267        jane();
    245268}
    246269
Note: See TracChangeset for help on using the changeset viewer.