Unified · Split
| @@ -107,7 +107,7 @@ namespace disvm · 106 unmodified lines | ||
| 107 | 107 | { |
| 108 | 108 | auto alloc_inst = vm_alloc_t::from_allocation(allocation); |
| 109 | 109 | assert(alloc_inst == nullptr || alloc_inst->alloc_type == intrinsic_type_desc::type<T>()); |
| 110 | − return dynamic_cast<T *>(alloc_inst); | |
| 110 | + return static_cast<T *>(alloc_inst); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | protected: |
| @@ -199,9 +199,9 @@ namespace disvm · 85 unmodified lines | ||
| 199 | 199 | static std::shared_ptr<const type_descriptor_t> type_desc(); |
| 200 | 200 | |
| 201 | 201 | public: |
| 202 | − vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count); | |
| 203 | − vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&); | |
| 204 | − vm_array_t(vm_array_t *original, word_t begin_index, word_t count); | |
| 202 | + vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length); | |
| 203 | + vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&); | |
| 204 | + vm_array_t(vm_array_t *original, word_t begin_index, word_t length); | |
| 205 | 205 | vm_array_t(const vm_string_t *s); |
| 206 | 206 | ~vm_array_t(); |
| 207 | 207 | |
| @@ -17,11 +17,11 @@ std::shared_ptr<const type_descriptor_t> vm_array_t::type_desc() · 16 unmodified lines | ||
| 17 | 17 | return intrinsic_type_desc::type<vm_array_t>(); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | −vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count) | |
| 20 | +vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length) | |
| 21 | 21 | : vm_alloc_t(vm_array_t::type_desc()) |
| 22 | 22 | , _arr{ nullptr } |
| 23 | 23 | , _element_type{ td } |
| 24 | − , _length{ count } | |
| 24 | + , _length{ length } | |
| 25 | 25 | , _original{ nullptr } |
| 26 | 26 | { |
| 27 | 27 | assert(_element_type != nullptr); |
| @@ -43,11 +43,11 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 15 unmodified lines | ||
| 43 | 43 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d\n", array_len); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | −vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&) | |
| 46 | +vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&) | |
| 47 | 47 | : vm_alloc_t(vm_array_t::type_desc()) |
| 48 | 48 | , _arr{ nullptr } |
| 49 | 49 | , _element_type{ td } |
| 50 | − , _length{ count } | |
| 50 | + , _length{ length } | |
| 51 | 51 | , _original{ nullptr } |
| 52 | 52 | { |
| 53 | 53 | assert(_element_type != nullptr); |
| @@ -56,16 +56,16 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 2 unmodified lines | ||
| 56 | 56 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm array: %d\n", _length); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | −vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t count) | |
| 59 | +vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length) | |
| 60 | 60 | : vm_alloc_t(vm_array_t::type_desc()) |
| 61 | 61 | , _arr{ nullptr } |
| 62 | 62 | , _element_type{ original->get_element_type() } |
| 63 | − , _length{ count } | |
| 63 | + , _length{ length } | |
| 64 | 64 | , _original{ original } |
| 65 | 65 | { |
| 66 | 66 | assert(_original != nullptr); |
| 67 | 67 | assert(0 <= begin_index && begin_index < _original->get_length()); |
| 68 | − assert(_length >= 0 && (count - begin_index) < _original->get_length()); | |
| 68 | + assert(_length >= 0 && (_length + begin_index) <= _original->get_length()); | |
| 69 | 69 | |
| 70 | 70 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 71 | 71 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d\n", begin_index, _length); |
| @@ -66,8 +66,22 @@ namespace · 65 unmodified lines | ||
| 66 | 66 | EXEC_DECL(shlw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) << vt_ref<word_t>(r.src); } |
| 67 | 67 | EXEC_DECL(shll) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) << vt_ref<big_t>(r.src); } |
| 68 | 68 | EXEC_DECL(shrb) { vt_ref<byte_t>(r.dest) = vt_ref<byte_t>(r.mid) >> vt_ref<byte_t>(r.src); } |
| 69 | − EXEC_DECL(shrw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src); } | |
| 70 | − EXEC_DECL(shrl) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src); } | |
| 69 | + EXEC_DECL(shrw) | |
| 70 | + { | |
| 71 | + vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src); | |
| 72 | + // Right shifting a negative number is implementation dependent in C++. | |
| 73 | + // Assert the current compiler defaults to arithmetic shifting, not logical. | |
| 74 | + assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0)); | |
| 75 | + } | |
| 76 | + | |
| 77 | + EXEC_DECL(shrl) | |
| 78 | + { | |
| 79 | + vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src); | |
| 80 | + // Right shifting a negative number is implementation dependent in C++. | |
| 81 | + // Assert the current compiler defaults to arithmetic shifting, not logical. | |
| 82 | + assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0)); | |
| 83 | + } | |
| 84 | + | |
| 71 | 85 | EXEC_DECL(lsrw) { vt_ref<word_t>(r.dest) = vt_ref<uword_t>(r.mid) >> vt_ref<word_t>(r.src); } |
| 72 | 86 | EXEC_DECL(lsrl) { vt_ref<big_t>(r.dest) = vt_ref<ubig_t>(r.mid) >> vt_ref<big_t>(r.src); } |
| 73 | 87 | |
| @@ -75,14 +89,14 @@ namespace · 1 unmodified line | ||
| 75 | 89 | // Conversion operations |
| 76 | 90 | // |
| 77 | 91 | |
| 78 | − EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<byte_t>(r.src); } | |
| 79 | − EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<word_t>(r.src); } | |
| 80 | − EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<word_t>(r.src); } | |
| 81 | − EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<big_t>(r.src); } | |
| 92 | + EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = vt_ref<byte_t>(r.src); } | |
| 93 | + EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = vt_ref<word_t>(r.src); } | |
| 94 | + EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = vt_ref<word_t>(r.src); } | |
| 95 | + EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = static_cast<word_t>(vt_ref<big_t>(r.src)); } | |
| 82 | 96 | EXEC_DECL(cvtrf) { vt_ref<short_real_t>(r.dest) = static_cast<short_real_t>(vt_ref<real_t>(r.src)); } |
| 83 | 97 | EXEC_DECL(cvtfr) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<short_real_t>(r.src)); } |
| 84 | − EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<word_t>(r.src); } | |
| 85 | − EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<short_word_t>(r.src); } | |
| 98 | + EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = vt_ref<word_t>(r.src); } | |
| 99 | + EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = vt_ref<short_word_t>(r.src); } | |
| 86 | 100 | EXEC_DECL(cvtlf) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<big_t>(r.src)); } |
| 87 | 101 | EXEC_DECL(cvtfl) |
| 88 | 102 | { |
| @@ -1626,7 +1640,7 @@ namespace · 1537 unmodified lines | ||
| 1626 | 1640 | if (e->alloc_type == vm_string_t::type_desc()) |
| 1627 | 1641 | { |
| 1628 | 1642 | // String |
| 1629 | − exception_id = dynamic_cast<vm_string_t *>(e); | |
| 1643 | + exception_id = static_cast<vm_string_t *>(e); | |
| 1630 | 1644 | |
| 1631 | 1645 | if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>()) |
| 1632 | 1646 | debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<\n", exception_id->str()); |
| @@ -481,7 +481,7 @@ namespace · 480 unmodified lines | ||
| 481 | 481 | if (arr_maybe->alloc_type != vm_array_t::type_desc()) |
| 482 | 482 | throw module_reader_exception{ "Data index not an array type" }; |
| 483 | 483 | |
| 484 | − auto arr = dynamic_cast<vm_array_t *>(arr_maybe); | |
| 484 | + auto arr = static_cast<vm_array_t *>(arr_maybe); | |
| 485 | 485 | |
| 486 | 486 | auto array_index = word_t{}; |
| 487 | 487 | std::tie(success, array_index) = read_next_word(reader); |
| @@ -203,7 +203,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 202 unmodified lines | ||
| 203 | 203 | assert(frame_type != nullptr); |
| 204 | 204 | assert(sizeof(vm_frame_base_alloc_t) < frame_type->size_in_bytes && "Requested frame size less than VM frame base size"); |
| 205 | 205 | |
| 206 | − auto layout = dynamic_cast<vm_stack_layout *>(_mem.get()); | |
| 206 | + auto layout = static_cast<vm_stack_layout *>(_mem.get()); | |
| 207 | 207 | |
| 208 | 208 | auto page_top_frame = layout->top_page->page_top_frame; |
| 209 | 209 | const auto new_frame_size = sizeof(vm_frame_t) + frame_type->size_in_bytes; |
| @@ -236,7 +236,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 26 unmodified lines | ||
| 236 | 236 | |
| 237 | 237 | vm_frame_t *vm_stack_t::push_frame() |
| 238 | 238 | { |
| 239 | − auto layout = dynamic_cast<vm_stack_layout *>(_mem.get()); | |
| 239 | + auto layout = static_cast<vm_stack_layout *>(_mem.get()); | |
| 240 | 240 | |
| 241 | 241 | auto current_top_frame = layout->top_frame; |
| 242 | 242 | auto new_top_frame = layout->top_page->page_top_frame; |
| @@ -252,7 +252,7 @@ vm_frame_t *vm_stack_t::push_frame() · 9 unmodified lines | ||
| 252 | 252 | |
| 253 | 253 | vm_frame_t *vm_stack_t::pop_frame() |
| 254 | 254 | { |
| 255 | − auto layout = dynamic_cast<vm_stack_layout *>(_mem.get()); | |
| 255 | + auto layout = static_cast<vm_stack_layout *>(_mem.get()); | |
| 256 | 256 | |
| 257 | 257 | auto current_frame = layout->top_frame; |
| 258 | 258 | if (current_frame == nullptr) |
| @@ -292,6 +292,6 @@ vm_frame_t *vm_stack_t::pop_frame() · 33 unmodified lines | ||
| 292 | 292 | |
| 293 | 293 | vm_frame_t *vm_stack_t::peek_frame() const |
| 294 | 294 | { |
| 295 | − auto layout = dynamic_cast<vm_stack_layout *>(_mem.get()); | |
| 295 | + auto layout = static_cast<vm_stack_layout *>(_mem.get()); | |
| 296 | 296 | return layout->top_frame; |
| 297 | 297 | } |