def dictionary_item_writing(): """Проверка на запись элемента списка""" args = [128, 64, 256] write.entity(0, "dictionary_item", args) display.entity(0) change.dictionary_item_part(0, "key", 48) display.entity(0)
def stack(num, obj_type, value): check_type("stack", obj_type) obj_size = memory_control.determine_object_size(obj_type, value) top = find.attribute(num, "first_empty_cell") place = check_free_place(num, obj_size) check_stack_overflow(num, place) write.entity(top, obj_type, value) change_stack(num, top + obj_size, top, place)
def entity_writing(): """Проверка на запись объектов""" entities = [[0, "none", None], [0, "link", 1000], [0, "command", 15], [0, "logic", 1], [0, "number", 255], [0, "chars", "something"]] for entity in entities: write.entity(*entity) display.cell(0) display.cell(1) display.entity(0)
def Pop(arg): arg_type, arg_value = arg if arg_type == "none": link_type, link = pull.memory_stack() elif arg_type == "link": link_type, link_value = pull.memory_stack() write.entity(arg_value, "link", link_value) else: raise UndefinedArgument(f"Поведение команды Pop с аргументом типа" f"{arg_type} не определено")
def relative_links(num): data_begin = find.attribute(num, "data_begin") data_end = find.attribute(num, "segment_end") index = data_begin while index < data_end: obj_type, obj_value = read.entity(index) if obj_type == "link": write.entity(index, "link", data_begin + obj_value) index += memory_control.determine_object_size(obj_type, obj_value) elif obj_type == "chars": index += memory_control.determine_object_size(obj_type, obj_value) else: index += 2
def stack(num): top = find.attribute(num, "first_empty_cell") data_begin = find.attribute(num, "data_begin") if top == data_begin: stack_type = find.attribute(num, "type") raise LowerCommandError(f"Стек {seg_types[stack_type]} пуст при " f"попытке извлечения") last_cell = find.attribute(num, "last_full_cell") free_cells = find.attribute(num, "free_cells") obj_type, obj_value = read.entity(last_cell) write.entity(last_cell, "none", None) change_stack(num, top - types_length["link"], last_cell - types_length["link"], free_cells + types_length["link"]) return obj_type, obj_value
def data_segment(num, obj_type, value): top = find.attribute(num, "first_empty_cell") obj_size = memory_control.determine_object_size(obj_type, value) place = check_free_place(num, obj_size) if place >= 0: write.entity(top, obj_type, value) change_data(num, top + obj_size, place) index = top else: if not find.is_last(num): next_num = find.attribute(num, "next_segment") index = data_segment(next_num, obj_type, value) else: new_num = extend.data_segment(num) index = data_segment(new_num, obj_type, value) return index
def Equate(receiver, source): left_type, left_value = receiver if left_type != "link": raise UndefinedArgument(f"Приравнивание командой Eqt для приёмника " f"типа {left_type} не определено") rec_type, rec_value = link.get_link(left_value) if rec_type != "link": raise UndefinedBehaviour(f"Приравнивание типа {rec_type} командой Eqt " f"не определено") right_type, right_value = source if right_type != "link": raise UndefinedArgument(f"Приравнивание командой Eqt для источника " f"типа {right_type} не определено") src_type, src_value = link.get_link(right_value) if src_type == "link": obj_type, obj_value = link.get_link(src_value) copy_num = make.entity(obj_type, obj_value) write.entity(left_value, "link", copy_num) else: write.entity(left_value, "link", right_value) append.memory_stack("link", 0)
def dictionary_item_part(num, part, value): if part == "dictionary": write.entity(num + 2, "link", value) elif part == "key": write.entity(num + 4, "link", value) elif part == "value": write.entity(num + 6, "link", value) else: raise LowerCommandError(f"Несуществующий атрибут элемента словаря " f"{part}")
def array_writing(): """Проверка на запись массива""" write.entity(0, "array", [5, 10, 15, 20, 25]) display.entity(0)
def attribute(num, name, value): index, kind = find_attribute(num, name) write.entity(index, kind, value)