Esempio n. 1
0
    def test_write_pushpop_pop_pointer(self):
        outfile = os.path.join(self.tmp_dir, 'arithm_jmp_test.asm')
        cmd = 'pop'
        seg = 'pointer'

        # THIS
        idx = 0
        cmpfile = os.path.join(curr_dir, 'pushpop_cmp',
                               '{}_{}_{}.asm'.format(cmd, seg, idx))
        with open(outfile, 'w') as file:
            codewriter = code.CodeWriter(file)
            codewriter.write_pushpop(cmd, seg, idx)
        self.assertFileEqual(outfile, cmpfile,
                             'Write {} command failed'.format(cmd))

        # THAT
        idx = 1
        cmpfile = os.path.join(curr_dir, 'pushpop_cmp',
                               '{}_{}_{}.asm'.format(cmd, seg, idx))
        with open(outfile, 'w') as file:
            codewriter = code.CodeWriter(file)
            codewriter.write_pushpop(cmd, seg, idx)
        self.assertFileEqual(outfile, cmpfile,
                             'Write {} command failed'.format(cmd))

        os.remove(outfile)
Esempio n. 2
0
    def test_write_arithmetic_jmp(self):
        arithm_jmp_cmds = ['eq', 'gt', 'lt']
        outfile = os.path.join(self.tmp_dir, 'arithm_jmp_test.asm')
        cmpfile = os.path.join(curr_dir, 'arithm_jmp_cmp', 'seq.asm')

        with open(outfile, 'w') as file:
            codewriter = code.CodeWriter(file)
            for cmd in arithm_jmp_cmds:
                codewriter.write_arithmetic(cmd)

        self.assertFileEqual(outfile, cmpfile,
                             'Write {} command failed'.format(cmd))
        os.remove(outfile)
Esempio n. 3
0
    def test_write_arithmetic(self):
        arithm_cmds = ['add', 'sub', 'neg', 'and', 'or', 'not']
        outfile = os.path.join(self.tmp_dir, 'arithm_test.asm')

        for cmd in arithm_cmds:
            cmpfile = os.path.join(curr_dir, '..', 'vmtranslator', 'asm',
                                   '{}.asm'.format(cmd))
            with open(outfile, 'w') as file:
                codewriter = code.CodeWriter(file)
                codewriter.write_arithmetic(cmd)
            self.assertFileEqual(outfile, cmpfile,
                                 'Write {} command failed'.format(cmd))
            os.remove(outfile)