def extendedTestToken(): import time tic = time.clock() a = './tests/test_code0/Extras_(Non_Project)/BeerTanks' b = './tests/test_code0/Extras_(Non_Project)/Binge' c = './tests/test_code0/Extras_(Non_Project)/Darts' d = './tests/test_code0/Extras_(Non_Project)/hangman' e = './tests/test_code0/Extras_(Non_Project)/LePacMan' f = './tests/test_code0/Extras_(Non_Project)/LunarLander2' g = './tests/test_code0/Extras_(Non_Project)/Maze' h = './tests/test_code0/Extras_(Non_Project)/Maze3d' i = './tests/test_code0/Extras_(Non_Project)/Pong' j = './tests/test_code0/Extras_(Non_Project)/Schizophrenia' k = './tests/test_code0/Extras_(Non_Project)/ShapeSwap' l = './tests/test_code0/Extras_(Non_Project)/Simon' m = './tests/test_code0/Extras_(Non_Project)/SlotMachineGame' n = './tests/test_code0/Extras_(Non_Project)/SnakeLike' o0 = './tests/test_code0/Extras_(Non_Project)/SpaceInvaders' # p = './tests/test_code0/Extras_(Non_Project)/TicJackToe\src' q = './tests/test_code0/Extras_(Non_Project)/WormsRock2' # testpaths = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o0, p, q] testpaths = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o0, q] filelist = [] for path in testpaths: filelist_ = main.fileOrPathParser(path) filelist = filelist + filelist_ for filename in filelist: main.mainloop(filename, outputMode='tokens') toc = time.clock() print('===========================================================') print("%s files tokenized. Tokenizing took %s seconds." % (len(filelist), (toc - tic)))
def main(): """ JackCC. Takes a Jack language file or files as input and outputs VM intermediary code, Hack Assembly code, or Hack machine code (the default). Command line flags will change the nature of our STDOUT and STDERR messages, what we're outputting, the name of our output file, etc. """ args = defineCLIParser() # define our CLI flags, etc compilerInput, tmpDir, vmInput, vmFilename, vmOutDir, asmInput,\ asmFilename, asmOutDir, finalOutputFile, finalOutputDir = setOutputVaribles(args) # /\ set up all the variables we'll need to compiler output try: # Our compiler (i.e. Jack to VM) is the only stage we should really # expect to fail, as lexical, parse, and semantic errors will halt # compilation. This makes sure execution halts gracefully, instead of # issuing a massive stack trace compiler.mainloop(compilerInput, customOutDir=tmpDir, vmfinaloutput=args.verbose, \ warnings=not(args.mutewarn)) except (CompilerError) as E: print('\n' + str(E)[1:-1]) MUTE(args) # User probably doesn't care we're deleting cleanUp(tmpDir) # temp files--hence the MUTE/UNMUTE UNMUTE(args) # . print('\nCompilation unsuccessful. Compilation halted.') exit(1) # Our other modules /shouldn't/ crash, because we're assuming our compiler # stage is outputting correct VM code, our VM is outputting correct Hack # Assembly, etc. MUTE( args ) # If verbose output flag is set (args.verbose=True), this will do nothing VM.vmtoassembly(vmInput, outputFile=vmFilename, customOutDir=vmOutDir) assembler.assembler(asmInput, asmFilename, asmOutDir) cleanUp(tmpDir) UNMUTE( args ) # if verbose output flag is set (args.verbose=True), this will do nothing if args.assembly or args.hack: print('Output: {}'.format( os.path.join(finalOutputDir, os.path.basename(finalOutputFile))))
def testLexer():# unit test for tokenizer import subprocess a = './tests/test_code0/ArrayTest' b = './tests/test_code0/ExpressionlessSquare' c = './tests/test_code0/Square' testpaths = [a, b, c] filelist = [] for path in testpaths: # filelist_, path = main.fileOrPathParser(path) filelist_ = main.fileOrPathParser(path) filelist = filelist + filelist_ for filename in filelist: main.mainloop(filename, outputMode='tokens') print('===========================================================') print('Diff results will appear, below each file. If none appear, everything worked.') # batch = './tests/tokentestscript.bat' # Windows test script batch = './tests/tokentestscript.bash' # Windows test script subprocess.call(batch)
def extendedTestParse(): """ Tests the output of the parser (and only the parser), by diff-ing output from other people's files/parser with the output of our parser. Diff is folder-by-folder, file-by-file, and should output nothing (i.e. compared files should be identical) """ import subprocess import time tic = time.clock() a = './tests/test_code0/Extras_(Non_Project)/BeerTanks' b = './tests/test_code0/Extras_(Non_Project)/Binge' c = './tests/test_code0/Extras_(Non_Project)/Darts' d = './tests/test_code0/Extras_(Non_Project)/hangman' e = './tests/test_code0/Extras_(Non_Project)/LePacMan' f = './tests/test_code0/Extras_(Non_Project)/LunarLander2' g = './tests/test_code0/Extras_(Non_Project)/Maze' h = './tests/test_code0/Extras_(Non_Project)/Maze3d' i = './tests/test_code0/Extras_(Non_Project)/Pong' j = './tests/test_code0/Extras_(Non_Project)/Schizophrenia' k = './tests/test_code0/Extras_(Non_Project)/ShapeSwap' l = './tests/test_code0/Extras_(Non_Project)/Simon' m = './tests/test_code0/Extras_(Non_Project)/SlotMachineGame' n = './tests/test_code0/Extras_(Non_Project)/SnakeLike' o = './tests/test_code0/Extras_(Non_Project)/SpaceInvaders' # p = './tests/test_code0/Extras_(Non_Project)/TicJackToe/src' q = './tests/test_code0/Extras_(Non_Project)/WormsRock2' # testpaths = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q] testpaths = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, q] filelist = [] for path in testpaths: filelist_ = main.fileOrPathParser(path) filelist = filelist + filelist_ for filename in filelist: main.mainloop(filename, outputMode='parseTree') toc = time.clock() print("%s files compiled. Compilation took %s seconds.\n" % (len(filelist), (toc - tic))) print('Diff results between our files and reference files:\n') batch = './tests/parsetestscriptextended.bash' # print('Check shell window to see if the the files match the tests.') # batch = './tests/parsetestscriptextended.bat' # Windows test script subprocess.call(batch) print('\nCheck `diff\' results, above. Files should be identical.')
def currentBookTest(): """ Tests the most "difficult"-to-compile book projects. If it finishes without error, the compiler's (ostensibly) successfully outputted the proper .vm files """ import time tic = time.clock() a = './tests/test_code1/Average' b = './tests/test_code1/ComplexArrays' c = './tests/test_code1/ConvertToBin' d = './tests/test_code1/Pong' e = './tests/test_code1/Seven' f = './tests/test_code1/Square' testpaths = [a, b, c, d, e, f] for path in testpaths: main.mainloop(path) toc = time.clock() print('===========================================================') print("Compilation took %s seconds." % (toc - tic))
def currentTest(): """ This is the default test suite. It sees whether book projects AND a ton of classroom projects (which I've not re-found the link to, yet) will compile. If it successfully compiles every file, tokenization and parsing have (ostensibly) worked, as has code output. Warnings are normal, as the compiler is over-zealous. If it freezes, it's (probably) because something's wrong with the compiler. """ import time tic = time.clock() a = './tests/test_code0/ArrayTest' # b = './tests/test_code0/ExpressionlessSquare' c = './tests/test_code0/Square' a1 = './tests/test_code0/Extras_(Non_Project)/BeerTanks' b1 = './tests/test_code0/Extras_(Non_Project)/Binge' c1 = './tests/test_code0/Extras_(Non_Project)/Darts' d = './tests/test_code0/Extras_(Non_Project)/hangman' e = './tests/test_code0/Extras_(Non_Project)/LePacMan' f = './tests/test_code0/Extras_(Non_Project)/LunarLander2' g = './tests/test_code0/Extras_(Non_Project)/Maze' h = './tests/test_code0/Extras_(Non_Project)/Maze3d' i = './tests/test_code0/Extras_(Non_Project)/Pong' j = './tests/test_code0/Extras_(Non_Project)/Schizophrenia' k = './tests/test_code0/Extras_(Non_Project)/ShapeSwap' l = './tests/test_code0/Extras_(Non_Project)/Simon' m = './tests/test_code0/Extras_(Non_Project)/SlotMachineGame' n = './tests/test_code0/Extras_(Non_Project)/SnakeLike' o = './tests/test_code0/Extras_(Non_Project)/SpaceInvaders' # p = './tests/test_code0/Extras_(Non_Project)/TicJackToe/src' # /\ won't work because it contains escaped characters (e.g. \" to represent a quote), which is # outside the language spec q = './tests/test_code0/Extras_(Non_Project)/WormsRock2' testpaths = [a, c, a1, b1, c1, d, e, f, g, h, i, j, k, l, m, n, o, q] # testpaths = [a, b, c, a1, b1, c1, d, e, f, g, h, i, j, k, l, m, n, o, q] for path in testpaths: main.mainloop(path) toc = time.clock() print('===========================================================') print("Compilation took %s seconds." % (toc - tic))