[15db1ab] | 1 | #include "gcpointers.h" |
---|
| 2 | |
---|
[bee4283] | 3 | // #include "gc.h" |
---|
[e47f529] | 4 | #include "internal/collector.h" |
---|
[c5833e8] | 5 | #include "internal/object_header.h" |
---|
[29ad0ac] | 6 | #include "internal/state.h" |
---|
[15db1ab] | 7 | |
---|
[385c130] | 8 | void register_ptr(gcpointer_t* this) |
---|
| 9 | { |
---|
| 10 | if(gcpointer_null(this)) return; |
---|
| 11 | |
---|
| 12 | if(gc_is_managed(this)) |
---|
| 13 | { |
---|
| 14 | gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this); |
---|
| 15 | check(obj); |
---|
| 16 | check(gc_obj_is_valide(obj)); |
---|
| 17 | check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL); |
---|
| 18 | this->next = obj->type_chain; |
---|
| 19 | obj->type_chain = this; |
---|
| 20 | check(obj->is_valide()); |
---|
| 21 | } |
---|
| 22 | else |
---|
| 23 | { |
---|
| 24 | gc_object_header* obj = gc_get_object_ptr((void*)this->ptr); |
---|
| 25 | check(obj); |
---|
| 26 | check(gc_obj_is_valide(obj)); |
---|
| 27 | check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL); |
---|
| 28 | this->next = obj->root_chain; |
---|
| 29 | obj->root_chain = this; |
---|
| 30 | check(gc_obj_is_valide(obj)); |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void unregister_ptr(gcpointer_t* this) |
---|
| 35 | { |
---|
| 36 | if(gcpointer_null(this)) return; |
---|
| 37 | |
---|
| 38 | gcpointer_t** prev_next_ptr = gc_find_previous_ref(this); |
---|
| 39 | check((*prev_next_ptr) == this); |
---|
| 40 | |
---|
| 41 | (*prev_next_ptr) = this->next; |
---|
| 42 | } |
---|
| 43 | |
---|
[6643e72] | 44 | void ?{}(gcpointer_t* this) |
---|
[385c130] | 45 | { |
---|
| 46 | this->ptr = (intptr_t)NULL; |
---|
| 47 | this->next = NULL; |
---|
| 48 | } |
---|
| 49 | |
---|
[6643e72] | 50 | void ?{}(gcpointer_t* this, void* address) |
---|
[385c130] | 51 | { |
---|
| 52 | this->ptr = (intptr_t)address; |
---|
| 53 | this->next = NULL; |
---|
| 54 | |
---|
| 55 | register_ptr(this); |
---|
| 56 | } |
---|
| 57 | |
---|
[6643e72] | 58 | void ?{}(gcpointer_t* this, gcpointer_t other) |
---|
[385c130] | 59 | { |
---|
[6643e72] | 60 | this->ptr = other.ptr; |
---|
[385c130] | 61 | this->next = NULL; |
---|
| 62 | |
---|
| 63 | register_ptr(this); |
---|
| 64 | } |
---|
| 65 | |
---|
[6643e72] | 66 | void ^?{}(gcpointer_t* this) |
---|
[385c130] | 67 | { |
---|
| 68 | unregister_ptr(this); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs) |
---|
| 72 | { |
---|
| 73 | if(this != rhs) |
---|
| 74 | { |
---|
| 75 | unregister_ptr(this); |
---|
| 76 | |
---|
| 77 | this->ptr = rhs->ptr; |
---|
| 78 | |
---|
| 79 | register_ptr(this); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return this; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //Logical operators |
---|
[f1e42c1] | 86 | bool gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs) |
---|
[385c130] | 87 | { |
---|
| 88 | return this->ptr == rhs->ptr; |
---|
| 89 | } |
---|
| 90 | |
---|
[f1e42c1] | 91 | bool gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs) |
---|
[385c130] | 92 | { |
---|
| 93 | return this->ptr != rhs->ptr; |
---|
| 94 | } |
---|
| 95 | |
---|
[f1e42c1] | 96 | bool gcpointer_null(gcpointer_t* this) |
---|
[385c130] | 97 | { |
---|
| 98 | return this->ptr == (intptr_t)NULL; |
---|
| 99 | } |
---|
[6643e72] | 100 | |
---|
| 101 | forall(otype T) void ?{}(gcpointer(T)* this) { |
---|
| 102 | (&this->internal) {}; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | forall(otype T) void ?{}(gcpointer(T)* this, void* address) { |
---|
| 106 | (&this->internal) { address }; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T)* other) { |
---|
| 110 | (&this->internal) { other->internal }; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | forall(otype T) void ^?{}(gcpointer(T)* this) { |
---|
| 114 | ^?{}(&this->internal); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | // forall(otype T) gcpointer(T) ?=?(gcpointer(T) this, gcpointer(T) rhs); |
---|
| 118 | // |
---|
| 119 | // forall(otype T) T *?(gcpointer(T) this); |
---|
| 120 | |
---|
| 121 | forall(otype T) T* get(gcpointer(T)* this) { |
---|
| 122 | return (T*)this->internal.ptr; |
---|
| 123 | } |
---|
| 124 | // |
---|
| 125 | // //Logical operators |
---|
| 126 | // forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs); |
---|
| 127 | // forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs); |
---|