Changeset 1ad1c99


Ignore:
Timestamp:
Apr 27, 2016, 5:35:59 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
84bb4d9
Parents:
21ae786
Message:

modified vector_test to use constructors and destructors

Location:
src/examples
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/examples/array.c

    r21ae786 r1ad1c99  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // array.c -- 
     7// array.c --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 18:13:52 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 27 17:21:52 2016
    1313// Update Count     : 3
    1414//
     
    2626// The first element is always at index 0.
    2727forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
    28 elt_type * begin( array_type array ) {
     28elt_type * begin( array_type * array ) {
    2929        return &array[ 0 ];
    3030}
     
    3232// The end iterator should point one past the last element.
    3333forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
    34 elt_type * end( array_type array ) {
     34elt_type * end( array_type * array ) {
    3535        return &array[ last( array ) ] + 1;
    3636}
  • src/examples/array.h

    r21ae786 r1ad1c99  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // array.h -- 
     7// array.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 18:13:35 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 27 17:26:04 2016
    1313// Update Count     : 5
    1414//
     
    2626
    2727// A bounded array is an array that carries its maximum index with it.
    28 trait bounded_array( otype array_type, otype elt_type | array( array_type, elt_type ) ) {
    29         int last( array_type );
     28trait bounded_array( otype array_type, otype elt_type | array( array_type *, elt_type ) ) {
     29        int last( array_type * );
    3030};
    3131
     
    4141// return iterators corresponding to the first element and the one-past-the-end element, STL-style.
    4242forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
    43 elt_type *begin( array_type );
     43elt_type * begin( array_type * array );
    4444
     45// The end iterator should point one past the last element.
    4546forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
    46 elt_type *end( array_type );
     47elt_type * end( array_type * array );
    4748
    4849#endif // ARRAY_H
  • src/examples/vector_int.c

    r21ae786 r1ad1c99  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Apr 06 17:18:31 2016
     12// Last Modified On : Wed Apr 27 17:27:12 2016
    1313// Update Count     : 3
    1414//
     
    3030        vec->capacity = reserve;
    3131        vec->data = malloc( sizeof( int ) * reserve );
     32}
     33
     34void ?{}( vector_int * vec, vector_int other ) {
     35        vec->last = other.last;
     36        vec->capacity = other.capacity;
     37        vec->data = malloc( sizeof( int ) * other.capacity );
     38        for (int i = 0; i < vec->last; i++) {
     39                vec->data[i] = other.data[i];
     40        }
    3241}
    3342
     
    5463// implement bounded_array
    5564
    56 lvalue int ?[?]( vector_int vec, int index ) {
    57         return vec.data[ index ];
     65lvalue int ?[?]( vector_int * vec, int index ) {
     66        return vec->data[ index ];
    5867}
    5968
    60 int last( vector_int vec ) {
    61         return vec.last;
     69int last( vector_int * vec ) {
     70        return vec->last;
    6271}
    6372
  • src/examples/vector_int.h

    r21ae786 r1ad1c99  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Apr 06 17:21:59 2016
     12// Last Modified On : Wed Apr 27 17:26:59 2016
    1313// Update Count     : 2
    1414//
     
    2626
    2727void ?{}( vector_int * );                                                               // allocate vector with default capacity
    28 void ?{}( vector_int *, int reserve );                                  // allocate vector with specified capacity
     28void ?{}( vector_int *, int reserve );          // allocate vector with specified capacity
     29void ?{}( vector_int * vec, vector_int other ); // copy constructor
    2930void ^?{}( vector_int * );                                                              // deallocate vector's storage
    3031
     
    3435// implement bounded_array
    3536
    36 lvalue int ?[?]( vector_int vec, int index );                   // access to arbitrary element (does not resize)
    37 int last( vector_int vec );                                                             // return last element
     37lvalue int ?[?]( vector_int * vec, int index );                 // access to arbitrary element (does not resize)
     38int last( vector_int * vec );                                                           // return last element
    3839
    3940#endif // VECTOR_INT_H
  • src/examples/vector_test.c

    r21ae786 r1ad1c99  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Apr 06 17:19:07 2016
     12// Last Modified On : Wed Apr 27 17:31:27 2016
    1313// Update Count     : 18
    1414//
     
    3434
    3535        sout | "Array elements:" | endl;
    36         write( begin( vec ), end( vec ), sout );
     36        write( begin( &vec ), end( &vec ), sout );
    3737        sout | endl;
    3838
    3939        sout | "Array elements reversed:" | endl;
    40         write_reverse( begin( vec ), end( vec ), sout );
     40        write_reverse( begin( &vec ), end( &vec ), sout );
    4141        sout | endl;
    4242}
Note: See TracChangeset for help on using the changeset viewer.