Changeset fd54fef for libcfa/src/memory.cfa
- Timestamp:
- Jan 19, 2021, 8:44:29 PM (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:
- dafbde8
- Parents:
- 2f47ea4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/memory.cfa
r2f47ea4 rfd54fef 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) | { void ^?{}(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 … … 64 64 } 65 65 66 forall( dtype T | sized(T), ttype Args| { void ?{}(T&, Args); })66 forall(T & | sized(T), Args... | { void ?{}(T&, Args); }) 67 67 void ?{}(counter_ptr(T) & this, Args args) { 68 68 this.data = (counter_data(T)*)new(args); 69 69 } 70 70 71 forall( dtype T| sized(T) | { void ^?{}(T &); })71 forall(T & | sized(T) | { void ^?{}(T &); }) 72 72 void ^?{}(counter_ptr(T) & this) { 73 73 internal_decrement(this); 74 74 } 75 75 76 forall( dtype T| sized(T))76 forall(T & | sized(T)) 77 77 T & *?(counter_ptr(T) & this) { 78 78 return *((this.data) ? &this.data->object : 0p); 79 79 } 80 80 81 forall( dtype T| sized(T) | { void ^?{}(T &); })81 forall(T & | sized(T) | { void ^?{}(T &); }) 82 82 void ?=?(counter_ptr(T) & this, counter_ptr(T) that) { 83 83 if (this.data != that.data) { … … 87 87 } 88 88 89 forall( dtype T| sized(T) | { void ^?{}(T &); })89 forall(T & | sized(T) | { void ^?{}(T &); }) 90 90 void ?=?(counter_ptr(T) & this, zero_t) { 91 91 internal_decrement(this); … … 93 93 } 94 94 95 forall( dtype T| sized(T))95 forall(T & | sized(T)) 96 96 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 97 97 return this.data == that.data; 98 98 } 99 99 100 forall( dtype T| sized(T))100 forall(T & | sized(T)) 101 101 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) { 102 102 return !?==?(this, that); 103 103 } 104 104 105 forall( dtype T| sized(T))105 forall(T & | sized(T)) 106 106 int ?==?(counter_ptr(T) const & this, zero_t) { 107 107 return this.data == 0; 108 108 } 109 109 110 forall( dtype T| sized(T))110 forall(T & | sized(T)) 111 111 int ?!=?(counter_ptr(T) const & this, zero_t) { 112 112 return !?==?(this, (zero_t)0); … … 114 114 115 115 // This is the only pointer that keeps this alive. 116 forall( dtype T)116 forall(T &) 117 117 void ?{}(unique_ptr(T) & this) { 118 118 this.data = 0p; 119 119 } 120 120 121 forall( dtype T)121 forall(T &) 122 122 void ?{}(unique_ptr(T) & this, zero_t) { 123 123 this.data = 0p; 124 124 } 125 125 126 forall( dtype T | sized(T), ttype Args| { void ?{}(T &, Args); })126 forall(T & | sized(T), Args... | { void ?{}(T &, Args); }) 127 127 void ?{}(unique_ptr(T) & this, Args args) { 128 128 this.data = (T *)new(args); 129 129 } 130 130 131 forall( dtype T| { void ^?{}(T &); })131 forall(T & | { void ^?{}(T &); }) 132 132 void ^?{}(unique_ptr(T) & this) { 133 133 delete(this.data); 134 134 } 135 135 136 forall( dtype T)136 forall(T &) 137 137 T & *?(unique_ptr(T) & this) { 138 138 return *this.data; 139 139 } 140 140 141 forall( dtype T| { void ^?{}(T &); })141 forall(T & | { void ^?{}(T &); }) 142 142 void ?=?(unique_ptr(T) & this, zero_t) { 143 143 delete(this.data); … … 145 145 } 146 146 147 forall( dtype T| { void ^?{}(T &); })147 forall(T & | { void ^?{}(T &); }) 148 148 void move(unique_ptr(T) & this, unique_ptr(T) & that) { 149 149 delete(this.data); … … 152 152 } 153 153 154 forall( dtype T)154 forall(T &) 155 155 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 156 156 return this.data == that.data; 157 157 } 158 158 159 forall( dtype T)159 forall(T &) 160 160 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 161 161 return !?==?(this, that); 162 162 } 163 163 164 forall( dtype T)164 forall(T &) 165 165 int ?==?(unique_ptr(T) const & this, zero_t) { 166 166 return this.data == 0; 167 167 } 168 168 169 forall( dtype T)169 forall(T &) 170 170 int ?!=?(unique_ptr(T) const & this, zero_t) { 171 171 return !?==?(this, (zero_t)0);
Note: See TracChangeset
for help on using the changeset viewer.