Exemplo n.º 1
0
 def test_pop_pointer_1(self):
     args = ['Filename', 'pointer', '1']
     expected = ('// pop pointer 1\n' + self.DECREMENT_SP_AND_LOAD_STACK +
                 '@THAT\n'
                 'M=D\n')
     actual = trans.parse_pop(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 2
0
 def test_pop_static(self):
     args = ['Filename', 'static', '7']
     expected = ('// pop static 7\n' + self.DECREMENT_SP_AND_LOAD_STACK +
                 '@Filename.7\n'
                 'M=D\n')
     actual = trans.parse_pop(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 3
0
 def test_non_existent_output_file(self):
     test_name = 'StackTest'
     test_folder = self.stack_arith_path + test_name + '/'
     test = test_folder + test_name + '.vm'
     out_file = 'sth/out.txt'
     with self.assertRaises(IOError):
         VMTranslator(test, out_file, False)
Exemplo n.º 4
0
 def test_push_constant(self):
     args = ['Filename', 'constant', '7']
     expected = ('// push constant 7\n'
                 '@7\n'
                 'D=A\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 5
0
 def test_push_static(self):
     args = ['Filename', 'static', '7']
     expected = ('// push static 7\n'
                 '@Filename.7\n'
                 'D=M\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 6
0
 def test_push_pointer_1(self):
     args = ['Filename', 'pointer', '1']
     expected = ('// push pointer 1\n'
                 '@THAT\n'
                 'D=M\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 7
0
 def test_clean_text(self):
     vm_text = ('// by Nisan and Schocken, MIT Press.\n'
                '// File name: projects/06/add/Add.asm\n'
                '// Computes R0 = 2 + 3  (R0 refers to RAM[0])\n'
                ' // Woah! \n'
                'push constant 8\n'
                'add\n'
                '\tsub \n'
                ' pop this // No Good!\n')
     expected = [['push', 'constant', '8'], ['add'], ['sub'],
                 ['pop', 'this']]
     actual = trans.clean_text(vm_text)
     self.assertEqual(expected, actual)
Exemplo n.º 8
0
 def test_pop_temp(self):
     args = ['Filename', 'temp', '7']
     expected = ('// pop temp 7\n'
                 '@7\n'
                 'D=A\n'
                 '@5\n'
                 'D=D+A\n'
                 '@R13\n'
                 'M=D\n' + self.DECREMENT_SP_AND_LOAD_STACK + '@R13\n'
                 'A=M\n'
                 'M=D\n')
     actual = trans.parse_pop(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 9
0
 def test_pop_argument(self):
     args = ['Filename', 'argument', '7']
     expected = ('// pop argument 7\n'
                 '@7\n'
                 'D=A\n'
                 '@ARG\n'
                 'D=D+M\n'
                 '@R13\n'
                 'M=D\n' + self.DECREMENT_SP_AND_LOAD_STACK + '@R13\n'
                 'A=M\n'
                 'M=D\n')
     actual = trans.parse_pop(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 10
0
 def test_push_temp(self):
     args = ['Filename', 'temp', '3']
     expected = ('// push temp 3\n'
                 '@3\n'
                 'D=A\n'
                 '@5\n'
                 'A=D+A\n'
                 'D=M\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 11
0
 def test_push_that(self):
     args = ['Filename', 'that', '7']
     expected = ('// push that 7\n'
                 '@7\n'
                 'D=A\n'
                 '@THAT\n'
                 'A=D+M\n'
                 'D=M\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 12
0
 def test_push_local(self):
     args = ['Filename', 'local', '7']
     expected = ('// push local 7\n'
                 '@7\n'
                 'D=A\n'
                 '@LCL\n'
                 'A=D+M\n'
                 'D=M\n'
                 '@SP\n'
                 'A=M\n'
                 'M=D\n'
                 '@SP\n'
                 'M=M+1\n')
     actual = trans.parse_push(*args)
     self.assertEqual(expected, actual)
Exemplo n.º 13
0
 def test_non_existent_input_file(self):
     non_existent_file = self.stack_arith_path + 'sth.asm'
     out_file = 'out.txt'
     with self.assertRaises(IOError):
         VMTranslator(non_existent_file, out_file, False)