2024-05-01 19:07:04 +00:00
|
|
|
module Main where
|
|
|
|
|
2024-05-06 21:15:22 +00:00
|
|
|
import Example
|
2024-05-07 07:53:16 +00:00
|
|
|
import Typecheck
|
2024-05-08 13:23:18 +00:00
|
|
|
import Parser.Lexer (alexScanTokens)
|
|
|
|
import Parser.JavaParser
|
2024-06-14 06:52:06 +00:00
|
|
|
import ByteCode.Builder
|
2024-05-08 13:23:18 +00:00
|
|
|
import ByteCode.ClassFile
|
|
|
|
import Data.ByteString (pack, writeFile)
|
2024-06-14 05:57:38 +00:00
|
|
|
import System.Environment
|
|
|
|
import System.FilePath.Posix (takeDirectory)
|
2024-05-01 19:07:04 +00:00
|
|
|
|
|
|
|
main = do
|
2024-06-14 05:57:38 +00:00
|
|
|
args <- getArgs
|
2024-06-14 06:52:06 +00:00
|
|
|
let filename = if null args
|
|
|
|
then error "Missing filename, I need to know what to compile"
|
|
|
|
else args!!0
|
2024-06-14 05:57:38 +00:00
|
|
|
let outputDirectory = takeDirectory filename
|
|
|
|
print ("Compiling " ++ filename)
|
|
|
|
file <- readFile filename
|
2024-05-14 11:20:37 +00:00
|
|
|
|
|
|
|
let untypedAST = parse $ alexScanTokens file
|
2024-06-13 20:25:35 +00:00
|
|
|
let typedAST = (typeCheckCompilationUnit untypedAST)
|
|
|
|
let assembledClasses = map (\(typedClass) -> classBuilder typedClass emptyClassFile) typedAST
|
2024-05-08 13:23:18 +00:00
|
|
|
|
2024-06-13 20:25:35 +00:00
|
|
|
mapM_ (\(classFile) -> let
|
|
|
|
fileContent = pack (serialize classFile)
|
2024-06-14 05:57:38 +00:00
|
|
|
fileName = outputDirectory ++ "/" ++ (className classFile) ++ ".class"
|
2024-06-13 20:25:35 +00:00
|
|
|
in Data.ByteString.writeFile fileName fileContent
|
|
|
|
) assembledClasses
|
|
|
|
|
|
|
|
|
|
|
|
|