History

Add type_descriptor::is_equal() function. - Replace pointer and use function throughout VM Complete implementation of vm_array_t::copy_from() which supports the slicela instruction.

arr committed 9 years ago

Commit 7838bae1 parent 5ef656f5 files · +30 −12Browse files

Showing the changes to src/vm/array.cpp (1 of 5 files). Show all

Unified · Split

src/vm/array.cpp+10−10
@@ -166,7 +166,7 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 165 unmodified lines
166166 if (this_begin_index < 0 || _length < (this_begin_index + source._length))
167167 throw out_of_range_memory{};
168168
169− if (source._element_type != _element_type)
169+ if (!source._element_type->is_equal(_element_type.get()))
170170 throw type_violation{};
171171
172172 auto dest_arr = _arr + (this_begin_index * _element_type->size_in_bytes);
@@ -174,15 +174,15 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 1 unmodified line
174174 // Increment all pointers if we have reference types.
175175 if (_element_type->map_in_bytes != 0)
176176 {
177− assert(false && "Not implemented");
178− //auto &type_desc = *_element_type;
179− //auto source_array_element = source->_arr;
180− //for (word_t i = 0; i < source->_length; ++i)
181− //{
182− // source_array_element += (i * type_desc.size_in_bytes);
183− // inc_ref_count_in_alloc(type_desc, source_array_element);
184− //}
177+ auto &type_desc = *_element_type;
178+ auto source_array_element = source._arr;
179+ for (auto i = word_t{ 0 }; i < source._length; ++i)
180+ {
181+ source_array_element += (i * type_desc.size_in_bytes);
182+ inc_ref_count_in_memory(type_desc, source_array_element);
183+ }
185184 }
186185
187− std::memcpy(dest_arr, source._arr, (source._length * _element_type->size_in_bytes));
186+ // Moving data within the same array is permitted so use memmove().
187+ std::memmove(dest_arr, source._arr, (source._length * _element_type->size_in_bytes));
188188 }