Showing the changes to src/vm/string.cpp (1 of 31 files). Show all
Unified · Split
| @@ -11,8 +11,13 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <debug.h> |
| 12 | 12 | #include <exceptions.h> |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::debug::component_trace_t; | |
| 15 | +using disvm::debug::log_level_t; | |
| 16 | + | |
| 17 | +using disvm::runtime::intrinsic_type_desc; | |
| 18 | +using disvm::runtime::type_descriptor_t; | |
| 19 | +using disvm::runtime::vm_string_t; | |
| 20 | +using disvm::runtime::word_t; | |
| 16 | 21 | |
| 17 | 22 | std::shared_ptr<const type_descriptor_t> vm_string_t::type_desc() |
| 18 | 23 | { |
| @@ -47,8 +52,8 @@ namespace · 28 unmodified lines | ||
| 47 | 52 | { |
| 48 | 53 | for (auto i = word_t{ 0 }; i < len; ++i) |
| 49 | 54 | { |
| 50 | − const auto sc1 = static_cast<runtime::rune_t>(s1[i]); | |
| 51 | − const auto sc2 = static_cast<runtime::rune_t>(s2[i]); | |
| 55 | + const auto sc1 = static_cast<disvm::runtime::rune_t>(s1[i]); | |
| 56 | + const auto sc2 = static_cast<disvm::runtime::rune_t>(s2[i]); | |
| 52 | 57 | |
| 53 | 58 | if (sc1 != sc2) |
| 54 | 59 | return (sc1 < sc2) ? (-1) : 1; |
| @@ -128,10 +133,10 @@ namespace · 73 unmodified lines | ||
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | template<> |
| 131 | − void copy_characters_to(runtime::rune_t *dest, word_t dest_start, const runtime::rune_t *source, word_t source_length) | |
| 136 | + void copy_characters_to(disvm::runtime::rune_t *dest, word_t dest_start, const disvm::runtime::rune_t *source, word_t source_length) | |
| 132 | 137 | { |
| 133 | 138 | assert(dest != nullptr && source != nullptr && dest != source); |
| 134 | − std::memcpy((dest + dest_start), source, (source_length * sizeof(runtime::rune_t))); | |
| 139 | + std::memcpy((dest + dest_start), source, (source_length * sizeof(disvm::runtime::rune_t))); | |
| 135 | 140 | } |
| 136 | 141 | |
| 137 | 142 | void combine( |
| @@ -146,14 +151,14 @@ namespace · 8 unmodified lines | ||
| 146 | 151 | { |
| 147 | 152 | if (dest_is_rune) |
| 148 | 153 | { |
| 149 | − auto dest_rune = reinterpret_cast<runtime::rune_t *>(dest); | |
| 154 | + auto dest_rune = reinterpret_cast<disvm::runtime::rune_t *>(dest); | |
| 150 | 155 | if (source1_is_rune) |
| 151 | − copy_characters_to(dest_rune, 0, reinterpret_cast<const runtime::rune_t *>(source1), source1_length); | |
| 156 | + copy_characters_to(dest_rune, 0, reinterpret_cast<const disvm::runtime::rune_t *>(source1), source1_length); | |
| 152 | 157 | else |
| 153 | 158 | copy_characters_to(dest_rune, 0, source1, source1_length); |
| 154 | 159 | |
| 155 | 160 | if (source2_is_rune) |
| 156 | − copy_characters_to(dest_rune, source1_length, reinterpret_cast<const runtime::rune_t *>(source2), source2_length); | |
| 161 | + copy_characters_to(dest_rune, source1_length, reinterpret_cast<const disvm::runtime::rune_t *>(source2), source2_length); | |
| 157 | 162 | else |
| 158 | 163 | copy_characters_to(dest_rune, source1_length, source2, source2_length); |
| 159 | 164 | } |
| @@ -235,8 +240,8 @@ vm_string_t::vm_string_t(std::size_t encoded_str_len, const uint8_t *encoded_str · 75 unmodified lines | ||
| 235 | 240 | encoded_str += utf8::decode(encoded_str, rune_dest[i]); |
| 236 | 241 | } |
| 237 | 242 | |
| 238 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 239 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm string: %d %d >>%s<<", _length, (_length_max * _character_size), dest); | |
| 243 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 244 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm string: %d %d >>%s<<", _length, (_length_max * _character_size), dest); | |
| 240 | 245 | } |
| 241 | 246 | |
| 242 | 247 | vm_string_t::vm_string_t(const vm_string_t &s1, const vm_string_t &s2) |
| @@ -297,8 +302,8 @@ vm_string_t::vm_string_t(const vm_string_t &other, word_t begin_index, word_t en · 54 unmodified lines | ||
| 297 | 302 | const auto length_in_bytes = _length * _character_size; |
| 298 | 303 | std::memcpy(dest, (src + (begin_index * _character_size)), length_in_bytes); |
| 299 | 304 | |
| 300 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 301 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm string: %#" PRIxPTR " %d %d %#" PRIxPTR, &other, begin_index, end_index, this); | |
| 305 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 306 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "copy: vm string: %#" PRIxPTR " %d %d %#" PRIxPTR, &other, begin_index, end_index, this); | |
| 302 | 307 | } |
| 303 | 308 | |
| 304 | 309 | vm_string_t::~vm_string_t() |
| @@ -314,8 +319,8 @@ vm_string_t::~vm_string_t() · 9 unmodified lines | ||
| 314 | 319 | debug::assign_debug_pointer(&source); |
| 315 | 320 | debug::assign_debug_pointer(&_encoded_str); |
| 316 | 321 | |
| 317 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 318 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm string"); | |
| 322 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 323 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm string"); | |
| 319 | 324 | } |
| 320 | 325 | |
| 321 | 326 | vm_string_t &vm_string_t::append(const vm_string_t &other) |
| @@ -389,7 +394,7 @@ word_t vm_string_t::get_length() const · 67 unmodified lines | ||
| 389 | 394 | return _length; |
| 390 | 395 | } |
| 391 | 396 | |
| 392 | −runtime::rune_t vm_string_t::get_rune(word_t index) const | |
| 397 | +disvm::runtime::rune_t vm_string_t::get_rune(word_t index) const | |
| 393 | 398 | { |
| 394 | 399 | if (index < 0 || _length <= index) |
| 395 | 400 | throw index_out_of_range_memory{ 0, _length - 1, index }; |
| @@ -401,12 +406,12 @@ runtime::rune_t vm_string_t::get_rune(word_t index) const · 5 unmodified lines | ||
| 401 | 406 | |
| 402 | 407 | // Check if multi-byte or ASCII |
| 403 | 408 | if (_character_size != sizeof(char)) |
| 404 | − return reinterpret_cast<const rune_t *>(source)[index]; | |
| 409 | + return reinterpret_cast<const disvm::runtime::rune_t *>(source)[index]; | |
| 405 | 410 | else |
| 406 | − return static_cast<const rune_t>(source[index]); | |
| 411 | + return static_cast<const disvm::runtime::rune_t>(source[index]); | |
| 407 | 412 | } |
| 408 | 413 | |
| 409 | −void vm_string_t::set_rune(word_t index, rune_t value) | |
| 414 | +void vm_string_t::set_rune(word_t index, disvm::runtime::rune_t value) | |
| 410 | 415 | { |
| 411 | 416 | // This function does not adhere to the immutable string contract. |
| 412 | 417 | // Therefore, it is unsafe to call this function if there is more |