module Main where import Example import Typecheck import Parser.Lexer (alexScanTokens) import Parser.JavaParser import ByteCode.Generator import ByteCode.ClassFile import Data.ByteString (pack, writeFile) import System.Environment import System.FilePath.Posix (takeDirectory) main = do args <- getArgs let filename = if (length args) > 0 then args!!0 else error "Missing filename, I need to know what to compile" let outputDirectory = takeDirectory filename print ("Compiling " ++ filename) file <- readFile filename let untypedAST = parse $ alexScanTokens file let typedAST = (typeCheckCompilationUnit untypedAST) let assembledClasses = map (\(typedClass) -> classBuilder typedClass emptyClassFile) typedAST mapM_ (\(classFile) -> let fileContent = pack (serialize classFile) fileName = outputDirectory ++ "/" ++ (className classFile) ++ ".class" in Data.ByteString.writeFile fileName fileContent ) assembledClasses