x86128: (Default)
[personal profile] x86128
Теперь интерпретатор может переварить более сложный тест:

MODULE Samples;
const
    pass = 12345;
    fail = 54321;

var t1 : integer;

procedure test1;
begin
    if t1 = 10 then
        t1 := 9
    elsif t1 < 0 then
        halt(fail)
    else
        halt(fail)
    end
end test1;

procedure test2;
begin
    if t1 = 10 then
        halt(fail)
    elsif t1 < 0 then
        halt(fail)
    else
        t1 := -1
    end
end test2;

procedure test3;
begin
    if t1 = 10 then
        halt(fail)
    elsif t1 < 0 then
        t1 := pass
    else
        halt(fail)
    end
end test3;

begin
    (* initializing test *)
    t1 := 10;

    (* do modifications of global var t1 *)
    test1;
    test2;
    test3;

    (* t1 must be pass *)
    halt(t1)

END Samples.


Получаем на выходе:
{'decls': {'consts': {'fail': 54321, 'pass': 12345},
           'procs': {'test1': {'args': [],
                               'decls': {'consts': {}, 'procs': {}, 'vars': {}},
                               'text': [('LOAD', 't1'),
                                        ('CONST', 10),
                                        ('RELOP', '='),
                                        ('BR_ZERO', 'L0'),
                                        ('CONST', 9),
                                        ('STOR', 't1'),
                                        ('BR', 'L2'),
                                        ('LABEL', 'L0'),
                                        ('LOAD', 't1'),
                                        ('CONST', 0),
                                        ('RELOP', '<'),
                                        ('BR_ZERO', 'L1'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('BR', 'L2'),
                                        ('LABEL', 'L1'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('LABEL', 'L2')]},
                     'test2': {'args': [],
                               'decls': {'consts': {}, 'procs': {}, 'vars': {}},
                               'text': [('LOAD', 't1'),
                                        ('CONST', 10),
                                        ('RELOP', '='),
                                        ('BR_ZERO', 'L3'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('BR', 'L5'),
                                        ('LABEL', 'L3'),
                                        ('LOAD', 't1'),
                                        ('CONST', 0),
                                        ('RELOP', '<'),
                                        ('BR_ZERO', 'L4'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('BR', 'L5'),
                                        ('LABEL', 'L4'),
                                        ('CONST', 1),
                                        ('UNARY', '-'),
                                        ('STOR', 't1'),
                                        ('LABEL', 'L5')]},
                     'test3': {'args': [],
                               'decls': {'consts': {}, 'procs': {}, 'vars': {}},
                               'text': [('LOAD', 't1'),
                                        ('CONST', 10),
                                        ('RELOP', '='),
                                        ('BR_ZERO', 'L6'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('BR', 'L8'),
                                        ('LABEL', 'L6'),
                                        ('LOAD', 't1'),
                                        ('CONST', 0),
                                        ('RELOP', '<'),
                                        ('BR_ZERO', 'L7'),
                                        ('LOAD', 'pass'),
                                        ('STOR', 't1'),
                                        ('BR', 'L8'),
                                        ('LABEL', 'L7'),
                                        ('LOAD', 'fail'),
                                        ('CALL', 'halt'),
                                        ('LABEL', 'L8')]}},
           'vars': {'t1': (0, 'integer')}},
 'name': 'Samples',
 'text': [('CONST', 10),
          ('STOR', 't1'),
          ('CALL', 'test1'),
          ('CALL', 'test2'),
          ('CALL', 'test3'),
          ('LOAD', 't1'),
          ('CALL', 'halt'),
          ('STOP', '12345')]}


И результат работы:
Program halted with code: 12345
SUCCESS


Заодно перелопатил на использование объектов вместо туплей чтобы избавиться от конструкций типа e[1][0][1] в пользу st.then_block

Profile

x86128: (Default)
x86128

April 2023

S M T W T F S
      1
2345678
9101112131415
16171819202122
232425 26272829
30      

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 06:27 am
Powered by Dreamwidth Studios