Changeset 2afec66
- Timestamp:
- Jul 26, 2017, 5:24:33 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 25bd9074
- Parents:
- 8a6cf7e
- Location:
- src/tests
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/.expect/castError.txt
r8a6cf7e r2afec66 4 4 to: 5 5 char 6 Alternatives are: Cost ( 1, 0, 0 ): Cast of:6 Alternatives are: Cost ( 1, 0, 0, 0 ): Cast of: 7 7 Variable Expression: f: function 8 8 accepting unspecified arguments … … 18 18 Environment: 19 19 20 Cost ( 1, 0, 0 ): Cast of:20 Cost ( 1, 0, 0, 0 ): Cast of: 21 21 Variable Expression: f: signed int 22 22 … … 28 28 Environment: 29 29 30 Cost ( 1, 0, 0 ): Cast of:30 Cost ( 1, 0, 0, 0 ): Cast of: 31 31 Variable Expression: f: double 32 32 -
src/tests/alloc.c
r8a6cf7e r2afec66 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // … … 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // alloc.c -- 8 // 7 // alloc.c -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Wed Feb 3 07:56:22 2016 … … 12 12 // Last Modified On : Fri Jun 2 15:13:03 2017 13 13 // Update Count : 316 14 // 14 // 15 15 16 16 #include <assert> 17 17 extern "C" { 18 #include <malloc.h> 19 #include <stdint.h> 20 #include <stdlib.h> 18 #include <malloc.h> // malloc_usable_size 19 #include <stdint.h> // uintptr_t 20 #include <stdlib.h> // posix_memalign 21 21 } // extern 22 22 #include <fstream> 23 #include <stdlib> 23 #include <stdlib> // access C malloc, realloc 24 24 25 25 int * foo( int * p, int c ) { return p; } … … 28 28 29 29 int main( void ) { 30 31 30 size_t dim = 10; 31 int * p; 32 32 char fill = '\1'; 33 33 34 34 // allocation, non-array types 35 35 36 p = (void *)malloc( sizeof(*p) );// C malloc, type unsafe36 p = (void *)malloc( sizeof(*p) ); // C malloc, type unsafe 37 37 *p = 0xdeadbeef; 38 38 printf( "C malloc %#x\n", *p ); 39 40 41 p = malloc();// CFA malloc, type safe39 free( p ); 40 41 p = malloc(); // CFA malloc, type safe 42 42 *p = 0xdeadbeef; 43 43 printf( "CFA malloc %#x\n", *p ); 44 45 46 p = alloc();// CFA alloc, type safe44 free( p ); 45 46 p = alloc(); // CFA alloc, type safe 47 47 *p = 0xdeadbeef; 48 48 printf( "CFA alloc %#x\n", *p ); 49 50 51 p = alloc( fill );// CFA alloc, fill49 free( p ); 50 51 p = alloc( fill ); // CFA alloc, fill 52 52 printf( "CFA alloc, fill %08x\n", *p ); 53 53 … … 56 56 printf( "\n" ); 57 57 58 p = calloc( dim, sizeof( *p ) );// C array calloc, type unsafe58 p = calloc( dim, sizeof( *p ) ); // C array calloc, type unsafe 59 59 printf( "C array calloc, fill 0\n" ); 60 60 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } 61 61 printf( "\n" ); 62 63 64 p = calloc( dim );// CFA array calloc, type safe62 free( p ); 63 64 p = calloc( dim ); // CFA array calloc, type safe 65 65 printf( "CFA array calloc, fill 0\n" ); 66 66 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } 67 67 printf( "\n" ); 68 69 70 p = alloc( dim );// CFA array alloc, type safe68 free( p ); 69 70 p = alloc( dim ); // CFA array alloc, type safe 71 71 for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; } 72 72 printf( "CFA array alloc, no fill\n" ); 73 73 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } 74 74 printf( "\n" ); 75 76 77 p = alloc( 2 * dim, fill );// CFA array alloc, fill75 free( p ); 76 77 p = alloc( 2 * dim, fill ); // CFA array alloc, fill 78 78 printf( "CFA array alloc, fill %#x\n", fill ); 79 79 for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); } … … 85 85 printf( "\n" ); 86 86 87 p = (void *)realloc( p, dim * sizeof(*p) );// C realloc87 p = (void *)realloc( p, dim * sizeof(*p) ); // C realloc 88 88 for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; } 89 89 printf( "C realloc\n" ); … … 91 91 printf( "\n" ); 92 92 93 p = realloc( p, 2 * dim * sizeof(*p) );// CFA realloc93 p = realloc( p, 2 * dim * sizeof(*p) ); // CFA realloc 94 94 for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; } 95 95 printf( "CFA realloc\n" ); … … 102 102 printf( "\n" ); 103 103 104 p = alloc( p, dim );// CFA resize array alloc104 p = alloc( p, dim ); // CFA resize array alloc 105 105 for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; } 106 106 printf( "CFA resize alloc\n" ); … … 108 108 printf( "\n" ); 109 109 110 p = alloc( p, 2 * dim );// CFA resize array alloc110 p = alloc( p, 2 * dim ); // CFA resize array alloc 111 111 for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; } 112 112 printf( "CFA resize array alloc\n" ); … … 114 114 printf( "\n" ); 115 115 116 p = alloc( p, dim );// CFA array alloc116 p = alloc( p, dim ); // CFA array alloc 117 117 printf( "CFA resize array alloc\n" ); 118 118 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } … … 122 122 p = 0; 123 123 124 p = alloc( p, dim, fill );// CFA array alloc, fill124 p = alloc( p, dim, fill ); // CFA array alloc, fill 125 125 printf( "CFA resize array alloc, fill\n" ); 126 126 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } 127 127 printf( "\n" ); 128 128 129 p = alloc( p, 2 * dim, fill );// CFA array alloc, fill129 p = alloc( p, 2 * dim, fill ); // CFA array alloc, fill 130 130 printf( "CFA resize array alloc, fill\n" ); 131 131 for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); } 132 132 printf( "\n" ); 133 133 134 p = alloc( p, dim, fill );// CFA array alloc, fill134 p = alloc( p, dim, fill ); // CFA array alloc, fill 135 135 printf( "CFA resize array alloc, fill\n" ); 136 136 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] );; } … … 139 139 140 140 141 142 141 struct Struct { int x; double y; }; 142 Struct st, st1, sta[dim], sta1[dim], * stp, * stp1; 143 143 144 144 // alignment, non-array types … … 146 146 enum { Alignment = 128 }; 147 147 148 148 stp = (memalign( Alignment, sizeof( *stp ) ) ){ 42, 42.5 }; // C memalign 149 149 assert( (uintptr_t)stp % Alignment == 0 ); 150 150 printf( "C memalign %d %g\n", stp->x, stp->y ); 151 152 153 stp = (memalign( Alignment )){ 42, 42.5 };// CFA memalign151 free( stp ); 152 153 stp = (memalign( Alignment )){ 42, 42.5 }; // CFA memalign 154 154 assert( (uintptr_t)stp % Alignment == 0 ); 155 155 printf( "CFA memalign %d %g\n", stp->x, stp->y ); 156 157 158 posix_memalign( (void **)&stp, Alignment, sizeof( *stp ) );// C posix_memalign156 free( stp ); 157 158 posix_memalign( (void **)&stp, Alignment, sizeof( *stp ) ); // C posix_memalign 159 159 *stp = (Struct){ 42, 42.5 }; 160 160 assert( (uintptr_t)stp % Alignment == 0 ); 161 161 printf( "CFA posix_memalign %d %g\n", stp->x, stp->y ); 162 163 164 posix_memalign( &stp, Alignment );// CFA posix_memalign162 free( stp ); 163 164 posix_memalign( &stp, Alignment ); // CFA posix_memalign 165 165 *stp = (Struct){ 42, 42.5 }; 166 166 assert( (uintptr_t)stp % Alignment == 0 ); 167 167 printf( "CFA posix_memalign %d %g\n", stp->x, stp->y ); 168 169 170 stp = (aligned_alloc( Alignment )){ 42, 42.5 };// CFA aligned_alloc168 free( stp ); 169 170 stp = (aligned_alloc( Alignment )){ 42, 42.5 }; // CFA aligned_alloc 171 171 assert( (uintptr_t)stp % Alignment == 0 ); 172 172 printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y ); 173 174 175 stp = (align_alloc( Alignment )){ 42, 42.5 };// CFA align_alloc173 free( stp ); 174 175 stp = (align_alloc( Alignment )){ 42, 42.5 }; // CFA align_alloc 176 176 assert( (uintptr_t)stp % Alignment == 0 ); 177 177 printf( "CFA align_alloc %d %g\n", stp->x, stp->y ); 178 179 180 stp = align_alloc( Alignment, fill );// CFA memalign, fill178 free( stp ); 179 180 stp = align_alloc( Alignment, fill ); // CFA memalign, fill 181 181 assert( (uintptr_t)stp % Alignment == 0 ); 182 182 printf( "CFA align_alloc fill %#x %a\n", stp->x, stp->y ); 183 183 free( stp ); 184 184 185 185 … … 187 187 printf( "\n" ); 188 188 189 stp = align_alloc( Alignment, dim );// CFA array memalign189 stp = align_alloc( Alignment, dim ); // CFA array memalign 190 190 assert( (uintptr_t)stp % Alignment == 0 ); 191 191 for ( int i = 0; i < dim; i += 1 ) { stp[i] = (Struct){ 42, 42.5 }; } … … 193 193 for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 194 194 printf( "\n" ); 195 196 197 stp = align_alloc( Alignment, dim, fill );// CFA array memalign, fill195 free( stp ); 196 197 stp = align_alloc( Alignment, dim, fill ); // CFA array memalign, fill 198 198 assert( (uintptr_t)stp % Alignment == 0 ); 199 199 printf( "CFA array align_alloc, fill\n" ); 200 200 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); } 201 201 printf( "\n" ); 202 202 free( stp ); 203 203 204 204 … … 206 206 printf( "\n" ); 207 207 208 memset( &st, fill );// CFA memset, type safe208 memset( &st, fill ); // CFA memset, type safe 209 209 printf( "CFA memset %#x %a\n", st.x, st.y ); 210 memcpy( &st1, &st );// CFA memcpy, type safe210 memcpy( &st1, &st ); // CFA memcpy, type safe 211 211 printf( "CFA memcpy %#x %a\n", st1.x, st1.y ); 212 212 … … 215 215 printf( "\n" ); 216 216 217 memset( sta, dim, fill );// CFA array memset, type safe217 memset( sta, dim, fill ); // CFA array memset, type safe 218 218 printf( "CFA array memset\n" ); 219 219 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta[i].x, sta[i].y ); } 220 220 printf( "\n" ); 221 221 222 memcpy( sta1, sta, dim );// CFA array memcpy, type safe222 memcpy( sta1, sta, dim ); // CFA array memcpy, type safe 223 223 printf( "CFA memcpy\n" ); 224 224 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta1[i].x, sta1[i].y ); } … … 247 247 printf( "\n" ); 248 248 249 250 251 252 253 249 float * fp = malloc() + 1; 250 printf( "pointer arithmetic %d\n", fp == fp - 1 ); 251 free( fp - 1 ); 252 253 p = foo( bar( baz( malloc(), 0 ), 0 ), 0 ); 254 254 *p = 0xdeadbeef; 255 255 printf( "CFA deep malloc %#x\n", *p ); 256 256 free( p ); 257 257 258 258 stp = malloc(); 259 259 printf( "\nSHOULD FAIL\n" ); 260 261 262 260 p = alloc( stp, dim * sizeof(*stp) ); 261 p = memset( stp, 10 ); 262 p = memcpy( &st1, &st ); 263 263 } // main 264 264 -
src/tests/avltree/avl.h
r8a6cf7e r2afec66 23 23 // forall( otype T, ttype Params | { void ?{}(T *, Params); } ) T * new( Params p ); 24 24 25 forall(dtype T | { void ^?{}(T *); })25 forall(dtype T | { void ^?{}(T &); }) 26 26 void delete(T * x); 27 27 … … 59 59 60 60 forall(otype K | Comparable(K), otype V) 61 void ?{}(tree(K, V) *t, K key, V value);61 void ?{}(tree(K, V) &t, K key, V value); 62 62 63 63 forall(otype K, otype V) 64 void ^?{}(tree(K, V) *t);64 void ^?{}(tree(K, V) & t); 65 65 66 66 forall(otype K | Comparable(K), otype V) -
src/tests/avltree/avl1.c
r8a6cf7e r2afec66 3 3 4 4 forall(otype K | Comparable(K), otype V) 5 void ?{}(tree(K, V) *t, K key, V value){6 ( &t->key) { key };7 ( &t->value) { value };8 t ->parent = NULL;9 t ->left = NULL;10 t ->right = NULL;11 t ->balance = 0;5 void ?{}(tree(K, V) &t, K key, V value){ 6 (t.key) { key }; 7 (t.value) { value }; 8 t.parent = NULL; 9 t.left = NULL; 10 t.right = NULL; 11 t.balance = 0; 12 12 } 13 13 14 14 forall(otype K, otype V) 15 void ^?{}(tree(K, V) *t){16 delete(t ->left);17 delete(t ->right);18 ^( &t->key){};19 ^( &t->value){};15 void ^?{}(tree(K, V) & t){ 16 delete(t.left); 17 delete(t.right); 18 ^(t.key){}; 19 ^(t.value){}; 20 20 } 21 21 … … 24 24 // infinite loop trying to resolve ... t = malloc(); 25 25 tree(K, V) * t = malloc(sizeof(tree(K,V))); 26 t{ key, value };26 (*t){ key, value }; 27 27 return t; 28 28 } -
src/tests/dtor-early-exit.c
r8a6cf7e r2afec66 27 27 28 28 // don't want these called 29 void ?{}(A *a) { assert( false ); }30 void ?{}(A * a, const char * name) { a->name = name; sout | "construct " | name | endl; a->x = (int*)malloc(); }31 void ?{}(A *a, const char * name, int * ptr) { assert( false ); }32 33 A ?=?(A * a, A a) { sout | "assign " | a->name | " " | a.name; return a; }34 void ?{}(A * a, A a) { sout | "copy construct " | a.name | endl; a->x = (int*)malloc(); }35 void ^?{}(A * a) { sout | "destruct " | a->name | endl; free(a->x); }29 void ?{}(A & a) { assert( false ); } 30 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); } 31 void ?{}(A & a, const char * name, int * ptr) { assert( false ); } 32 33 A ?=?(A & a, A b) { sout | "assign " | a.name | " " | b.name; return a; } 34 void ?{}(A & a, A b) { sout | "copy construct " | b.name | endl; a.x = (int*)malloc(); } 35 void ^?{}(A & a) { sout | "destruct " | a.name | endl; free(a.x); } 36 36 37 37 // test returns -
src/tests/globals.c
r8a6cf7e r2afec66 5 5 }; 6 6 7 void ?{}( value_t * this ) { this->value = 22; }7 void ?{}( value_t & this ) { this.value = 22; } 8 8 9 9 //Standard case … … 12 12 }; 13 13 14 void ?{}( g_t * this ) { (&this->val){}; }14 void ?{}( g_t & this ) { (this.val){}; } 15 15 16 16 g_t g; … … 25 25 //Inline case 26 26 struct gi_t; 27 void ?{}( gi_t *this );27 void ?{}( gi_t & this ); 28 28 29 29 struct gi_t { … … 31 31 } gi; 32 32 33 void ?{}( gi_t * this ) { (&this->val){}; }33 void ?{}( gi_t & this ) { (this.val){}; } 34 34 35 35 //Inline autogen case … … 43 43 }; 44 44 45 void ?{}( gs_t * this ) { (&this->val){}; }45 void ?{}( gs_t & this ) { (this.val){}; } 46 46 47 47 static gs_t gs; … … 56 56 //Static inline case 57 57 struct gsi_t; 58 void ?{}( gsi_t *this );58 void ?{}( gsi_t & this ); 59 59 60 60 static struct gsi_t { … … 62 62 } gsi; 63 63 64 void ?{}( gsi_t * this ) { (&this->val){}; }64 void ?{}( gsi_t & this ) { (this.val){}; } 65 65 66 66 //Static inline autogen case -
src/tests/init_once.c
r8a6cf7e r2afec66 60 60 return -1; 61 61 } 62 void ?{}(array *arr) {63 memset(arr ->elems, 0, sizeof(arr->elems));64 arr ->length = 0;62 void ?{}(array & arr) { 63 memset(arr.elems, 0, sizeof(arr.elems)); 64 arr.length = 0; 65 65 } 66 66 array constructed; 67 67 array destructed; 68 68 69 void ?{}(init_once *x) {70 assert( find( &constructed, x ) == -1 );71 remove( &destructed, x );72 insert( &constructed, x );69 void ?{}(init_once & x) { 70 assert( find( &constructed, &x ) == -1 ); 71 remove( &destructed, &x ); 72 insert( &constructed, &x ); 73 73 74 x ->x = malloc(sizeof(int));74 x.x = malloc(sizeof(int)); 75 75 } 76 76 77 void ?{}(init_once *x, init_once other) {77 void ?{}(init_once & x, init_once other) { 78 78 x{}; // reuse default ctor 79 79 } 80 80 81 void ^?{}(init_once *x) {82 assert( find( &destructed, x ) == -1 );83 remove( &constructed, x );84 insert( &destructed, x );81 void ^?{}(init_once & x) { 82 assert( find( &destructed, &x ) == -1 ); 83 remove( &constructed, &x ); 84 insert( &destructed, &x ); 85 85 86 free(x ->x);86 free(x.x); 87 87 } 88 88 //*** end setup … … 125 125 init_once x; 126 126 init_once y = x; 127 (&x){}; // ensure this doesn't execute127 x{}; // ensure this doesn't execute 128 128 break; 129 129 } -
src/tests/memberCtors.c
r8a6cf7e r2afec66 3 3 }; 4 4 5 void ?{}(WrappedInt *this) {5 void ?{}(WrappedInt & this) { 6 6 printf("constructing int\n"); 7 this ->x = 0;7 this.x = 0; 8 8 } 9 9 10 void ?{}(WrappedInt *this, WrappedInt other) {10 void ?{}(WrappedInt & this, WrappedInt other) { 11 11 printf("copy constructing int: %d\n", other.x); 12 this ->x = other.x;12 this.x = other.x; 13 13 } 14 14 15 void ?{}(WrappedInt *this, int x) {15 void ?{}(WrappedInt & this, int x) { 16 16 printf("constructing int: %d\n", x); 17 this ->x = x;17 this.x = x; 18 18 } 19 19 20 void ^?{}(WrappedInt *this) {21 printf("destructing int: %d\n", this ->x);20 void ^?{}(WrappedInt & this) { 21 printf("destructing int: %d\n", this.x); 22 22 } 23 23 24 void ?=?(WrappedInt *this, int x) {25 printf("assigning int: %d %d\n", this ->x, x);26 this ->x = x;24 void ?=?(WrappedInt & this, int x) { 25 printf("assigning int: %d %d\n", this.x, x); 26 this.x = x; 27 27 } 28 28 … … 31 31 }; 32 32 33 void ?{}(A *a) {33 void ?{}(A & a) { 34 34 // currently must define default ctor, since there's no "= default" syntax 35 35 } 36 36 37 void ?{}(A *a, int x) {37 void ?{}(A & a, int x) { 38 38 printf("begin construct A\n"); 39 printf("construct a ->x\n");40 ( &a->x){ x+999 };41 printf("assign a ->y\n");42 a ->y = 0; // not a constructor - default constructor will be inserted39 printf("construct a.x\n"); 40 (a.x){ x+999 }; 41 printf("assign a.y\n"); 42 a.y = 0; // not a constructor - default constructor will be inserted 43 43 printf("end construct A\n"); 44 44 } // z never constructed - will be automatically default constructed 45 45 46 void ?{}(A *this, A other) {46 void ?{}(A & this, A other) { 47 47 printf("begin copy construct A\n"); 48 printf("copy construct this ->x\n");49 ( &this->x){ other.x };50 printf("assign this ->y\n");51 this ->y = other.y; // not a constructor - copy constructor will be inserted48 printf("copy construct this.x\n"); 49 (this.x){ other.x }; 50 printf("assign this.y\n"); 51 this.y = other.y; // not a constructor - copy constructor will be inserted 52 52 printf("end copy construct A\n"); 53 53 } // z never constructed - will be automatically copy constructed 54 54 55 A ?=?(A *this, A other) {55 A ?=?(A & this, A other) { 56 56 printf("begin ?=? A\n"); 57 this ->x = other.x;58 this ->y = other.y;59 this ->z = other.z;57 this.x = other.x; 58 this.y = other.y; 59 this.z = other.z; 60 60 printf("end ?=? A\n"); 61 return *this;61 return this; 62 62 } 63 63 … … 66 66 }; 67 67 68 void ?{}(B *b) {68 void ?{}(B & b) { 69 69 printf("begin construct B\n"); 70 printf("assign b ->a2\n");71 b ->a2 = (A) { 2 };72 printf("construct b ->a1\n");73 ( &b->a1){ 1 };70 printf("assign b.a2\n"); 71 b.a2 = (A) { 2 }; 72 printf("construct b.a1\n"); 73 (b.a1){ 1 }; 74 74 #ifdef ERR1 75 ( &b->a2){ b->a3 }; // error, b->a2 was used previously but is explicitly constructed75 (b.a2){ b.a3 }; // error, b->a2 was used previously but is explicitly constructed 76 76 #endif 77 77 printf("end construct B\n"); 78 78 } // a2, a3 never constructed - will be automatically default constructed 79 79 80 void ^?{}(B *b) {81 b ->a2 = (A) { 0 };82 ^( &b->a1){};80 void ^?{}(B & b) { 81 b.a2 = (A) { 0 }; 82 ^(b.a1){}; 83 83 } // a2, a3 never destructed - will be automatically destructed 84 84 -
src/tests/multiDimension.c
r8a6cf7e r2afec66 4 4 }; 5 5 6 void ?{}(X *this) {6 void ?{}(X & this) { 7 7 printf("default constructing\n"); 8 ( &this->a){ 123 };9 this ->ptr = malloc(sizeof(int));8 (this.a){ 123 }; 9 this.ptr = malloc(sizeof(int)); 10 10 } 11 11 12 void ?{}(X *this, X other) {12 void ?{}(X & this, X other) { 13 13 printf("copy constructing\n"); 14 ( &this->a){ other.a };15 this ->ptr = malloc(sizeof(int));14 (this.a){ other.a }; 15 this.ptr = malloc(sizeof(int)); 16 16 } 17 17 18 void ?{}(X *this, int a) {18 void ?{}(X & this, int a) { 19 19 printf("constructing with %d\n", a); 20 ( &this->a){ a };21 this ->ptr = malloc(sizeof(int));20 (this.a){ a }; 21 this.ptr = malloc(sizeof(int)); 22 22 } 23 23 24 void ^?{}(X *this) {24 void ^?{}(X & this) { 25 25 printf("destructing\n"); 26 free(this ->ptr);26 free(this.ptr); 27 27 } 28 28 29 X ?=?(X *this, X other) {30 this ->a = other.a;31 return *this;29 X ?=?(X & this, X other) { 30 this.a = other.a; 31 return this; 32 32 } 33 33 -
src/tests/operators.c
r8a6cf7e r2afec66 11 11 } 12 12 13 int ?=?( int *a, int b ) {13 int ?=?( int &a, int b ) { 14 14 return 0; 15 15 } -
src/tests/preempt.c
r8a6cf7e r2afec66 16 16 }; 17 17 18 void ?{}( worker_t *this, int value ) {19 this ->value = value;18 void ?{}( worker_t & this, int value ) { 19 this.value = value; 20 20 } 21 21 -
src/tests/rational.c
r8a6cf7e r2afec66 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 6 // 7 7 // rational.c -- test rational number package 8 // 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Mon Mar 28 08:43:12 2016 … … 12 12 // Last Modified On : Wed May 17 15:46:35 2017 13 13 // Update Count : 65 14 // 14 // 15 15 16 16 #include <rational> … … 20 20 21 21 // UNNECESSARY, FIX ME 22 void ?{}( int * this ) { *this = 0; }23 void ?{}( int * this, zero_t ) { *this = 0; }24 void ?{}( int * this, one_t ) { *this = 1; }22 void ?{}( int & this ) { this = 0; } 23 void ?{}( int & this, zero_t ) { this = 0; } 24 void ?{}( int & this, one_t ) { this = 1; } 25 25 double convert( int i ) { return (double)i; } 26 26 int convert( double d ) { return (int)d; } -
src/tests/sched-int-barge.c
r8a6cf7e r2afec66 19 19 }; 20 20 21 void ?{} ( global_data_t *this ) {22 this ->done = false;23 this ->counter = 0;24 this ->state = BARGE;21 void ?{} ( global_data_t & this ) { 22 this.done = false; 23 this.counter = 0; 24 this.state = BARGE; 25 25 26 this ->do_signal = 6;27 this ->do_wait1 = 1;28 this ->do_wait2 = 3;26 this.do_signal = 6; 27 this.do_wait1 = 1; 28 this.do_wait2 = 3; 29 29 } 30 30 31 void ^?{} ( global_data_t *this ) {}31 void ^?{} ( global_data_t & this ) {} 32 32 33 33 global_t globalA; -
src/tests/sched-int-disjoint.c
r8a6cf7e r2afec66 14 14 15 15 monitor global_data_t; 16 void ?{}( global_data_t *this );17 void ^?{} ( global_data_t *this );16 void ?{}( global_data_t & this ); 17 void ^?{} ( global_data_t & this ); 18 18 19 19 monitor global_data_t { … … 26 26 volatile bool all_done; 27 27 28 void ?{}( global_data_t *this ) {29 this ->counter == 0;30 this ->state = BARGE;28 void ?{}( global_data_t & this ) { 29 this.counter == 0; 30 this.state = BARGE; 31 31 } 32 32 33 void ^?{} ( global_data_t *this ) {}33 void ^?{} ( global_data_t & this ) {} 34 34 35 35 //------------------------------------------------------------------------------ -
src/tests/test.py
r8a6cf7e r2afec66 31 31 # parses the Makefile to find the machine type (32-bit / 64-bit) 32 32 def getMachineType(): 33 sh('echo "void ?{}(int *a,int b){}int main(){return 0;}" > .dummy.c')33 sh('echo "void ?{}(int&a,int b){}int main(){return 0;}" > .dummy.c') 34 34 ret, out = sh("make .dummy -s", print2stdout=True) 35 35 -
src/tests/tupleAssign.c
r8a6cf7e r2afec66 48 48 int z; 49 49 } x; 50 X ?=?(X *x, double d) {}50 X ?=?(X & x, double d) {} 51 51 [int, double, int] t; 52 52 -
src/tests/tupleVariadic.c
r8a6cf7e r2afec66 29 29 } 30 30 31 forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } )31 forall( dtype T, ttype Params | sized(T) | { void ?{}(T &, Params); } ) 32 32 T * new(Params p); 33 33 … … 38 38 39 39 // xxx - eventually this will be collapsed...x 40 void ?{}(array *a) {41 a ->size = 0;42 a ->data = 0;40 void ?{}(array & a) { 41 a.size = 0; 42 a.data = 0; 43 43 printf("called ?{} with no a\n"); 44 44 } 45 45 46 void ?{}(array *a, int a0) {47 a ->size = 1;48 a ->data = (int*)malloc(sizeof(int)*a->size);49 a ->data[0] = a0;46 void ?{}(array & a, int a0) { 47 a.size = 1; 48 a.data = (int*)malloc(sizeof(int)*a.size); 49 a.data[0] = a0; 50 50 printf("called ?{} with a: %d\n", a0); 51 51 } 52 52 53 void ?{}(array *a, int a0, int a1) {54 a ->size = 2;55 a ->data = (int*)malloc(sizeof(int)*a->size);56 a ->data[0] = a0;57 a ->data[1] = a1;53 void ?{}(array & a, int a0, int a1) { 54 a.size = 2; 55 a.data = (int*)malloc(sizeof(int)*a.size); 56 a.data[0] = a0; 57 a.data[1] = a1; 58 58 printf("called ?{} with a: %d %d\n", a0, a1); 59 59 } 60 60 61 void ?{}(array *a, int a0, int a1, int a2) {62 a ->size = 3;63 a ->data = (int*)malloc(sizeof(int)*a->size);64 a ->data[0] = a0;65 a ->data[1] = a1;66 a ->data[2] = a2;61 void ?{}(array & a, int a0, int a1, int a2) { 62 a.size = 3; 63 a.data = (int*)malloc(sizeof(int)*a.size); 64 a.data[0] = a0; 65 a.data[1] = a1; 66 a.data[2] = a2; 67 67 printf("called ?{} with a: %d %d %d\n", a0, a1, a2); 68 68 } 69 69 70 70 // test use of a tuple argument 71 [void] ?{}(array *a, [int, int, int, int] args) {71 [void] ?{}(array & a, [int, int, int, int] args) { 72 72 int a0, a1, a2, a3; 73 73 [a0, a1, a2, a3] = args; 74 a ->size = 4;75 a ->data = malloc(sizeof(int)*a->size);76 a ->data[0] = a0;77 a ->data[1] = a1;78 a ->data[2] = a2;79 a ->data[3] = a3;74 a.size = 4; 75 a.data = malloc(sizeof(int)*a.size); 76 a.data[0] = a0; 77 a.data[1] = a1; 78 a.data[2] = a2; 79 a.data[3] = a3; 80 80 printf("called ?{} with a: %d %d %d %d\n", a0, a1, a2, a3); 81 81 } -
src/tests/vector/vector_int.c
r8a6cf7e r2afec66 20 20 #define DEFAULT_CAPACITY 20 21 21 22 void ?{}( vector_int *vec ) {22 void ?{}( vector_int & vec ) { 23 23 vec { DEFAULT_CAPACITY }; 24 24 } 25 25 26 void ?{}( vector_int *vec, int reserve ) {27 vec ->last = -1;28 vec ->capacity = reserve;29 vec ->data = malloc( sizeof( int ) * reserve );26 void ?{}( vector_int & vec, int reserve ) { 27 vec.last = -1; 28 vec.capacity = reserve; 29 vec.data = malloc( sizeof( int ) * reserve ); 30 30 } 31 31 32 void ?{}( vector_int *vec, vector_int other ) {33 vec ->last = other.last;34 vec ->capacity = other.capacity;35 vec ->data = malloc( sizeof( int ) * other.capacity );36 for (int i = 0; i < vec ->last; i++) {37 vec ->data[i] = other.data[i];32 void ?{}( vector_int & vec, vector_int other ) { 33 vec.last = other.last; 34 vec.capacity = other.capacity; 35 vec.data = malloc( sizeof( int ) * other.capacity ); 36 for (int i = 0; i < vec.last; i++) { 37 vec.data[i] = other.data[i]; 38 38 } 39 39 } 40 40 41 void ^?{}( vector_int *vec ) {41 void ^?{}( vector_int & vec ) { 42 42 free( vec->data ); 43 43 } -
src/tests/vector/vector_int.h
r8a6cf7e r2afec66 25 25 } vector_int; 26 26 27 void ?{}( vector_int *); // allocate vector with default capacity28 void ?{}( vector_int *, int reserve ); // allocate vector with specified capacity29 void ?{}( vector_int *vec, vector_int other ); // copy constructor30 void ^?{}( vector_int *); // deallocate vector's storage27 void ?{}( vector_int & ); // allocate vector with default capacity 28 void ?{}( vector_int &, int reserve ); // allocate vector with specified capacity 29 void ?{}( vector_int & vec, vector_int other ); // copy constructor 30 void ^?{}( vector_int & ); // deallocate vector's storage 31 31 32 32 void reserve( vector_int *vec, int reserve ); // reserve more capacity
Note: See TracChangeset
for help on using the changeset viewer.