def alloc_list(self, pos, size_tag, item_count, body_length): """ Allocate a new list of the given size, and write the resulting pointer at position i. Return the newly allocated position. """ body_length = ptr.round_up_to_word(body_length) result = self.allocate(body_length) offet = result - (pos + 8) p = ptr.new_list(offet // 8, size_tag, item_count) self.write_int64(pos, p) return result
def _endof_list_bit(seg, p, offset, count): bytes_length = ptr.round_up_to_word(count) // 8 return ptr.round_up_to_word(offset + bytes_length)
def _endof_list_primitive(seg, p, offset, item_size, count): item_size = ptr.list_item_length(item_size) return ptr.round_up_to_word(offset + item_size * count)
def visit_list_bit(self, buf, p, offset, count): bytes_length = ptr.round_up_to_word(count) / 8 return ptr.round_up_to_word(offset + bytes_length)
def visit_list_primitive(self, buf, p, offset, item_size, count): item_size = ptr.list_item_length(item_size) return ptr.round_up_to_word(offset + item_size*count)
def test_round_up_to_word(): assert ptr.round_up_to_word(0) == 0 assert ptr.round_up_to_word(5) == 8 assert ptr.round_up_to_word(7) == 8 assert ptr.round_up_to_word(8) == 8 assert ptr.round_up_to_word(9) == 16