Showing the changes to src/include/runtime.h (1 of 10 files). Show all
Unified · Split
| @@ -98,7 +98,14 @@ namespace disvm · 97 unmodified lines | |||
| 98 | 98 | ||
| 99 | static vm_alloc_t *allocate(std::shared_ptr<const type_descriptor_t> td); | 99 | static vm_alloc_t *allocate(std::shared_ptr<const type_descriptor_t> td); |
| 100 | static vm_alloc_t *copy(const vm_alloc_t &other); | 100 | static vm_alloc_t *copy(const vm_alloc_t &other); |
| 101 | static vm_alloc_t *from_allocation(pointer_t allocation); | 101 | |
| 102 | static vm_alloc_t *from_allocation(pointer_t allocation) | ||
| 103 | { | ||
| 104 | if (allocation == nullptr) | ||
| 105 | return nullptr; | ||
| 106 | |||
| 107 | return reinterpret_cast<vm_alloc_t *>(reinterpret_cast<uint8_t *>(allocation) - sizeof(vm_alloc_t)); | ||
| 108 | } | ||
| 102 | 109 | ||
| 103 | template <typename T> | 110 | template <typename T> |
| 104 | static T *from_allocation(pointer_t allocation) | 111 | static T *from_allocation(pointer_t allocation) |
| @@ -125,7 +132,12 @@ namespace disvm · 20 unmodified lines | |||
| 125 | pointer_t gc_reserved; | 132 | pointer_t gc_reserved; |
| 126 | 133 | ||
| 127 | public: | 134 | public: |
| 128 | pointer_t get_allocation() const; | 135 | pointer_t get_allocation() const |
| 136 | { | ||
| 137 | // Remove const on the this pointer so the offset can be computed. | ||
| 138 | auto non_const_this = const_cast<vm_alloc_t *>(this); | ||
| 139 | return reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(non_const_this) + sizeof(vm_alloc_t)); | ||
| 140 | } | ||
| 129 | 141 | ||
| 130 | template <typename T> | 142 | template <typename T> |
| 131 | T *get_allocation() const | 143 | T *get_allocation() const |
| @@ -638,7 +650,7 @@ namespace disvm · 506 unmodified lines | |||
| 638 | class vm_frame_t final | 650 | class vm_frame_t final |
| 639 | { | 651 | { |
| 640 | public: | 652 | public: |
| 641 | vm_frame_t(std::shared_ptr<const type_descriptor_t> &frame_type); | 653 | vm_frame_t(std::shared_ptr<const type_descriptor_t> frame_type); |
| 642 | ~vm_frame_t(); | 654 | ~vm_frame_t(); |
| 643 | 655 | ||
| 644 | std::shared_ptr<const type_descriptor_t> frame_type; | 656 | std::shared_ptr<const type_descriptor_t> frame_type; |