Пример #1
0
 def test_works_for_good_code(self):
     self._assert_results_match(
         inp=[
             'jump main',
             'func:',
             'out "Input your age: "',
             'ini age',
             'out "You are "',
             'out age',
             'out " years old -- that\'s cool!"',
             'back',
             'main:',
             'br func',
         ],
         # 0. main 1. func  2            3. age
         mem=[37, 6, 'Input your age: ', None,
              'You are ', ' years old -- that\'s cool!'],
         #    4           5
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.JUMP,
             Op.PUSH, i32(2),
             Op.OUT,
             Op.INI,
             Op.POP, i32(3),
             Op.PUSH, i32(4),
             Op.OUT,
             Op.PUSH, i32(3),
             Op.OUT,
             Op.PUSH, i32(5),
             Op.OUT,
             Op.BACK,
             Op.PUSH, i32(1),
             Op.BR)
     )
Пример #2
0
 def test_works_for_multiple_instructions(self):
     self._assert_results_match(
         inp=['ini n', 'out n'],
         mem=[None],
         ins=make.ins(Op.INI, Op.POP, i32(0),
              Op.PUSH, i32(0), Op.OUT)
     )
Пример #3
0
 def test_br_(self):
     self._assert_results_match(
         inp=['br func'],
         mem=[None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.BR)
     )
Пример #4
0
 def test_out_(self):
     self._assert_results_match(
         inp=['out age'],
         mem=[None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.OUT)
     )
Пример #5
0
 def test_ins_(self):
     self._assert_results_match(
         inp=['ins name'],
         mem=[None],
         ins=make.ins(
             Op.INS,
             Op.POP, i32(0))
     )
Пример #6
0
 def test_jump_(self):
     self._assert_results_match(
         inp=['jump main'],
         mem=[None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.JUMP)
     )
Пример #7
0
 def test_jmpf_(self):
     self._assert_results_match(
         inp=['jmpf false main'],
         mem=[None, None],
         ins=make.ins(
             Op.PUSH, i32(1),
             Op.PUSH, i32(0),
             Op.JMPF)
     )
Пример #8
0
 def test_sti_(self):
     self._assert_results_match(
         inp=['sti "42" magic'],
         mem=['42', None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.STI,
             Op.POP, i32(1))
     )
Пример #9
0
 def test_not_(self):
     self._assert_results_match(
         inp=['not 42 false'],
         mem=[42, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.BOOL,
             Op.NOT,
             Op.POP, i32(1))
     )
Пример #10
0
 def test_con_(self):
     self._assert_results_match(
         inp=['con "hello" world message'],
         mem=['hello', None, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.CON,
             Op.POP, i32(2))
     )
Пример #11
0
 def test_neq_(self):
     self._assert_results_match(
         inp=['neq a 2 b'],
         mem=[None, 2, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.NEQ,
             Op.POP, i32(2))
     )
Пример #12
0
 def test_lth_(self):
     self._assert_results_match(
         inp=['lth a 2 b'],
         mem=[None, 2, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.LTH,
             Op.POP, i32(2))
     )
Пример #13
0
 def test_mul_(self):
     self._assert_results_match(
         inp=['mul a 2 b'],
         mem=[None, 2, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.MUL,
             Op.POP, i32(2))
     )
Пример #14
0
 def test_div_(self):
     self._assert_results_match(
         inp=['div a 2 b'],
         mem=[None, 2, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.DIV,
             Op.POP, i32(2))
     )
Пример #15
0
 def test_sub_(self):
     self._assert_results_match(
         inp=['sub a 2 b'],
         mem=[None, 2, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.SUB,
             Op.POP, i32(2))
     )
Пример #16
0
 def test_put_(self):
     self._assert_results_match(
         inp=['put 1 a', 'put a b'],
         mem=[1, None, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.POP, i32(1),
             Op.PUSH, i32(1),
             Op.POP, i32(2))
     )
Пример #17
0
 def test_add_(self):
     self._assert_results_match(
         inp=['add 1 a b'],
         mem=[1, None, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.PUSH, i32(1),
             Op.ADD,
             Op.POP, i32(2))
     )
Пример #18
0
 def test_err(self):
     self._assert_results_match(
         inp=['err "piss off" 404'],
         mem=['piss off', 404],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.OUT,
             Op.PUSH, i32(1),
             Op.ERR)
     )
Пример #19
0
 def test_and_(self):
     self._assert_results_match(
         inp=['and 0 1 false'],
         mem=[0, 1, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.BOOL,
             Op.PUSH, i32(1),
             Op.BOOL,
             Op.AND,
             Op.POP, i32(2))
     )
Пример #20
0
 def test_or_(self):
     self._assert_results_match(
         inp=['or 0 1 true'],
         mem=[0, 1, None],
         ins=make.ins(
             Op.PUSH, i32(0),
             Op.BOOL,
             Op.PUSH, i32(1),
             Op.BOOL,
             Op.OR,
             Op.POP, i32(2))
     )
Пример #21
0
 def test_works_for_label_and_instruction(self):
     self._assert_results_match(
         inp=['jump exit', 'exit:'],
         mem=[6],
         ins=make.ins(Op.PUSH, i32(0), Op.JUMP)
     )
Пример #22
0
 def test_nl_(self):
     self._assert_results_match(
         inp=['nl'],
         mem=[],
         ins=make.ins(Op.NL)
     )
Пример #23
0
 def test_end_(self):
     self._assert_results_match(
         inp=['end'],
         mem=[],
         ins=make.ins(Op.END)
     )
Пример #24
0
 def test_back_(self):
     self._assert_results_match(
         inp=['back'],
         mem=[],
         ins=make.ins(Op.BACK)
     )
Пример #25
0
 def test_works_for_empty_code(self):
     self._assert_results_match(
         inp=[],
         mem=[],
         ins=make.ins()
     )