Ignore:
Timestamp:
Nov 12, 2020, 11:25:13 AM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
fe23950
Parents:
654d5a47
Message:

formatting, simplify "free" with multiple arguments, make "delete" inline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r654d5a47 r94429f8  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul 19 15:05:28 2020
    13 // Update Count     : 501
     12// Last Modified On : Thu Nov 12 07:46:09 2020
     13// Update Count     : 503
    1414//
    1515
     
    2626//---------------------------------------
    2727
    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
     30forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
     31T * anew( size_t dim, TT p ) {
    5232        T * arr = alloc( dim );
    5333        for ( unsigned int i = 0; i < dim; i += 1 ) {
     
    6848} // adelete
    6949
    70 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    71 void adelete( T arr[], Params rest ) {
     50forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } )
     51void adelete( T arr[], TT rest ) {
    7252        if ( arr ) {                                                                            // ignore null
    7353                size_t dim = malloc_size( arr ) / sizeof( T );
Note: See TracChangeset for help on using the changeset viewer.