Changes in / [a6fe3de:89e6ffc]
- Location:
- src
- Files:
-
- 1 deleted
- 7 edited
-
examples/gc_no_raii/src/internal/card_table.h (modified) (1 diff)
-
examples/gc_no_raii/src/internal/memory_pool.c (modified) (3 diffs)
-
examples/gc_no_raii/src/internal/memory_pool.h (modified) (2 diffs)
-
examples/gc_no_raii/src/internal/state.c (modified) (1 diff)
-
libcfa/containers/vector (modified) (13 diffs)
-
libcfa/containers/vector.c (modified) (6 diffs)
-
tests/.expect/libcfa_vector.txt (deleted)
-
tests/libcfa_vector.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/gc_no_raii/src/internal/card_table.h
ra6fe3de r89e6ffc 18 18 }; 19 19 20 static inline void ?{}(card_table_t*this)20 static inline void ctor_card(card_table_t* const this) 21 21 { 22 22 this->count = 0; 23 23 } 24 24 25 static inline void ^?{}(card_table_t*this)25 static inline void dtor_card(card_table_t* const this) 26 26 { 27 27 -
src/examples/gc_no_raii/src/internal/memory_pool.c
ra6fe3de r89e6ffc 11 11 const size_t gc_pool_header_size = (size_t)( &(((gc_memory_pool*)NULL)->start_p) ); 12 12 13 void ?{}(gc_memory_pool*this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type)13 void ctor(gc_memory_pool *const this, size_t size, gc_memory_pool* next, gc_memory_pool* mirror, uint8_t type) 14 14 { 15 15 this->mirror = mirror; … … 17 17 this->type_code = type; 18 18 19 this->cards = ( (card_table_t*)malloc(sizeof(card_table_t)) ){}; 19 card_table_t* new = (card_table_t*)malloc(sizeof(card_table_t)); 20 this->cards = new; 21 ctor_card(this->cards); 20 22 21 23 this->end_p = ((uint8_t*)this) + size; … … 27 29 } 28 30 29 void ^?{}(gc_memory_pool*this)31 void dtor(gc_memory_pool *const this) 30 32 { 31 ^(&this->cards){};33 dtor_card(this->cards); 32 34 free(this->cards); 33 35 } -
src/examples/gc_no_raii/src/internal/memory_pool.h
ra6fe3de r89e6ffc 27 27 }; 28 28 29 void ?{}( gc_memory_pool*this,29 void ctor( gc_memory_pool *const this, 30 30 size_t size, 31 31 gc_memory_pool* next, … … 34 34 ); 35 35 36 void ^?{}(gc_memory_pool*this);36 void dtor(gc_memory_pool *const this); 37 37 38 38 struct gc_pool_object_iterator -
src/examples/gc_no_raii/src/internal/state.c
ra6fe3de r89e6ffc 131 131 132 132 this->from_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1)); 133 this->to_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1));134 135 this->from_space{ POOL_SIZE_BYTES, old_from_space, this->to_space, this->from_code };136 this->to_space { POOL_SIZE_BYTES, old_to_space, this->from_space, (~this->from_code) & 0x01 };133 this->to_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1)); 134 135 ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space, this->from_code); 136 ctor(this->to_space, POOL_SIZE_BYTES, old_to_space, this->from_space, (~this->from_code) & 0x01); 137 137 138 138 this->total_space += gc_pool_size_used(this->from_space); -
src/libcfa/containers/vector
ra6fe3de r89e6ffc 20 20 } 21 21 22 #define DESTROY(x) 23 22 24 //------------------------------------------------------------------------------ 23 25 //Declaration 24 26 trait allocator_c(otype T, otype allocator_t) 25 27 { 26 void realloc_storage(allocator_t*, size_t); 27 T* data(allocator_t*); 28 void ctor(allocator_t* const); 29 void dtor(allocator_t* const); 30 void realloc_storage(allocator_t* const, size_t); 31 T* data(allocator_t* const); 28 32 }; 29 30 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))31 struct vector;32 33 //------------------------------------------------------------------------------34 //Initialization35 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))36 void ?{}(vector(T, allocator_t)* this);37 38 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))39 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);40 41 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))42 vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);43 44 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))45 void ^?{}(vector(T, allocator_t)* this);46 33 47 34 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) … … 53 40 54 41 //------------------------------------------------------------------------------ 42 //Initialization 43 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 44 void ctor(vector(T, allocator_t) *const this); 45 46 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 47 void dtor(vector(T, allocator_t) *const this); 48 49 //------------------------------------------------------------------------------ 55 50 //Capacity 56 51 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 57 static inline bool empty(vector(T, allocator_t) *this)52 static inline bool empty(vector(T, allocator_t) *const this) 58 53 { 59 54 return this->size == 0; … … 61 56 62 57 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 63 static inline size_t size(vector(T, allocator_t) *this)58 static inline size_t size(vector(T, allocator_t) *const this) 64 59 { 65 60 return this->size; … … 67 62 68 63 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 69 static inline void reserve(vector(T, allocator_t) *this, size_t size)64 static inline void reserve(vector(T, allocator_t) *const this, size_t size) 70 65 { 71 66 realloc_storage(&this->storage, this->size+1); … … 75 70 //Element access 76 71 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 77 static inline T at(vector(T, allocator_t) *this, size_t index)72 static inline T at(vector(T, allocator_t) *const this, size_t index) 78 73 { 79 74 return data(&this->storage)[index]; … … 81 76 82 77 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 83 static inline T ?[?](vector(T, allocator_t) *this, size_t index)78 static inline T ?[?](vector(T, allocator_t) *const this, size_t index) 84 79 { 85 80 return data(&this->storage)[index]; … … 87 82 88 83 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 89 static inline T front(vector(T, allocator_t) *this)84 static inline T front(vector(T, allocator_t) *const this) 90 85 { 91 86 return data(&this->storage)[0]; … … 93 88 94 89 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 95 static inline T back(vector(T, allocator_t) *this)90 static inline T back(vector(T, allocator_t) *const this) 96 91 { 97 92 return data(&this->storage)[this->size - 1]; … … 101 96 //Modifiers 102 97 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 103 void push_back(vector(T, allocator_t) *this, T value);98 void push_back(vector(T, allocator_t) *const this, T value); 104 99 105 100 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 106 void pop_back(vector(T, allocator_t) *this);101 void pop_back(vector(T, allocator_t) *const this); 107 102 108 103 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 109 void clear(vector(T, allocator_t) *this);104 void clear(vector(T, allocator_t) *const this); 110 105 111 106 //------------------------------------------------------------------------------ 112 107 //Iterators 113 108 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 114 static inline T* begin(vector(T, allocator_t) *this)109 static inline T* begin(vector(T, allocator_t) *const this) 115 110 { 116 111 return data(&this->storage); … … 118 113 119 114 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 120 static inline const T* cbegin(const vector(T, allocator_t) *this)115 static inline const T* cbegin(const vector(T, allocator_t) *const this) 121 116 { 122 117 return data(&this->storage); … … 124 119 125 120 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 126 static inline T* end(vector(T, allocator_t) *this)121 static inline T* end(vector(T, allocator_t) *const this) 127 122 { 128 123 return data(&this->storage) + this->size; … … 130 125 131 126 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 132 static inline const T* cend(const vector(T, allocator_t) *this)127 static inline const T* cend(const vector(T, allocator_t) *const this) 133 128 { 134 129 return data(&this->storage) + this->size; … … 145 140 146 141 forall(otype T) 147 void ?{}(heap_allocator(T)*this);142 void ctor(heap_allocator(T) *const this); 148 143 149 144 forall(otype T) 150 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);145 void dtor(heap_allocator(T) *const this); 151 146 152 147 forall(otype T) 153 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);148 void realloc_storage(heap_allocator(T) *const this, size_t size); 154 149 155 150 forall(otype T) 156 void ^?{}(heap_allocator(T)* this); 157 158 forall(otype T) 159 void realloc_storage(heap_allocator(T)* this, size_t size); 160 161 forall(otype T) 162 static inline T* data(heap_allocator(T)* this) 151 static inline T* data(heap_allocator(T) *const this) 163 152 { 164 153 return this->storage; -
src/libcfa/containers/vector.c
ra6fe3de r89e6ffc 18 18 #include <stdlib> 19 19 20 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))21 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other);22 23 20 //------------------------------------------------------------------------------ 24 21 //Initialization 25 22 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 26 void ?{}(vector(T, allocator_t)*this)23 void ctor(vector(T, allocator_t) *const this) 27 24 { 28 (&this->storage){};25 ctor(&this->storage); 29 26 this->size = 0; 30 27 } 31 28 32 29 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 34 { 35 (&this->storage){ rhs.storage }; 36 copy_internal(this, &rhs); 37 } 38 39 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 40 // vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 41 // { 42 // (&this->storage){}; 43 // copy_internal(this, &rhs); 44 // return *this; 45 // } 46 47 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 48 void ^?{}(vector(T, allocator_t)* this) 30 void dtor(vector(T, allocator_t) *const this) 49 31 { 50 32 clear(this); 51 ^(&this->storage){};33 dtor(&this->storage); 52 34 } 53 35 … … 55 37 //Modifiers 56 38 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 57 void push_back(vector(T, allocator_t) *this, T value)39 void push_back(vector(T, allocator_t) *const this, T value) 58 40 { 59 41 realloc_storage(&this->storage, this->size+1); … … 63 45 64 46 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 65 void pop_back(vector(T, allocator_t) *this)47 void pop_back(vector(T, allocator_t) *const this) 66 48 { 67 49 this->size--; 68 ^(&data(&this->storage)[this->size]){};50 DESTROY(data(&this->storage)[this->size]); 69 51 } 70 52 71 53 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 72 void clear(vector(T, allocator_t) *this)54 void clear(vector(T, allocator_t) *const this) 73 55 { 74 56 for(size_t i = 0; i < this->size; i++) 75 57 { 76 ^(&data(&this->storage)[this->size]){};58 DESTROY(data(&this->storage)[this->size]); 77 59 } 78 60 this->size = 0; … … 80 62 81 63 //------------------------------------------------------------------------------ 82 //Internal Helpers83 84 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))85 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other)86 {87 this->size = other->size;88 for(size_t i = 0; i < this->size; i++) {89 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };90 }91 }92 93 //------------------------------------------------------------------------------94 64 //Allocator 95 65 forall(otype T) 96 void ?{}(heap_allocator(T)*this)66 void ctor(heap_allocator(T) *const this) 97 67 { 98 68 this->storage = 0; … … 101 71 102 72 forall(otype T) 103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs) 104 { 105 this->capacity = rhs.capacity; 106 this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T)); 107 } 108 109 forall(otype T) 110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs) 111 { 112 this->capacity = rhs.capacity; 113 this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T)); 114 return *this; 115 } 116 117 forall(otype T) 118 void ^?{}(heap_allocator(T)* this) 73 void dtor(heap_allocator(T) *const this) 119 74 { 120 75 free(this->storage); … … 122 77 123 78 forall(otype T) 124 inline void realloc_storage(heap_allocator(T) *this, size_t size)79 inline void realloc_storage(heap_allocator(T) *const this, size_t size) 125 80 { 126 81 enum { GROWTH_RATE = 2 }; -
src/tests/libcfa_vector.c
ra6fe3de r89e6ffc 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 // 7 // libcfa_vector.c -- 8 // 6 // 7 // libcfa_vector.c -- 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Mon Jul 4 23:36:19 2016 … … 12 12 // Last Modified On : Tue Jul 5 15:08:05 2016 13 13 // Update Count : 26 14 // 14 // 15 15 16 16 #include <fstream> … … 28 28 int main() { 29 29 vector( int, heap_allocator(int) ) iv; 30 ctor( &iv ); 30 31 31 32 assert( empty( &iv ) );
Note:
See TracChangeset
for help on using the changeset viewer.