Showing the changes to src/vm/string.cpp (1 of 31 files). Show all
Unified · Split
| @@ -11,8 +11,13 @@ · 10 unmodified lines | |||
| 11 | #include <debug.h> | 11 | #include <debug.h> |
| 12 | #include <exceptions.h> | 12 | #include <exceptions.h> |
| 13 | 13 | ||
| 14 | using namespace disvm; | 14 | using disvm::debug::component_trace_t; |
| 15 | using namespace disvm::runtime; | 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 | std::shared_ptr<const type_descriptor_t> vm_string_t::type_desc() | 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 | for (auto i = word_t{ 0 }; i < len; ++i) | 53 | for (auto i = word_t{ 0 }; i < len; ++i) |
| 49 | { | 54 | { |
| 50 | const auto sc1 = static_cast<runtime::rune_t>(s1[i]); | 55 | const auto sc1 = static_cast<disvm::runtime::rune_t>(s1[i]); |
| 51 | const auto sc2 = static_cast<runtime::rune_t>(s2[i]); | 56 | const auto sc2 = static_cast<disvm::runtime::rune_t>(s2[i]); |
| 52 | 57 | ||
| 53 | if (sc1 != sc2) | 58 | if (sc1 != sc2) |
| 54 | return (sc1 < sc2) ? (-1) : 1; | 59 | return (sc1 < sc2) ? (-1) : 1; |
| @@ -128,10 +133,10 @@ namespace · 73 unmodified lines | |||
| 128 | } | 133 | } |
| 129 | 134 | ||
| 130 | template<> | 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 | assert(dest != nullptr && source != nullptr && dest != source); | 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 | void combine( | 142 | void combine( |
| @@ -146,14 +151,14 @@ namespace · 8 unmodified lines | |||
| 146 | { | 151 | { |
| 147 | if (dest_is_rune) | 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 | if (source1_is_rune) | 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 | else | 157 | else |
| 153 | copy_characters_to(dest_rune, 0, source1, source1_length); | 158 | copy_characters_to(dest_rune, 0, source1, source1_length); |
| 154 | 159 | ||
| 155 | if (source2_is_rune) | 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 | else | 162 | else |
| 158 | copy_characters_to(dest_rune, source1_length, source2, source2_length); | 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 | encoded_str += utf8::decode(encoded_str, rune_dest[i]); | 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>()) | 243 | if (disvm::debug::is_component_tracing_enabled<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); | 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 | vm_string_t::vm_string_t(const vm_string_t &s1, const vm_string_t &s2) | 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 | const auto length_in_bytes = _length * _character_size; | 302 | const auto length_in_bytes = _length * _character_size; |
| 298 | std::memcpy(dest, (src + (begin_index * _character_size)), length_in_bytes); | 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>()) | 305 | if (disvm::debug::is_component_tracing_enabled<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); | 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 | vm_string_t::~vm_string_t() | 309 | vm_string_t::~vm_string_t() |
| @@ -314,8 +319,8 @@ vm_string_t::~vm_string_t() · 9 unmodified lines | |||
| 314 | debug::assign_debug_pointer(&source); | 319 | debug::assign_debug_pointer(&source); |
| 315 | debug::assign_debug_pointer(&_encoded_str); | 320 | debug::assign_debug_pointer(&_encoded_str); |
| 316 | 321 | ||
| 317 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | 322 | if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) |
| 318 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm string"); | 323 | disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm string"); |
| 319 | } | 324 | } |
| 320 | 325 | ||
| 321 | vm_string_t &vm_string_t::append(const vm_string_t &other) | 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 | return _length; | 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 | if (index < 0 || _length <= index) | 399 | if (index < 0 || _length <= index) |
| 395 | throw index_out_of_range_memory{ 0, _length - 1, index }; | 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 | // Check if multi-byte or ASCII | 407 | // Check if multi-byte or ASCII |
| 403 | if (_character_size != sizeof(char)) | 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 | else | 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 | // This function does not adhere to the immutable string contract. | 416 | // This function does not adhere to the immutable string contract. |
| 412 | // Therefore, it is unsafe to call this function if there is more | 417 | // Therefore, it is unsafe to call this function if there is more |