Changeset fd54fef for libcfa/src/containers
- 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
- Location:
- libcfa/src/containers
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/list.hfa
r2f47ea4 rfd54fef 66 66 #define __DLISTED_MGD_JUSTIMPL(STRUCT) 67 67 68 forall( dtype tE) {68 forall( tE & ) { 69 69 struct $mgd_link { 70 70 tE *elem; … … 83 83 (this.is_terminator){ 1 }; 84 84 } 85 forall ( otypetInit | { void ?{}( $mgd_link(tE) &, tInit); } )85 forall ( tInit | { void ?{}( $mgd_link(tE) &, tInit); } ) 86 86 static inline void ?=?( $mgd_link(tE) &this, tInit i ) { 87 87 ^?{}( this ); … … 115 115 __DLISTED_MGD_COMMON(STRUCT, STRUCT, $links) 116 116 117 trait $dlistable( dtype Tnode, dtype Telem) {117 trait $dlistable(Tnode &, Telem &) { 118 118 $mgd_link(Telem) & $prev_link(Tnode &); 119 119 $mgd_link(Telem) & $next_link(Tnode &); … … 125 125 }; 126 126 127 forall ( dtype Tnode, dtype Telem| $dlistable(Tnode, Telem)) {127 forall (Tnode &, Telem & | $dlistable(Tnode, Telem)) { 128 128 129 129 // implemented as a sentinel item in an underlying cicrular list -
libcfa/src/containers/maybe.cfa
r2f47ea4 rfd54fef 18 18 19 19 20 forall( otypeT)20 forall(T) 21 21 void ?{}(maybe(T) & this) { 22 22 this.has_value = false; 23 23 } 24 24 25 forall( otypeT)25 forall(T) 26 26 void ?{}(maybe(T) & this, T value) { 27 27 this.has_value = true; … … 29 29 } 30 30 31 forall( otypeT)31 forall(T) 32 32 void ?{}(maybe(T) & this, maybe(T) other) { 33 33 this.has_value = other.has_value; … … 37 37 } 38 38 39 forall( otypeT)39 forall(T) 40 40 maybe(T) ?=?(maybe(T) & this, maybe(T) that) { 41 41 if (this.has_value && that.has_value) { … … 51 51 } 52 52 53 forall( otypeT)53 forall(T) 54 54 void ^?{}(maybe(T) & this) { 55 55 if (this.has_value) { … … 58 58 } 59 59 60 forall( otypeT)60 forall(T) 61 61 bool ?!=?(maybe(T) this, zero_t) { 62 62 return this.has_value; 63 63 } 64 64 65 forall( otypeT)65 forall(T) 66 66 maybe(T) maybe_value(T value) { 67 67 return (maybe(T)){value}; 68 68 } 69 69 70 forall( otypeT)70 forall(T) 71 71 maybe(T) maybe_none() { 72 72 return (maybe(T)){}; 73 73 } 74 74 75 forall( otypeT)75 forall(T) 76 76 bool has_value(maybe(T) * this) { 77 77 return this->has_value; 78 78 } 79 79 80 forall( otypeT)80 forall(T) 81 81 T get(maybe(T) * this) { 82 82 assertf(this->has_value, "attempt to get from maybe without value"); … … 84 84 } 85 85 86 forall( otypeT)86 forall(T) 87 87 void set(maybe(T) * this, T value) { 88 88 if (this->has_value) { … … 94 94 } 95 95 96 forall( otypeT)96 forall(T) 97 97 void set_none(maybe(T) * this) { 98 98 if (this->has_value) { -
libcfa/src/containers/maybe.hfa
r2f47ea4 rfd54fef 19 19 20 20 // DO NOT USE DIRECTLY! 21 forall( otypeT)21 forall(T) 22 22 struct maybe { 23 23 bool has_value; … … 26 26 27 27 28 forall( otypeT)28 forall(T) 29 29 void ?{}(maybe(T) & this); 30 30 31 forall( otypeT)31 forall(T) 32 32 void ?{}(maybe(T) & this, T value); 33 33 34 forall( otypeT)34 forall(T) 35 35 void ?{}(maybe(T) & this, maybe(T) other); 36 36 37 forall( otypeT)37 forall(T) 38 38 void ^?{}(maybe(T) & this); 39 39 40 forall( otypeT)40 forall(T) 41 41 maybe(T) ?=?(maybe(T) & this, maybe(T) other); 42 42 43 forall( otypeT)43 forall(T) 44 44 bool ?!=?(maybe(T) this, zero_t); 45 45 46 46 /* Waiting for bug#11 to be fixed. 47 forall( otypeT)47 forall(T) 48 48 maybe(T) maybe_value(T value); 49 49 50 forall( otypeT)50 forall(T) 51 51 maybe(T) maybe_none(); 52 52 */ 53 53 54 forall( otypeT)54 forall(T) 55 55 bool has_value(maybe(T) * this); 56 56 57 forall( otypeT)57 forall(T) 58 58 T get(maybe(T) * this); 59 59 60 forall( otypeT)60 forall(T) 61 61 void set(maybe(T) * this, T value); 62 62 63 forall( otypeT)63 forall(T) 64 64 void set_none(maybe(T) * this); 65 65 -
libcfa/src/containers/pair.cfa
r2f47ea4 rfd54fef 13 13 #include <containers/pair.hfa> 14 14 15 forall( otype R, otypeS15 forall(R, S 16 16 | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); }) 17 17 int ?<?(pair(R, S) p, pair(R, S) q) { … … 19 19 } 20 20 21 forall( otype R, otypeS21 forall(R, S 22 22 | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); }) 23 23 int ?<=?(pair(R, S) p, pair(R, S) q) { … … 25 25 } 26 26 27 forall( otype R, otypeS | { int ?==?(R, R); int ?==?(S, S); })27 forall(R, S | { int ?==?(R, R); int ?==?(S, S); }) 28 28 int ?==?(pair(R, S) p, pair(R, S) q) { 29 29 return p.first == q.first && p.second == q.second; 30 30 } 31 31 32 forall( otype R, otypeS | { int ?!=?(R, R); int ?!=?(S, S); })32 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); }) 33 33 int ?!=?(pair(R, S) p, pair(R, S) q) { 34 34 return p.first != q.first || p.second != q.second; 35 35 } 36 36 37 forall( otype R, otypeS37 forall(R, S 38 38 | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); }) 39 39 int ?>?(pair(R, S) p, pair(R, S) q) { … … 41 41 } 42 42 43 forall( otype R, otypeS43 forall(R, S 44 44 | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); }) 45 45 int ?>=?(pair(R, S) p, pair(R, S) q) { -
libcfa/src/containers/pair.hfa
r2f47ea4 rfd54fef 16 16 #pragma once 17 17 18 forall( otype R, otypeS) struct pair {18 forall(R, S) struct pair { 19 19 R first; 20 20 S second; 21 21 }; 22 22 23 forall( otype R, otypeS23 forall(R, S 24 24 | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); }) 25 25 int ?<?(pair(R, S) p, pair(R, S) q); 26 26 27 forall( otype R, otypeS27 forall(R, S 28 28 | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); }) 29 29 int ?<=?(pair(R, S) p, pair(R, S) q); 30 30 31 forall( otype R, otypeS | { int ?==?(R, R); int ?==?(S, S); })31 forall(R, S | { int ?==?(R, R); int ?==?(S, S); }) 32 32 int ?==?(pair(R, S) p, pair(R, S) q); 33 33 34 forall( otype R, otypeS | { int ?!=?(R, R); int ?!=?(S, S); })34 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); }) 35 35 int ?!=?(pair(R, S) p, pair(R, S) q); 36 36 37 forall( otype R, otypeS37 forall(R, S 38 38 | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); }) 39 39 int ?>?(pair(R, S) p, pair(R, S) q); 40 40 41 forall( otype R, otypeS41 forall(R, S 42 42 | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); }) 43 43 int ?>=?(pair(R, S) p, pair(R, S) q); -
libcfa/src/containers/result.cfa
r2f47ea4 rfd54fef 18 18 19 19 20 forall( otype T, otypeE)20 forall(T, E) 21 21 void ?{}(result(T, E) & this) { 22 22 this.has_value = false; … … 24 24 } 25 25 26 forall( otype T, otypeE)26 forall(T, E) 27 27 void ?{}(result(T, E) & this, one_t, T value) { 28 28 this.has_value = true; … … 30 30 } 31 31 32 forall( otype T, otypeE)32 forall(T, E) 33 33 void ?{}(result(T, E) & this, zero_t, E error) { 34 34 this.has_value = false; … … 36 36 } 37 37 38 forall( otype T, otypeE)38 forall(T, E) 39 39 void ?{}(result(T, E) & this, result(T, E) other) { 40 40 this.has_value = other.has_value; … … 46 46 } 47 47 48 forall( otype T, otypeE)48 forall(T, E) 49 49 result(T, E) ?=?(result(T, E) & this, result(T, E) that) { 50 50 if (this.has_value && that.has_value) { … … 63 63 } 64 64 65 forall( otype T, otypeE)65 forall(T, E) 66 66 void ^?{}(result(T, E) & this) { 67 67 if (this.has_value) { … … 72 72 } 73 73 74 forall( otype T, otypeE)74 forall(T, E) 75 75 bool ?!=?(result(T, E) this, zero_t) { 76 76 return this.has_value; 77 77 } 78 78 79 forall( otype T, otypeE)79 forall(T, E) 80 80 result(T, E) result_value(T value) { 81 81 return (result(T, E)){1, value}; 82 82 } 83 83 84 forall( otype T, otypeE)84 forall(T, E) 85 85 result(T, E) result_error(E error) { 86 86 return (result(T, E)){0, error}; 87 87 } 88 88 89 forall( otype T, otypeE)89 forall(T, E) 90 90 bool has_value(result(T, E) * this) { 91 91 return this->has_value; 92 92 } 93 93 94 forall( otype T, otypeE)94 forall(T, E) 95 95 T get(result(T, E) * this) { 96 96 assertf(this->has_value, "attempt to get from result without value"); … … 98 98 } 99 99 100 forall( otype T, otypeE)100 forall(T, E) 101 101 E get_error(result(T, E) * this) { 102 102 assertf(!this->has_value, "attempt to get from result without error"); … … 104 104 } 105 105 106 forall( otype T, otypeE)106 forall(T, E) 107 107 void set(result(T, E) * this, T value) { 108 108 if (this->has_value) { … … 115 115 } 116 116 117 forall( otype T, otypeE)117 forall(T, E) 118 118 void set_error(result(T, E) * this, E error) { 119 119 if (this->has_value) { -
libcfa/src/containers/result.hfa
r2f47ea4 rfd54fef 19 19 20 20 // DO NOT USE DIRECTLY! 21 forall( otype T, otypeE)21 forall(T, E) 22 22 union inner_result{ 23 23 T value; … … 25 25 }; 26 26 27 forall( otype T, otypeE)27 forall(T, E) 28 28 struct result { 29 29 bool has_value; … … 32 32 33 33 34 forall( otype T, otypeE)34 forall(T, E) 35 35 void ?{}(result(T, E) & this); 36 36 37 forall( otype T, otypeE)37 forall(T, E) 38 38 void ?{}(result(T, E) & this, one_t, T value); 39 39 40 forall( otype T, otypeE)40 forall(T, E) 41 41 void ?{}(result(T, E) & this, zero_t, E error); 42 42 43 forall( otype T, otypeE)43 forall(T, E) 44 44 void ?{}(result(T, E) & this, result(T, E) other); 45 45 46 forall( otype T, otypeE)46 forall(T, E) 47 47 void ^?{}(result(T, E) & this); 48 48 49 forall( otype T, otypeE)49 forall(T, E) 50 50 result(T, E) ?=?(result(T, E) & this, result(T, E) other); 51 51 52 forall( otype T, otypeE)52 forall(T, E) 53 53 bool ?!=?(result(T, E) this, zero_t); 54 54 55 55 /* Wating for bug#11 to be fixed. 56 forall( otype T, otypeE)56 forall(T, E) 57 57 result(T, E) result_value(T value); 58 58 59 forall( otype T, otypeE)59 forall(T, E) 60 60 result(T, E) result_error(E error); 61 61 */ 62 62 63 forall( otype T, otypeE)63 forall(T, E) 64 64 bool has_value(result(T, E) * this); 65 65 66 forall( otype T, otypeE)66 forall(T, E) 67 67 T get(result(T, E) * this); 68 68 69 forall( otype T, otypeE)69 forall(T, E) 70 70 E get_error(result(T, E) * this); 71 71 72 forall( otype T, otypeE)72 forall(T, E) 73 73 void set(result(T, E) * this, T value); 74 74 75 forall( otype T, otypeE)75 forall(T, E) 76 76 void set_error(result(T, E) * this, E error); 77 77 -
libcfa/src/containers/stackLockFree.hfa
r2f47ea4 rfd54fef 17 17 #include <stdint.h> 18 18 19 forall( dtype T)19 forall( T & ) 20 20 union Link { 21 21 struct { // 32/64-bit x 2 … … 31 31 }; // Link 32 32 33 forall( otypeT | sized(T) | { Link(T) * ?`next( T * ); } ) {33 forall( T | sized(T) | { Link(T) * ?`next( T * ); } ) { 34 34 struct StackLF { 35 35 Link(T) stack; -
libcfa/src/containers/vector.cfa
r2f47ea4 rfd54fef 18 18 #include <stdlib.hfa> 19 19 20 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))20 forall(T, allocator_t | allocator_c(T, allocator_t)) 21 21 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other); 22 22 23 23 //------------------------------------------------------------------------------ 24 24 //Initialization 25 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))25 forall(T, allocator_t | allocator_c(T, allocator_t)) 26 26 void ?{}(vector(T, allocator_t)& this) 27 27 { … … 30 30 } 31 31 32 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))32 forall(T, allocator_t | allocator_c(T, allocator_t)) 33 33 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs) 34 34 { … … 37 37 } 38 38 39 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))39 // forall(T, allocator_t | allocator_c(T, allocator_t)) 40 40 // vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 41 41 // { … … 45 45 // } 46 46 47 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))47 forall(T, allocator_t | allocator_c(T, allocator_t)) 48 48 void ^?{}(vector(T, allocator_t)& this) 49 49 { … … 54 54 //------------------------------------------------------------------------------ 55 55 //Modifiers 56 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))56 forall(T, allocator_t | allocator_c(T, allocator_t)) 57 57 void push_back(vector(T, allocator_t)* this, T value) 58 58 { … … 62 62 } 63 63 64 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))64 forall(T, allocator_t | allocator_c(T, allocator_t)) 65 65 void pop_back(vector(T, allocator_t)* this) 66 66 { … … 69 69 } 70 70 71 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))71 forall(T, allocator_t | allocator_c(T, allocator_t)) 72 72 void clear(vector(T, allocator_t)* this) 73 73 { … … 82 82 //Internal Helpers 83 83 84 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))84 forall(T, allocator_t | allocator_c(T, allocator_t)) 85 85 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other) 86 86 { … … 93 93 //------------------------------------------------------------------------------ 94 94 //Allocator 95 forall( otypeT)95 forall(T) 96 96 void ?{}(heap_allocator(T)& this) 97 97 { … … 100 100 } 101 101 102 forall( otypeT)102 forall(T) 103 103 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs) 104 104 { … … 107 107 } 108 108 109 forall( otypeT)109 forall(T) 110 110 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs) 111 111 { … … 115 115 } 116 116 117 forall( otypeT)117 forall(T) 118 118 void ^?{}(heap_allocator(T)& this) 119 119 { … … 121 121 } 122 122 123 forall( otypeT)123 forall(T) 124 124 inline void realloc_storage(heap_allocator(T)* this, size_t size) 125 125 { -
libcfa/src/containers/vector.hfa
r2f47ea4 rfd54fef 20 20 //------------------------------------------------------------------------------ 21 21 //Allocator 22 forall( otypeT)22 forall(T) 23 23 struct heap_allocator 24 24 { … … 27 27 }; 28 28 29 forall( otypeT)29 forall(T) 30 30 void ?{}(heap_allocator(T)& this); 31 31 32 forall( otypeT)32 forall(T) 33 33 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs); 34 34 35 forall( otypeT)35 forall(T) 36 36 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs); 37 37 38 forall( otypeT)38 forall(T) 39 39 void ^?{}(heap_allocator(T)& this); 40 40 41 forall( otypeT)41 forall(T) 42 42 void realloc_storage(heap_allocator(T)* this, size_t size); 43 43 44 forall( otypeT)44 forall(T) 45 45 static inline T* data(heap_allocator(T)* this) 46 46 { … … 50 50 //------------------------------------------------------------------------------ 51 51 //Declaration 52 trait allocator_c( otype T, otypeallocator_t)52 trait allocator_c(T, allocator_t) 53 53 { 54 54 void realloc_storage(allocator_t*, size_t); … … 56 56 }; 57 57 58 forall( otype T, otypeallocator_t = heap_allocator(T) | allocator_c(T, allocator_t))58 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 59 59 struct vector; 60 60 61 61 //------------------------------------------------------------------------------ 62 62 //Initialization 63 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))63 forall(T, allocator_t | allocator_c(T, allocator_t)) 64 64 void ?{}(vector(T, allocator_t)& this); 65 65 66 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))66 forall(T, allocator_t | allocator_c(T, allocator_t)) 67 67 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 68 68 69 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))69 forall(T, allocator_t | allocator_c(T, allocator_t)) 70 70 vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 71 71 72 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))72 forall(T, allocator_t | allocator_c(T, allocator_t)) 73 73 void ^?{}(vector(T, allocator_t)& this); 74 74 75 forall( otype T, otypeallocator_t = heap_allocator(T) | allocator_c(T, allocator_t))75 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) 76 76 struct vector 77 77 { … … 82 82 //------------------------------------------------------------------------------ 83 83 //Capacity 84 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))84 forall(T, allocator_t | allocator_c(T, allocator_t)) 85 85 static inline bool empty(vector(T, allocator_t)* this) 86 86 { … … 88 88 } 89 89 90 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))90 forall(T, allocator_t | allocator_c(T, allocator_t)) 91 91 static inline size_t size(vector(T, allocator_t)* this) 92 92 { … … 94 94 } 95 95 96 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))96 forall(T, allocator_t | allocator_c(T, allocator_t)) 97 97 static inline void reserve(vector(T, allocator_t)* this, size_t size) 98 98 { … … 102 102 //------------------------------------------------------------------------------ 103 103 //Element access 104 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))104 forall(T, allocator_t | allocator_c(T, allocator_t)) 105 105 static inline T at(vector(T, allocator_t)* this, size_t index) 106 106 { … … 108 108 } 109 109 110 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))110 forall(T, allocator_t | allocator_c(T, allocator_t)) 111 111 static inline T ?[?](vector(T, allocator_t)* this, size_t index) 112 112 { … … 114 114 } 115 115 116 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))116 forall(T, allocator_t | allocator_c(T, allocator_t)) 117 117 static inline T front(vector(T, allocator_t)* this) 118 118 { … … 120 120 } 121 121 122 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))122 forall(T, allocator_t | allocator_c(T, allocator_t)) 123 123 static inline T back(vector(T, allocator_t)* this) 124 124 { … … 128 128 //------------------------------------------------------------------------------ 129 129 //Modifiers 130 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))130 forall(T, allocator_t | allocator_c(T, allocator_t)) 131 131 void push_back(vector(T, allocator_t)* this, T value); 132 132 133 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))133 forall(T, allocator_t | allocator_c(T, allocator_t)) 134 134 void pop_back(vector(T, allocator_t)* this); 135 135 136 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))136 forall(T, allocator_t | allocator_c(T, allocator_t)) 137 137 void clear(vector(T, allocator_t)* this); 138 138 139 139 //------------------------------------------------------------------------------ 140 140 //Iterators 141 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))141 forall(T, allocator_t | allocator_c(T, allocator_t)) 142 142 static inline T* begin(vector(T, allocator_t)* this) 143 143 { … … 145 145 } 146 146 147 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))147 // forall(T, allocator_t | allocator_c(T, allocator_t)) 148 148 // static inline const T* cbegin(const vector(T, allocator_t)* this) 149 149 // { … … 151 151 // } 152 152 153 forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))153 forall(T, allocator_t | allocator_c(T, allocator_t)) 154 154 static inline T* end(vector(T, allocator_t)* this) 155 155 { … … 157 157 } 158 158 159 // forall( otype T, otypeallocator_t | allocator_c(T, allocator_t))159 // forall(T, allocator_t | allocator_c(T, allocator_t)) 160 160 // static inline const T* cend(const vector(T, allocator_t)* this) 161 161 // {
Note: See TracChangeset
for help on using the changeset viewer.