source: tests/nested_function.cfa@ fece3d9

ADT ast-experimental
Last change on this file since fece3d9 was 5416b44, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

make expected output for nested functions deterministic

  • Property mode set to 100644
File size: 817 bytes
RevLine 
[03656d1]1#include <thread.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4
5enum { VALUES = 10_000 };
[5416b44]6int values[VALUES], total = 0;
7
8thread T { int id; };
[03656d1]9
[666f8a3]10void main( T & ) {
[5416b44]11 int sum = 0;
[666f8a3]12 void f() {
[03656d1]13 int i = 0;
14 void h( void ) { // nest routine
15 int j = i; // non-local reference
16 void g( void ) { // nest routine
17 i += 1; // non-local reference
18 j += 1; // non-local reference
19 if ( i < 3 ) h();
20 } // g
21 if ( prng( 6 ) == 0 ) g(); // prevent compiler inlining
22 else h();
23 i += 1;
[5416b44]24 sum += bsearchl( j, values, VALUES ); // has internal nested compare routine
[03656d1]25 } // h
26 h();
27 } // f
28 f();
[5416b44]29 __atomic_fetch_add( &total, sum, __ATOMIC_SEQ_CST );
[03656d1]30}
31int main() {
32 set_seed( 1003 );
33 for ( i; VALUES ) values[i] = i;
[5416b44]34 {
35 T t[5];
36 }
37 sout | "total" | total;
[03656d1]38}
Note: See TracBrowser for help on using the repository browser.