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

View File

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