source: translator/examples/sum.c @ a0d9f94

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newstringwith_gc
Last change on this file since a0d9f94 was a0d9f94, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

add compiler flag to driver, update examples, fix unnamed bit fields

  • Property mode set to 100644
File size: 539 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 ) )
17T 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 main() {
26    int a[10];
27    for ( int i = 0; i < 10; ++i ) {
28        a[i] = i;
29    }
30    printf( "the sum is %d\n", sum( 10, a ) );
31}
Note: See TracBrowser for help on using the repository browser.