source: translator/sum.c@ a0d9f94

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since a0d9f94 was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 552 bytes
RevLine 
[51b73452]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.