Changeset 8be729f
 Timestamp:
 Feb 1, 2021, 4:23:55 PM (3 years ago)
 Branches:
 ADT, armeh, astexperimental, enum, forallpointerdecay, jacob/cs343translation, master, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 85871478
 Parents:
 f99f5ba
 Files:

 1 added
 3 edited
Legend:
 Unmodified
 Added
 Removed

libcfa/src/memory.cfa
rf99f5ba r8be729f 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 … … 56 56 } 57 57 58 forall(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);62 //internal_decrement(this); 63 63 internal_copy(this, that); 64 64 } … … 66 66 forall(T &  sized(T), Args...  { void ?{}(T&, Args); }) 67 67 void ?{}(counter_ptr(T) & this, Args args) { 68 this.data = (counter_data(T)*)new(args); 68 this.data = malloc(); 69 this.data>counter = 1; 70 (this.data>object){args}; 69 71 } 70 72 … … 126 128 forall(T &  sized(T), Args...  { void ?{}(T &, Args); }) 127 129 void ?{}(unique_ptr(T) & this, Args args) { 128 this.data = (T *)new(args); 130 this.data = malloc(); 131 (*this.data){args}; 129 132 } 130 133 
libcfa/src/memory.hfa
rf99f5ba r8be729f 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:29:00 202013 // Update Count : 012 // Last Modified On : Fri Jan 29 15:52:00 2021 13 // Update Count : 1 14 14 // 15 15 … … 17 17 18 18 // Internal data object. 19 forall(T &  sized(T)) {20 21 22 23 19 forall(T &  sized(T)) 20 struct counter_data { 21 unsigned int counter; 22 T object; 23 }; 24 24 25 forall(Args...  { void ?{}(T &, Args); })26 25 forall(T &  sized(T), Args...  { void ?{}(T &, Args); }) 26 void ?{}(counter_data(T) & this, Args args); 27 27 28 forall(  { void ^?{}(T &); }) 29 void ^?{}(counter_data(T) & this); 30 } 28 forall(T &  sized(T)  { void ^?{}(T &); }) 29 void ^?{}(counter_data(T) & this); 31 30 32 31 // This is one of many pointers keeping this alive. 33 forall(T &  sized(T)) {34 35 36 32 forall(T &  sized(T)) 33 struct counter_ptr { 34 counter_data(T) * data; 35 }; 37 36 38 void ?{}(counter_ptr(T) & this); 39 void ?{}(counter_ptr(T) & this, zero_t); 40 forall(  { void ^?{}(T &); }) 41 void ?{}(counter_ptr(T) & this, counter_ptr(T) that); 42 forall(Args...  { void ?{}(T&, Args); }) 43 void ?{}(counter_ptr(T) & this, Args args); 37 forall(T &  sized(T)) 38 void ?{}(counter_ptr(T) & this); 39 forall(T &  sized(T)) 40 void ?{}(counter_ptr(T) & this, zero_t); 41 forall(T &  sized(T)) 42 void ?{}(counter_ptr(T) & this, counter_ptr(T) that); 43 forall(T &  sized(T), Args...  { void ?{}(T&, Args); }) 44 void ?{}(counter_ptr(T) & this, Args args); 44 45 45 forall( { void ^?{}(T &); })46 46 forall(T &  sized(T)  { void ^?{}(T &); }) 47 void ^?{}(counter_ptr(T) & this); 47 48 48 T & *?(counter_ptr(T) & this); 49 forall(T &  sized(T)) 50 T & *?(counter_ptr(T) & this); 49 51 50 forall( { void ^?{}(T &); })51 52 forall( { void ^?{}(T &); })53 52 forall(T &  sized(T)  { void ^?{}(T &); }) 53 void ?=?(counter_ptr(T) & this, counter_ptr(T) that); 54 forall(T &  sized(T)  { void ^?{}(T &); }) 55 void ?=?(counter_ptr(T) & this, zero_t); 54 56 55 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that); 56 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that); 57 int ?==?(counter_ptr(T) const & this, zero_t); 58 int ?!=?(counter_ptr(T) const & this, zero_t); 59 } 57 forall(T &  sized(T)) 58 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that); 59 forall(T &  sized(T)) 60 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that); 61 forall(T &  sized(T)) 62 int ?==?(counter_ptr(T) const & this, zero_t); 63 forall(T &  sized(T)) 64 int ?!=?(counter_ptr(T) const & this, zero_t); 60 65 61 66 // This is the only pointer that keeps this alive. 62 forall(T &) {63 64 65 67 forall(T &) 68 struct unique_ptr { 69 T * data; 70 }; 66 71 67 void ?{}(unique_ptr(T) & this); 68 void ?{}(unique_ptr(T) & this, zero_t); 69 void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void; 70 forall(  sized(T), Args...  { void ?{}(T &, Args); }) 71 void ?{}(unique_ptr(T) & this, Args args); 72 forall(T &) 73 void ?{}(unique_ptr(T) & this); 74 forall(T &) 75 void ?{}(unique_ptr(T) & this, zero_t); 76 forall(T &) 77 void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void; 78 forall(T &  sized(T), Args...  { void ?{}(T &, Args); }) 79 void ?{}(unique_ptr(T) & this, Args args); 72 80 73 forall( { void ^?{}(T &); })74 81 forall(T &  { void ^?{}(T &); }) 82 void ^?{}(unique_ptr(T) & this); 75 83 76 T & *?(unique_ptr(T) & this); 84 forall(T & ) 85 T & *?(unique_ptr(T) & this); 77 86 78 void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void; 79 forall(  { void ^?{}(T &); }) 80 void ?=?(unique_ptr(T) & this, zero_t); 87 forall(T &) 88 void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void; 89 forall(T &  { void ^?{}(T &); }) 90 void ?=?(unique_ptr(T) & this, zero_t); 81 91 82 forall( { void ^?{}(T &); })83 92 forall(T &  { void ^?{}(T &); }) 93 void move(unique_ptr(T) & this, unique_ptr(T) & that); 84 94 85 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that); 86 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that); 87 int ?==?(unique_ptr(T) const & this, zero_t); 88 int ?!=?(unique_ptr(T) const & this, zero_t); 89 } 95 forall(T &) 96 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that); 97 forall(T &) 98 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that); 99 forall(T &) 100 int ?==?(unique_ptr(T) const & this, zero_t); 101 forall(T &) 102 int ?!=?(unique_ptr(T) const & this, zero_t); 
tests/smartpointers.cfa
rf99f5ba r8be729f 2 2 3 3 #include <memory.hfa> 4 #include < stdlib.hfa>4 #include <assert.h> 5 5 6 6 void counter_test(void) { … … 53 53 } 54 54 55 void declare_test(void) { 56 counter_ptr(int) ptr_i0 = 3; 57 counter_ptr(char) ptr_c0 = 'a'; 58 counter_ptr(float) ptr_f0 = 3.5f; 59 counter_ptr(double) ptr_d0 = 3.5; 60 61 unique_ptr(int) ptr_i1 = 3; 62 unique_ptr(char) ptr_c1 = 'a'; 63 unique_ptr(float) ptr_f1 = 3.5f; 64 unique_ptr(double) ptr_d1 = 3.5; 65 } 66 55 67 int main(int argc, char * argv[]) { 56 68 counter_test(); 57 69 unique_test(); 58 70 pointer_equality(); 71 72 printf("done\n"); 59 73 }
Note: See TracChangeset
for help on using the changeset viewer.