Ejemplo n.º 1
0
  def main():
    path = Util.getCommandLineArgument(1)
    code_writer = CodeWriter(path.replace('.vm', '') + '.asm')

    if os.path.isdir(path):
      files = FileSet(path, 'vm')

      while files.hasMoreFiles():
        filename = files.nextFile()
        Main.parse(filename, code_writer)
    elif os.path.isfile(path):
      Main.parse(path, code_writer)

    code_writer.Close()
Ejemplo n.º 2
0
class TestCodeWriter(unittest.TestCase):
    def setUp(self):
        self.filename = './StackArithmetic/SimpleAdd/SimpleAdd.asm'
        self.code_writer = CodeWriter(self.filename)

    def tearDown(self):
        self.code_writer.Close()

    def assertion(self, actual, expected):
        asserted = actual == expected
        if not asserted:
            print 'FAILED: assert {} == {}'.format(actual, expected)
        assert asserted

    def test_constructor_sets_attributes(self):
        assert self.code_writer.output.__class__.__name__ == 'file'

    def test_write_arthmetic(self):
        # self.assertion(self.code_writer.writeArithmetic('add'), '')
        assert '@SP' in self.code_writer.writeArithmetic('add')