def compileProgram(self, ast, outputName): globalNs = self.scanAssemblies(self.references) self.fixPrimitives() # Fill globalNs with declared symbols for decl in ast: if hasattr(decl, 'name'): globalNs.symbols[decl.name] = decl globalScope = semantic.makeGlobalScope(globalNs.symbols) st = semantic.semantic(ast, globalScope) gen = CodeGenerator() gen.createProgram(outputName, st)
class CodeGeneratorTest(unittest.TestCase): def setUp(self): self.gen = CodeGenerator() def testBuildEmptyProgram(self): name = os.path.join('bin', 'codegen_empty_test') program = [] # it is a complicated program self.gen.createProgram(name, program) result = os.system('%s >> stdout.txt' % name) self.failUnless(result == 0) def testBuildHelloWorld(self): '''FIXME: this test no longer works if run in isolation. ''' program = [ PrintStatement(StringLiteral((0, '<fakesource>'), '\'Hello, code generator test!\'')) ] name = os.path.join('bin', 'codegen_hello_test') self.gen.createProgram(name, program) result = os.system('%s >> stdout.txt' % name) self.failUnless(result == 0) def testBuildLibrary(self): program = util.source(''' class LibraryClass: def SayHi(): print 'Hi!' ''') util.buildProgram('build_library_test.dll', program) self.assertTrue(os.path.exists('bin/build_library_test.dll'))