module Main where import Example import Typecheck import Parser.Lexer (alexScanTokens) import Parser.JavaParser import ByteCode.Builder import ByteCode.ClassFile import Data.ByteString (pack, writeFile) import System.Environment import System.FilePath.Posix (takeDirectory) main = do args <- getArgs let filename = if null args then error "Missing filename, I need to know what to compile" else args!!0 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