Example #1
0
def Jump(arg):
    arg_type, arg_value = arg
    if arg_type == "link":
        change.attribute(seg_links["system"], "target_cell", arg_value)
    else:
        raise UndefinedBehaviour(f"Поведение команды Jmp с аргументом типа"
                                 f"{arg_type} не определено")
Example #2
0
def data_segment(num):
    new_size = calculate_new_size(num)
    new_num = add.create_segment("data_segment", self_length=new_size)
    attach_with_old_segment(num, new_num)
    change.attribute(seg_links["system"], "last_data_segment", new_num)
    add.empty_data(new_num)
    return new_num
Example #3
0
def program(cells):
    length = memory_control.determine_segment_size("program", len(cells))
    num = create_segment("program", self_length=length)
    # потом: сделать механизм проверки главности программы
    change.attribute(seg_links["system"], "main_program", num)
    data_begin = stream_data(num, cells)
    change.attribute(seg_links["system"], "target_cell", data_begin)
    change.relative_links(num)
    namespace(num)
    return num
Example #4
0
def Jump_if(condition, arg):
    cond_arg_type, cond_type, cond_value = link.unpack(condition)
    arg_type, arg_value = arg
    if arg_type == "link":
        if cond_type == "logic":
            if not cond_value:
                change.attribute(seg_links["system"], "target_cell", arg_value)
                append.memory_stack("link", 0)
        else:
            raise UndefinedBehaviour(
                f"Поведение команды Jif с аргументами типов {arg_type} и "
                f"{cond_type} не определено")
    else:
        raise UndefinedArgument(f"Поведение команды Jif с аргументом типа"
                                f"{arg_type} не определено")
Example #5
0
def attribute_writing():
    """Проверка на изменение атрибута"""
    add.system_area()
    display.segment(0)
    show.attribute(0, "segment_end")
    show.attribute(0, "memory_stack")
    print()
    change.attribute(0, "segment_end", 64)
    display.segment(0)
    show.attribute(0, "segment_end")
    print()
    change.attribute(0, "memory_stack", 32)
    display.segment(0)
    show.attribute(0, "memory_stack")
    print()
Example #6
0
def segment(num, seg_type, length):
    base_args = {}
    if type(seg_type) == int:
        if not (0 <= seg_type < len(seg_types)):
            raise LowerCommandError(f"Неподдерживаемый индекс типа"
                                    f"сегмента: {seg_type}")
        base_args["type"] = seg_type
    elif type(seg_type) == str:
        if seg_type not in seg_types:
            raise LowerCommandError(f"Неизвестный тип сегмента: {seg_type}")
        base_args["type"] = seg_types.index(seg_type)
    base_args["length"] = length
    write.segment(num, base_args, {})
    # запись ссылки на конец сегмента
    change.attribute(num, "segment_end", num + length)
Example #7
0
def namespace(program_num):
    num = create_segment("namespace")
    change.attribute(num, "program", program_num)
    change.attribute(program_num, "namespace", num)
    # потом: сделать механизм проверки главности пространства имён
    change.attribute(seg_links["system"], "target_namespace", num)
    empty_data(num)
    return num
Example #8
0
def Return():
    link_type, target_cell = pull.call_stack()
    change.attribute(seg_links["system"], "target_cell", target_cell)
Example #9
0
def change_data(num, first_empty_cell_value, free_cells_value):
    change.attribute(num, "first_empty_cell", first_empty_cell_value)
    change.attribute(num, "free_cells", free_cells_value)
Example #10
0
def change_stack(num, first_empty_cell_value, last_full_cell_value,
                 free_cells_value):
    change.attribute(num, "first_empty_cell", first_empty_cell_value)
    change.attribute(num, "last_full_cell", last_full_cell_value)
    change.attribute(num, "free_cells", free_cells_value)
Example #11
0
def empty_data(num):
    first = num + header_length
    change.attribute(num, "data_begin", first)
    change.attribute(num, "first_empty_cell", first)
    seg_end = find.attribute(num, "segment_end")
    change.attribute(num, "free_cells", seg_end - first)
Example #12
0
def tape_length(delta):
    length = find.attribute(seg_links["system"], "tape_length")
    change.attribute(seg_links["system"], "tape_length", length + delta)
Example #13
0
def data_segment():
    num = create_segment("data_segment")
    change.attribute(seg_links["system"], "first_data_segment", num)
    change.attribute(seg_links["system"], "last_data_segment", num)
    empty_data(num)
    return num
Example #14
0
def call_stack():
    num = create_segment("call_stack")
    change.attribute(seg_links["system"], "call_stack", num)
    empty_data(num)
    return num
Example #15
0
def End():
    change.attribute(seg_links["system"], "target_cell", 0)
Example #16
0
def stream_data(num, stream):
    first = num + header_length
    change.attribute(num, "data_begin", first)
    write.cells_stream(first, stream)
    change.attribute(num, "first_empty_cell", first + len(stream))
    return first
Example #17
0
def attach_with_old_segment(num, new_num):
    change.attribute(num, "next_segment", new_num)
    change.attribute(new_num, "previous_segment", num)