<commit_before>module Main where


import Control.Monad
import System.Environment
import System.Exit (exitFailure)
import System.Directory (doesFileExist)
import System.Cmd (rawSystem)

import L1_64.ParL1
import L1_64.ErrM

import L1Tox64.Compile

main :: IO ()
main = do
    args <- getArgs
    when (length args /= 1) $ do
        putStrLn "usage: filename"
        exitFailure
    runtimeOExists <- doesFileExist "runtime.o"
    unless runtimeOExists $ putStrLn "No runtime.o. Exiting." >> exitFailure
    contents <- readFile (head args)
    let ts = myLexer contents
    case pProgram ts of
      Bad s   -> do putStrLn "\nParse              Failed...\n"
                    putStrLn "Tokens:"
                    print ts
                    putStrLn s
      Ok tree -> do writeFile "prog.S" (generateAssembly tree)
                    rawSystem "as" ["--64", "-o", "prog.o", "prog.S"]
                    rawSystem "gcc" ["-m64", "-o", "a.out", "prog.o", "runtime.o"]
                    return ()

<commit_msg>Abort compilation if a system command fails<commit_after>module Main where


import Control.Monad
import System.Environment
import System.Cmd
import System.Exit
import System.Directory

import L1_64.ParL1
import L1_64.ErrM

import L1Tox64.Compile

main :: IO ()
main = do
    args <- getArgs
    when (length args /= 1) $ do
        putStrLn "usage: filename"
        exitFailure
    runtimeOExists <- doesFileExist "runtime.o"
    unless runtimeOExists $ putStrLn "No runtime.o. Exiting." >> exitFailure
    contents <- readFile (head args)
    let ts = myLexer contents
    case pProgram ts of
      Bad s   -> do putStrLn "\nParse              Failed...\n"
                    putStrLn "Tokens:"
                    print ts
                    putStrLn s
      Ok tree -> do writeFile "prog.S" (generateAssembly tree)
                    rawSystem "as" ["--64", "-o", "prog.o", "prog.S"] >>= throwIfError
                    rawSystem "gcc" ["-m64", "-o", "a.out", "prog.o", "runtime.o"] >>= throwIfError
                    return ()

throwIfError :: ExitCode -> IO ()
throwIfError ExitSuccess = return ()
throwIfError e@ExitFailure{} = exitWith e >> return ()

{'fraction_non_alphanumeric': 0.11217948717948718, 'fraction_numerical': 0.013736263736263736, 'mean_word_length': 2.1125356125356127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1506017', 'n_tokens_mistral': 703, 'n_tokens_neox': 652, 'n_words': 200}