source: translator/sum.c @ 51b7345

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51b7345 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 552 bytes
Line 
1// "./cfa -g sum.c"
2// "./cfa -CFA sum.c > sum_out.c"
3// "gcc32 -g sum_out.c LibCfa/libcfa.a"
4
5extern "C" {
6  int printf( const char *, ... );
7}
8
9context sumable( type T ) {
10    const T 0;
11    T ?+?(T, T);
12    T ?++(T*);
13    [T] ?+=?(T*,T);
14};
15
16forall( type T | sumable( T ) )
17    T sum( int n, T a[] ) {
18        T total = 0;
19        int i;
20        for ( i = 0; i < n; i += 1 )
21            total = total + a[i];
22        return total;
23    }
24
25int
26main()
27{
28  int a[ 10 ];
29  int i;
30  for( i = 0; i < 10; ++i ) {
31    a[ i ] = i;
32  }
33  printf( "the sum is %d\n", sum( 10, a ) );
34  return 0;
35}
Note: See TracBrowser for help on using the repository browser.