Changeset d3b7937 for src/examples
- Timestamp:
- Jan 29, 2016, 4:36:39 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- ae8b942
- Parents:
- f3fc8cbe
- Location:
- src/examples
- Files:
-
- 2 added
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/examples/Makefile.am
rf3fc8cbe rd3b7937 11 11 ## Created On : Sun May 31 09:08:15 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Fri Nov 20 16:03:46 201514 ## Update Count : 2 413 ## Last Modified On : Mon Jan 25 22:31:42 2016 14 ## Update Count : 25 15 15 ############################################################################### 16 16 … … 20 20 21 21 noinst_PROGRAMS = fstream_test vector_test # build but do not install 22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c23 vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c22 fstream_test_SOURCES = fstream_test.c 23 vector_test_SOURCES = vector_int.c array.c vector_test.c -
src/examples/Makefile.in
rf3fc8cbe rd3b7937 48 48 CONFIG_CLEAN_VPATH_FILES = 49 49 PROGRAMS = $(noinst_PROGRAMS) 50 am_fstream_test_OBJECTS = iostream.$(OBJEXT) fstream.$(OBJEXT) \ 51 fstream_test.$(OBJEXT) iterator.$(OBJEXT) 50 am_fstream_test_OBJECTS = fstream_test.$(OBJEXT) 52 51 fstream_test_OBJECTS = $(am_fstream_test_OBJECTS) 53 52 fstream_test_LDADD = $(LDADD) 54 am_vector_test_OBJECTS = vector_int.$(OBJEXT) fstream.$(OBJEXT) \ 55 iostream.$(OBJEXT) array.$(OBJEXT) iterator.$(OBJEXT) \ 53 am_vector_test_OBJECTS = vector_int.$(OBJEXT) array.$(OBJEXT) \ 56 54 vector_test.$(OBJEXT) 57 55 vector_test_OBJECTS = $(am_vector_test_OBJECTS) … … 176 174 top_builddir = @top_builddir@ 177 175 top_srcdir = @top_srcdir@ 178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c179 vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c176 fstream_test_SOURCES = fstream_test.c 177 vector_test_SOURCES = vector_int.c array.c vector_test.c 180 178 all: all-am 181 179 … … 191 189 esac; \ 192 190 done; \ 193 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/examples/Makefile'; \191 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/examples/Makefile'; \ 194 192 $(am__cd) $(top_srcdir) && \ 195 $(AUTOMAKE) -- foreignsrc/examples/Makefile193 $(AUTOMAKE) --gnu src/examples/Makefile 196 194 .PRECIOUS: Makefile 197 195 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status … … 229 227 230 228 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/array.Po@am__quote@ 231 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstream.Po@am__quote@232 229 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstream_test.Po@am__quote@ 233 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iostream.Po@am__quote@234 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iterator.Po@am__quote@235 230 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector_int.Po@am__quote@ 236 231 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector_test.Po@am__quote@ -
src/examples/alloc.c
rf3fc8cbe rd3b7937 1 #if 0 1 2 extern "C" { 2 3 typedef long unsigned int size_t; … … 15 16 return (T *)calloc( size, sizeof(T) ); 16 17 } 18 #endif 19 typedef int size_t; 17 20 forall( type T ) T * realloc( T *ptr, size_t n ) { 18 return (T *)(void *)realloc( ptr, sizeof(T) );21 // return (T *)(void *)realloc( ptr, sizeof(T) ); 19 22 } 20 forall( type T ) T * realloc( T *ptr, size_t n, T c ) {21 return (T *)realloc( ptr, n );22 }23 //forall( type T ) T * realloc( T *ptr, size_t n, T c ) { 24 // return (T *)realloc( ptr, n ); 25 //} 23 26 24 int *foo( int *p, int c );25 int *bar( int *p, int c );26 int *baz( int *p, int c );27 //int *foo( int *p, int c ); 28 //int *bar( int *p, int c ); 29 //int *baz( int *p, int c ); 27 30 28 31 int main( void ) { 29 size_t size = 10; 30 int * x = malloc(); 31 x = malloc(); 32 x = calloc( 10 ); // calloc: array set to 0 33 x = realloc( x, 10 ); 34 x = realloc( x, 10, '\0' ); 35 x = malloc( 5 ); 36 float *fp = malloc() + 1; 32 // size_t size = 10; 33 //int * x = malloc(); 34 int * x; 35 // x = malloc(); 36 // x = calloc( 10 ); // calloc: array set to 0 37 // x = realloc( x, 10 ); 38 // x = realloc( x, 10, '\0' ); 39 // x = malloc( 5 ); 40 // float *fp = malloc() + 1; 37 41 38 42 struct St1 { int x; double y; }; 39 43 struct St1 * st1; 40 double *y;44 // double *y; 41 45 x = realloc( st1, 10 ); // SHOULD FAIL!! 42 46 #if 0 -
src/examples/array.h
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:10:32 201513 // Update Count : 212 // Last Modified On : Tue Jan 26 17:09:29 2016 13 // Update Count : 3 14 14 // 15 15 … … 17 17 #define ARRAY_H 18 18 19 //#include "iterator.h"19 //#include <iterator> 20 20 21 21 // An array has contiguous elements accessible in any order using integer indicies. The first -
src/examples/constants.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon J un 8 20:44:48 201513 // Update Count : 7 512 // Last Modified On : Mon Jan 25 23:44:12 2016 13 // Update Count : 76 14 14 // 15 15 … … 54 54 L_"\x_ff_ee"; 55 55 L"a_b\r\Qyc\u_00_40 x_y_z\xff_AA"; 56 L_"a_b\r\Qyc\u_00_40\ 56 L_"a_b\r\Qyc\u_00_40\ 57 57 x_y_z\xff_AA"; 58 58 "abc" "def" "ghi"; -
src/examples/fstream_test.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:30:39201613 // Update Count : 4 112 // Last Modified On : Tue Jan 26 17:11:33 2016 13 // Update Count : 42 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 int main( void ) { -
src/examples/hello.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Nov 22 17:40:37 201513 // Update Count : 512 // Last Modified On : Tue Jan 26 17:11:49 2016 13 // Update Count : 7 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 int main() { … … 24 24 // Local Variables: // 25 25 // tab-width: 4 // 26 // compile-command: "cfa hello.c fstream.o iostream.o iterator.o" //26 // compile-command: "cfa hello.c" // 27 27 // End: // -
src/examples/identity.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 23:38:05201613 // Update Count : 612 // Last Modified On : Tue Jan 26 17:11:58 2016 13 // Update Count : 8 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 forall( type T ) … … 37 37 // Local Variables: // 38 38 // tab-width: 4 // 39 // compile-command: "cfa identity.c fstream.o iostream.o iterator.o" //39 // compile-command: "cfa identity.c" // 40 40 // End: // -
src/examples/minmax.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:40:51201613 // Update Count : 2612 // Last Modified On : Thu Jan 28 22:15:14 2016 13 // Update Count : 42 14 14 // 15 15 16 #include "fstream.h" 17 18 forall( type T | { int ?<?( T, T ); } ) 19 T min( const T t1, const T t2 ) { 20 return t1 < t2 ? t1 : t2; 21 } // min 16 #include <fstream> 17 #include <algorithm> 22 18 23 19 int main( void ) { 24 20 ofstream *sout = ofstream_stdout(); 25 // char does not have less than.21 // char does not have less or greater than. 26 22 int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; } 23 int ?>?( char op1, char op2 ) { return (int)op1 > (int)op2; } 27 24 28 25 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' ) | endl; … … 36 33 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmin " | min( 4.0, 3.1 ) | endl; 37 34 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmin " | min( 4.0l, 3.1l ) | endl; 35 sout | endl; 36 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' ) | endl; 37 sout | "signed int\t\t" | 4 | ' ' | 3 | "\tmax " | max( 4, 3 ) | endl; 38 sout | "unsigned int\t\t" | 4u | ' ' | 3u | "\tmax " | max( 4u, 3u ) | endl; 39 sout | "signed long int\t\t" | 4l | ' ' | 3l | "\tmax " | max( 4l, 3l ) | endl; 40 sout | "unsigned long int\t" | 4ul | ' ' | 3ul | "\tmax " | max( 4ul, 3ul ) | endl; 41 sout | "signed long long int\t" | 4ll | ' ' | 3ll | "\tmax " | max( 4ll, 3ll ) | endl; 42 sout | "unsigned long long int\t" | 4ull | ' ' | 3ull | "\tmax " | max( 4ull, 3ull ) | endl; 43 sout | "float\t\t\t" | 4.0f | ' ' | 3.1f | "\tmax " | max( 4.0f, 3.1f ) | endl; 44 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmax " | max( 4.0, 3.1 ) | endl; 45 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmax " | max( 4.0l, 3.1l ) | endl; 38 46 } // main 39 47 40 48 // Local Variables: // 41 49 // tab-width: 4 // 42 // compile-command: "cfa min .c fstream.o iostream.o iterator.o" //50 // compile-command: "cfa minmax.c" // 43 51 // End: // -
src/examples/new.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:23:55 201513 // Update Count : 112 // Last Modified On : Mon Jan 25 23:33:55 2016 13 // Update Count : 2 14 14 // 15 15 … … 25 25 t - 4; 26 26 t[7]; 27 7[t];28 27 } 29 28 -
src/examples/quad.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:26:36 201513 // Update Count : 212 // Last Modified On : Tue Jan 26 17:13:48 2016 13 // Update Count : 5 14 14 // 15 15 16 extern "C" { 17 #include <stdio.h> 18 } 16 #include <fstream> 19 17 20 18 forall( type T | { T ?*?( T, T ); } ) … … 29 27 30 28 int main() { 29 ofstream *sout = ofstream_stdout(); 31 30 int N = 2; 32 printf( "result of quad of %d is %d\n", N, quad( N ) );31 sout | "result of quad of " | N | " is " | quad( N ) | endl; 33 32 } 34 33 -
src/examples/quoted_keyword.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 3 22:46:28 201613 // Update Count : 712 // Last Modified On : Tue Jan 26 17:13:58 2016 13 // Update Count : 8 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 // test quoted keyword usage -
src/examples/square.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 5 18:08:20201613 // Update Count : 2 112 // Last Modified On : Tue Jan 26 17:14:16 2016 13 // Update Count : 25 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 forall( type T | { T ?*?( T, T ); } ) … … 35 35 sout | square( s ) | endl; 36 36 #endif 37 short ints = 9;37 short s = 9; 38 38 square( s ); 39 39 #if 0 … … 69 69 // Local Variables: // 70 70 // tab-width: 4 // 71 // compile-command: "cfa square.c fstream.o iostream.o iterator.o" //71 // compile-command: "cfa square.c" // 72 72 // End: // -
src/examples/sum.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 07:40:24201613 // Update Count : 1 2612 // Last Modified On : Thu Jan 28 17:05:53 2016 13 // Update Count : 130 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 context sumable( type T ) { … … 22 22 T ++?( T * ); 23 23 T ?++( T * ); 24 }; 24 }; // sumable 25 25 26 26 forall( type T | sumable( T ) ) … … 30 30 total += a[i]; // select + 31 31 return total; 32 } 32 } // sum 33 33 34 34 // Required to satisfy sumable as char does not have addition. … … 61 61 | sum( size, (int *)a ) | ", check " | (int)s | endl; 62 62 63 float s = 0.0, a[size]; 64 float v = low / 10.0; 65 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 66 s += (float)v; 67 a[i] = (float)v; 68 } 69 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 70 | sum( size, (float *)a ) | ", check " | (float)s | endl; 71 63 72 double s = 0.0, a[size]; 64 73 double v = low / 10.0; … … 69 78 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 70 79 | sum( size, (double *)a ) | ", check " | (double)s | endl; 71 72 float s = 0.0, a[size]; 73 float v = low / 10.0; 74 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 75 s += (float)v; 76 a[i] = (float)v; 77 } 78 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 79 | sum( size, (float *)a ) | ", check " | (float)s | endl; 80 } 80 } // main 81 81 82 82 // Local Variables: // 83 83 // tab-width: 4 // 84 // compile-command: "cfa sum.c fstream.o iostream.o iterator.o" //84 // compile-command: "cfa sum.c" // 85 85 // End: // -
src/examples/swap.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:32:25201613 // Update Count : 512 // Last Modified On : Tue Jan 26 16:49:41 2016 13 // Update Count : 7 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 forall( type T ) … … 33 33 // Local Variables: // 34 34 // tab-width: 4 // 35 // compile-command: "cfa swap.c fstream.o iostream.o iterator.o" //35 // compile-command: "cfa swap.c" // 36 36 // End: // -
src/examples/twice.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:32:04 201613 // Update Count : 1 012 // Last Modified On : Tue Jan 26 17:14:44 2016 13 // Update Count : 12 14 14 // 15 15 16 #include "fstream.h"16 #include <fstream> 17 17 18 18 forall( type T | { T ?+?( T, T ); T ?++( T * ); [T] ?+=?( T *, T ); } ) … … 33 33 // Local Variables: // 34 34 // tab-width: 4 // 35 // compile-command: "cfa twice.c fstream.o iostream.o iterator.o" //35 // compile-command: "cfa twice.c" // 36 36 // End: // -
src/examples/vector_test.c
rf3fc8cbe rd3b7937 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:31:56201613 // Update Count : 1 412 // Last Modified On : Tue Jan 26 17:14:52 2016 13 // Update Count : 17 14 14 // 15 15 16 #include "fstream.h" 16 #include <fstream> 17 #include <iterator> 17 18 #include "vector_int.h" 18 19 #include "array.h" 19 #include "iterator.h"20 20 21 21 int main( void ) { … … 46 46 // Local Variables: // 47 47 // tab-width: 4 // 48 // compile-command: "cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o" //48 // compile-command: "cfa vector_test.c vector_int.o array.o" // 49 49 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.