add: Classbuilder & ClassFileBuilder
This commit is contained in:
parent
f988c80b83
commit
c920a3dfb6
@ -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 = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
3
src/ByteCode/Operations.hs
Normal file
3
src/ByteCode/Operations.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module ByteCode.Operations where
|
||||
data Operation = Iadd
|
||||
-- |
|
Loading…
Reference in New Issue
Block a user