MiniJavaCompiler/src/Main.hs

31 lines
832 B
Haskell
Raw Normal View History

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-12 14:55:19 +00:00
import ByteCode.Generator
2024-05-08 13:23:18 +00:00
import ByteCode.ClassFile
import Data.ByteString (pack, writeFile)
2024-05-01 19:07:04 +00:00
main = do
-- read source code from disk
2024-05-14 11:20:37 +00:00
file <- readFile "Testklasse.java"
-- parse source code
2024-05-14 11:20:37 +00:00
let untypedAST = parse $ alexScanTokens file
-- typecheck AST
let typedAST = (typeCheckCompilationUnit untypedAST)
-- assemble classes
let assembledClasses = map (\(typedClass) -> classBuilder typedClass emptyClassFile) typedAST
2024-05-08 13:23:18 +00:00
-- write class files to disk
mapM_ (\(classFile) -> let
fileContent = pack (serialize classFile)
fileName = (className classFile) ++ ".class"
in Data.ByteString.writeFile fileName fileContent
) assembledClasses