add: Classbuilder & ClassFileBuilder

This commit is contained in:
Christian Brier 2024-05-07 11:54:54 +02:00
parent f988c80b83
commit c920a3dfb6
2 changed files with 24 additions and 14 deletions

View File

@ -1,31 +1,38 @@
module ByteCode.ClassFile.Generator(
fromAST
classBuilder
) where
import ByteCode.Constants
import ByteCode.ClassFile (ClassFile (..), ConstantInfo (..))
import Ast
import ByteCode.Operations
baseConstants = [
ClassInfo 4,
MethodRefInfo 1 3,
NameAndTypeInfo 5 6,
Utf8Info "java/lang/Object",
Utf8Info "<init>",
Utf8Info "()V"
]
type ClassFileBuilder a = ClassFile -> a -> ClassFile
fromAST :: Class -> ClassFile
fromAST (Class name methods fields) = let
classBuilder :: ClassFileBuilder Class
classBuilder _ (Class name methods fields) = let
baseConstants = [
ClassInfo 4,
MethodRefInfo 1 3,
NameAndTypeInfo 5 6,
Utf8Info "java/lang/Object",
Utf8Info "<init>",
Utf8Info "()V"
]
nameConstants = [ClassInfo 8, Utf8Info name]
in
ClassFile {
constantPool = baseConstants,
constantPool = baseConstants ++ nameConstants,
accessFlags = accessPublic,
thisClass = 1,
thisClass = 7,
superClass = 1,
fields = [],
methods = [],
attributes = []
}
}

View File

@ -0,0 +1,3 @@
module ByteCode.Operations where
data Operation = Iadd
-- |