Changeset 8e4aa05 for libcfa/src/memory.cfa
- Timestamp:
- Mar 4, 2021, 7:40:25 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 77d601f
- Parents:
- 342af53 (diff), a5040fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/memory.cfa
r342af53 r8e4aa05 10 10 // Created On : Tue Jun 2 16:48:00 2020 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 3 12:30:00 202013 // Update Count : 012 // Last Modified On : Mon Feb 1 16:10:00 2021 13 // Update Count : 1 14 14 // 15 15 … … 18 18 19 19 // Internal data object. 20 forall( dtype T | sized(T), ttype Args| { void ?{}(T &, Args); })20 forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) 21 21 void ?{}(counter_data(T) & this, Args args) { 22 22 (this.counter){1}; … … 24 24 } 25 25 26 forall( dtype T| sized(T) | { void ^?{}(T &); })26 forall(T & | sized(T) | { void ^?{}(T &); }) 27 27 void ^?{}(counter_data(T) & this) { 28 28 assert(0 == this.counter); … … 31 31 32 32 // This is one of many pointers keeping this alive. 33 forall( dtype T| sized(T))33 forall(T & | sized(T)) 34 34 void ?{}(counter_ptr(T) & this) { 35 35 this.data = 0p; 36 36 } 37 37 38 forall( dtype T| sized(T))38 forall(T & | sized(T)) 39 39 void ?{}(counter_ptr(T) & this, zero_t) { 40 40 this.data = 0p; 41 41 } 42 42 43 forall( dtype T| sized(T) | { void ^?{}(T &); })43 forall(T & | sized(T) | { void ^?{}(T &); }) 44 44 static void internal_decrement(counter_ptr(T) & this) { 45 45 if (this.data && 0 == --this.data->counter) { … … 48 48 } 49 49 50 forall( dtype T| sized(T))50 forall(T & | sized(T)) 51 51 static void internal_copy(counter_ptr(T) & this, counter_ptr(T) & that) { 52 52 this.data = that.data; … … 56 56 } 57 57 58 forall( dtype T | sized(T) | { void ^?{}(T &); })58 forall(T & | sized(T)) 59 59 void ?{}(counter_ptr(T) & this, counter_ptr(T) that) { 60 60 // `that` is a copy but it should have neither a constructor 61 61 // nor destructor run on it so it shouldn't need adjustment. 62 internal_decrement(this);63 62 internal_copy(this, that); 64 63 } 65 64 66 forall( dtype T | sized(T), ttype Args| { void ?{}(T&, Args); })65 forall(T & | sized(T), Args... | { void ?{}(T&, Args); }) 67 66 void ?{}(counter_ptr(T) & this, Args args) { 68 this.data = (counter_data(T)*)new(args); 67 this.data = malloc(); 68 this.data->counter = 1; 69 (this.data->object){args}; 69 70 } 70 71 71 forall( dtype T| sized(T) | { void ^?{}(T &); })72 forall(T & | sized(T) | { void ^?{}(T &); }) 72 73 void ^?{}(counter_ptr(T) & this) { 73 74 internal_decrement(this); 74 75 } 75 76 76 forall( dtype T| sized(T))77 forall(T & | sized(T)) 77 78 T & *?(counter_ptr(T) & this) { 78 79 return *((this.data) ? &this.data->object : 0p); 79 80 } 80 81 81 forall( dtype T| sized(T) | { void ^?{}(T &); })82 forall(T & | sized(T) | { void ^?{}(T &); }) 82 83 void ?=?(counter_ptr(T) & this, counter_ptr(T) that) { 83 84 if (this.data != that.data) { … … 87 88 } 88 89 89 forall( dtype T| sized(T) | { void ^?{}(T &); })90 forall(T & | sized(T) | { void ^?{}(T &); }) 90 91 void ?=?(counter_ptr(T) & this, zero_t) { 91 92 internal_decrement(this); … … 93 94 } 94 95 95 forall( dtype T| sized(T))96 forall(T & | sized(T)) 96 97 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 97 98 return this.data == that.data; 98 99 } 99 100 100 forall( dtype T| sized(T))101 forall(T & | sized(T)) 101 102 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 102 103 return !?==?(this, that); 103 104 } 104 105 105 forall( dtype T| sized(T))106 forall(T & | sized(T)) 106 107 int ?==?(counter_ptr(T) const & this, zero_t) { 107 108 return this.data == 0; 108 109 } 109 110 110 forall( dtype T| sized(T))111 forall(T & | sized(T)) 111 112 int ?!=?(counter_ptr(T) const & this, zero_t) { 112 113 return !?==?(this, (zero_t)0); … … 114 115 115 116 // This is the only pointer that keeps this alive. 116 forall( dtype T)117 forall(T &) 117 118 void ?{}(unique_ptr(T) & this) { 118 119 this.data = 0p; 119 120 } 120 121 121 forall( dtype T)122 forall(T &) 122 123 void ?{}(unique_ptr(T) & this, zero_t) { 123 124 this.data = 0p; 124 125 } 125 126 126 forall( dtype T | sized(T), ttype Args| { void ?{}(T &, Args); })127 forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) 127 128 void ?{}(unique_ptr(T) & this, Args args) { 128 this.data = (T *)new(args); 129 this.data = malloc(); 130 (*this.data){args}; 129 131 } 130 132 131 forall( dtype T| { void ^?{}(T &); })133 forall(T & | { void ^?{}(T &); }) 132 134 void ^?{}(unique_ptr(T) & this) { 133 135 delete(this.data); 134 136 } 135 137 136 forall( dtype T)138 forall(T &) 137 139 T & *?(unique_ptr(T) & this) { 138 140 return *this.data; 139 141 } 140 142 141 forall( dtype T| { void ^?{}(T &); })143 forall(T & | { void ^?{}(T &); }) 142 144 void ?=?(unique_ptr(T) & this, zero_t) { 143 145 delete(this.data); … … 145 147 } 146 148 147 forall( dtype T| { void ^?{}(T &); })149 forall(T & | { void ^?{}(T &); }) 148 150 void move(unique_ptr(T) & this, unique_ptr(T) & that) { 149 151 delete(this.data); … … 152 154 } 153 155 154 forall( dtype T)156 forall(T &) 155 157 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 156 158 return this.data == that.data; 157 159 } 158 160 159 forall( dtype T)161 forall(T &) 160 162 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 161 163 return !?==?(this, that); 162 164 } 163 165 164 forall( dtype T)166 forall(T &) 165 167 int ?==?(unique_ptr(T) const & this, zero_t) { 166 168 return this.data == 0; 167 169 } 168 170 169 forall( dtype T)171 forall(T &) 170 172 int ?!=?(unique_ptr(T) const & this, zero_t) { 171 173 return !?==?(this, (zero_t)0);
Note:
See TracChangeset
for help on using the changeset viewer.