Changeset 94429f8
- Timestamp:
- Nov 12, 2020, 11:25:13 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- fe23950
- Parents:
- 654d5a47
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r654d5a47 r94429f8 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 19 15:05:28202013 // Update Count : 50 112 // Last Modified On : Thu Nov 12 07:46:09 2020 13 // Update Count : 503 14 14 // 15 15 … … 26 26 //--------------------------------------- 27 27 28 // allocation/deallocation and constructor/destructor, non-array types 29 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 30 T * new( Params p ) { 31 return &(*malloc()){ p }; // run constructor 32 } // new 33 34 forall( dtype T | { void ^?{}( T & ); } ) 35 void delete( T * ptr ) { 36 if ( ptr ) { // ignore null 37 ^(*ptr){}; // run destructor 38 free( ptr ); 39 } // if 40 } // delete 41 42 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) 43 void delete( T * ptr, Params rest ) { 44 delete( ptr ); 45 delete( rest ); 46 } // delete 47 48 49 // allocation/deallocation and constructor/destructor, array types 50 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 51 T * anew( size_t dim, Params p ) { 28 // Cforall allocation/deallocation and constructor/destructor, array types 29 30 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) 31 T * anew( size_t dim, TT p ) { 52 32 T * arr = alloc( dim ); 53 33 for ( unsigned int i = 0; i < dim; i += 1 ) { … … 68 48 } // adelete 69 49 70 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params); } )71 void adelete( T arr[], Paramsrest ) {50 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) 51 void adelete( T arr[], TT rest ) { 72 52 if ( arr ) { // ignore null 73 53 size_t dim = malloc_size( arr ) / sizeof( T ); -
libcfa/src/stdlib.hfa
r654d5a47 r94429f8 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Sep 1 20:32:34202013 // Update Count : 5 0512 // Last Modified On : Thu Nov 12 08:12:08 2020 13 // Update Count : 515 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "bits/defs.hfa" 19 #include "bits/align.hfa" 18 #include "bits/defs.hfa" // OPTIONAL_THREAD 19 #include "bits/align.hfa" // libAlign 20 20 21 21 #include <stdlib.h> // *alloc, strto*, ato* … … 104 104 void free( T * addr ) { 105 105 free( (void *) addr ); // C free 106 } // free107 } // distribution108 109 static inline forall( ttype TT | { void free( TT ); } ) {110 // T* does not take void* and vice-versa111 112 void free( void * addr, TT rest ) {113 free( addr );114 free( rest );115 } // free116 117 forall( dtype T | sized(T) )118 void free( T * addr, TT rest ) {119 free( addr );120 free( rest );121 106 } // free 122 107 } // distribution … … 177 162 static inline T_align ?`align ( size_t a ) { return (T_align){a}; } 178 163 static inline T_resize ?`resize ( void * a ) { return (T_resize){a}; } 164 179 165 static inline forall( dtype T | sized(T) ) { 180 181 166 S_fill(T) ?`fill ( T t ) { 182 167 S_fill(T) ret = { 't' }; … … 250 235 251 236 } // distribution TT 252 253 237 } // distribution T 254 238 … … 262 246 return (T *)memcpy( dest, src, sizeof(T) ); 263 247 } // memcpy 264 } // distribution 265 266 static inline forall( dtype T | sized(T) ) { 248 267 249 // Cforall safe initialization/copy, i.e., implicit size specification, array types 268 250 T * amemset( T dest[], char fill, size_t dim ) { … … 275 257 } // distribution 276 258 259 // Cforall deallocation for multiple objects 260 static inline forall( dtype T, ttype TT | { void free( TT ); } ) 261 void free( T * addr, TT rest ) { 262 free( addr ); 263 free( rest ); 264 } // free 265 277 266 // Cforall allocation/deallocation and constructor/destructor, non-array types 278 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p ); 279 forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr ); 280 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) 268 T * new( TT p ) { 269 return &(*malloc()){ p }; // run constructor 270 } // new 271 272 static inline forall( dtype T | { void ^?{}( T & ); } ) 273 void delete( T * ptr ) { 274 if ( ptr ) { // ignore null 275 ^(*ptr){}; // run destructor 276 free( ptr ); 277 } // if 278 } // delete 279 280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } ) 281 void delete( T * ptr, TT rest ) { 282 delete( ptr ); 283 delete( rest ); 284 } // delete 281 285 282 286 // Cforall allocation/deallocation and constructor/destructor, array types 283 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Paramsp );287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p ); 284 288 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); 285 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) void adelete( T arr[], Paramsrest );289 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest ); 286 290 287 291 //--------------------------------------- … … 379 383 //--------------------------------------- 380 384 381 extern bool threading_enabled( void) OPTIONAL_THREAD;385 extern bool threading_enabled( void ) OPTIONAL_THREAD; 382 386 383 387 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.