History

Address more bugs found during limbo compiler testing

arr committed 9 years ago

Commit 84ac3311 parent 220aaf26 files · +52 −63Browse files

Showing the changes to src/include (2 of 6 files). Show all

Unified · Split

2 files
  1. src/include/runtime.h +1 −1
  2. src/include/vm_memory.h +20 −15
src/include/runtime.h+1−1
@@ -198,7 +198,7 @@ namespace disvm · 197 unmodified lines
198198
199199 public:
200200 vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length);
201− vm_array_t(vm_array_t *original, word_t begin_index, word_t length);
201+ vm_array_t(vm_array_t &original, word_t begin_index, word_t length);
202202 vm_array_t(const vm_string_t *s);
203203 ~vm_array_t();
204204
src/include/vm_memory.h+20−15
@@ -60,9 +60,12 @@ namespace disvm · 59 unmodified lines
6060 // Destroy supplied memory based on the type descriptor
6161 void destroy_memory(const type_descriptor_t &type_desc, void *data);
6262
63− // Increment the ref count of all points in the supplied memory allocation
63+ // Increment the ref count of all pointers in the supplied memory allocation
6464 void inc_ref_count_in_memory(const type_descriptor_t &type_desc, void *data);
6565
66+ // Decrement the ref count of all pointers in the supplied memory allocation
67+ void dec_ref_count_in_memory(const type_descriptor_t &type_desc, void *data);
68+
6669 // Decrement the ref count and if 0 free the allocation
6770 void dec_ref_count_and_free(vm_alloc_t *alloc);
6871
@@ -81,20 +84,21 @@ namespace disvm · 12 unmodified lines
8184 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += (8 * sizeof(pointer_t)))
8285 {
8386 const auto words8 = type_desc.pointer_map[i];
84− if (words8 != 0)
85− {
86− const auto flags = std::bitset<sizeof(words8) * 8>{ words8 };
87−
88− // Enumerating the flags in reverse order so memory access is sequential.
89− if (flags[7] && (memory[0] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[0]), offset_accum);
90− if (flags[6] && (memory[1] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[1]), offset_accum + (1 * sizeof(pointer_t)));
91− if (flags[5] && (memory[2] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[2]), offset_accum + (2 * sizeof(pointer_t)));
92− if (flags[4] && (memory[3] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[3]), offset_accum + (3 * sizeof(pointer_t)));
93− if (flags[3] && (memory[4] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[4]), offset_accum + (4 * sizeof(pointer_t)));
94− if (flags[2] && (memory[5] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[5]), offset_accum + (5 * sizeof(pointer_t)));
95− if (flags[1] && (memory[6] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[6]), offset_accum + (6 * sizeof(pointer_t)));
96− if (flags[0] && (memory[7] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[7]), offset_accum + (7 * sizeof(pointer_t)));
97− }
87+ assert(sizeof(words8) == 1);
88+ if (words8 == 0)
89+ continue;
90+
91+ const auto flags = std::bitset<sizeof(words8) * 8>{ words8 };
92+
93+ // Enumerating the flags in reverse order so memory access is sequential.
94+ if (flags[7] && (memory[0] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[0]), offset_accum);
95+ if (flags[6] && (memory[1] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[1]), offset_accum + (1 * sizeof(pointer_t)));
96+ if (flags[5] && (memory[2] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[2]), offset_accum + (2 * sizeof(pointer_t)));
97+ if (flags[4] && (memory[3] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[3]), offset_accum + (3 * sizeof(pointer_t)));
98+ if (flags[3] && (memory[4] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[4]), offset_accum + (4 * sizeof(pointer_t)));
99+ if (flags[2] && (memory[5] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[5]), offset_accum + (5 * sizeof(pointer_t)));
100+ if (flags[1] && (memory[6] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[6]), offset_accum + (6 * sizeof(pointer_t)));
101+ if (flags[0] && (memory[7] != runtime_constants::nil)) callback(reinterpret_cast<pointer_t>(memory[7]), offset_accum + (7 * sizeof(pointer_t)));
98102 }
99103 }
100104
@@ -112,6 +116,7 @@ namespace disvm · 11 unmodified lines
112116 if (byte_offset < type_desc.map_in_bytes)
113117 {
114118 const auto words8 = type_desc.pointer_map[byte_offset];
119+ assert(sizeof(words8) == 1);
115120 if (words8 != 0)
116121 {
117122 const auto flags = std::bitset<sizeof(words8) * 8>{ words8 };