add: Classbuilder & ClassFileBuilder
This commit is contained in:
parent
f988c80b83
commit
c920a3dfb6
@ -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 = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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