working export of binary class files
This commit is contained in:
parent
967c3a4b41
commit
f93a1ba58c
@ -16,7 +16,7 @@ executable compiler
|
|||||||
src/ByteCode,
|
src/ByteCode,
|
||||||
src/ByteCode/ClassFile
|
src/ByteCode/ClassFile
|
||||||
build-tool-depends: alex:alex, happy:happy
|
build-tool-depends: alex:alex, happy:happy
|
||||||
other-modules: Parser.Lexer, Ast, Parser.JavaParser, ByteCode.ByteUtil, ByteCode.ClassFile, ByteCode.ClassFile.Generator
|
other-modules: Parser.Lexer, Ast, Parser.JavaParser, ByteCode.ByteUtil, ByteCode.ClassFile, ByteCode.ClassFile.Generator, ByteCode.Constants
|
||||||
|
|
||||||
test-suite tests
|
test-suite tests
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
module ByteCode.ClassFile where
|
module ByteCode.ClassFile(
|
||||||
|
ConstantInfo(..),
|
||||||
|
Attribute(..),
|
||||||
|
MemberInfo(..),
|
||||||
|
ClassFile(..),
|
||||||
|
serialize
|
||||||
|
) where
|
||||||
|
|
||||||
import Data.Word
|
import Data.Word
|
||||||
import Data.Int
|
import Data.Int
|
||||||
import Data.ByteString (unpack)
|
import Data.ByteString (unpack)
|
||||||
import Data.ByteString.UTF8 (fromString)
|
import Data.ByteString.UTF8 (fromString)
|
||||||
import ByteCode.ByteUtil
|
import ByteCode.ByteUtil
|
||||||
|
import ByteCode.Constants
|
||||||
tagClass = 0x07
|
|
||||||
tagFieldref = 0x09
|
|
||||||
tagMethodref = 0x0A
|
|
||||||
tagNameandtype = 0x0C
|
|
||||||
tagInteger = 0x03
|
|
||||||
tagUtf8 = 0x01
|
|
||||||
|
|
||||||
accessPublic = 0x01
|
|
||||||
accessPrivate = 0x02
|
|
||||||
accessProtected = 0x04
|
|
||||||
|
|
||||||
data ConstantInfo = ClassInfo Word16
|
data ConstantInfo = ClassInfo Word16
|
||||||
| FieldRefInfo Word16 Word16
|
| FieldRefInfo Word16 Word16
|
||||||
|
@ -1 +1,31 @@
|
|||||||
module ByteCode.ClassFile.Generator where
|
module ByteCode.ClassFile.Generator(
|
||||||
|
fromAST
|
||||||
|
) where
|
||||||
|
|
||||||
|
import ByteCode.Constants
|
||||||
|
import ByteCode.ClassFile (ClassFile (..), ConstantInfo (..))
|
||||||
|
import Ast
|
||||||
|
|
||||||
|
|
||||||
|
baseConstants = [
|
||||||
|
ClassInfo 4,
|
||||||
|
MethodRefInfo 1 3,
|
||||||
|
NameAndTypeInfo 5 6,
|
||||||
|
Utf8Info "java/lang/Object",
|
||||||
|
Utf8Info "<init>",
|
||||||
|
Utf8Info "()V"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
fromAST :: Class -> ClassFile
|
||||||
|
fromAST (Class name methods fields) = let
|
||||||
|
in
|
||||||
|
ClassFile {
|
||||||
|
constantPool = baseConstants,
|
||||||
|
accessFlags = accessPublic,
|
||||||
|
thisClass = 1,
|
||||||
|
superClass = 1,
|
||||||
|
fields = [],
|
||||||
|
methods = [],
|
||||||
|
attributes = []
|
||||||
|
}
|
25
src/ByteCode/Constants.hs
Normal file
25
src/ByteCode/Constants.hs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
module ByteCode.Constants where
|
||||||
|
import Data.Word
|
||||||
|
|
||||||
|
|
||||||
|
tagClass :: Word8
|
||||||
|
tagFieldref :: Word8
|
||||||
|
tagMethodref :: Word8
|
||||||
|
tagNameandtype :: Word8
|
||||||
|
tagInteger :: Word8
|
||||||
|
tagUtf8 :: Word8
|
||||||
|
|
||||||
|
accessPublic :: Word16
|
||||||
|
accessPrivate :: Word16
|
||||||
|
accessProtected :: Word16
|
||||||
|
|
||||||
|
tagClass = 0x07
|
||||||
|
tagFieldref = 0x09
|
||||||
|
tagMethodref = 0x0A
|
||||||
|
tagNameandtype = 0x0C
|
||||||
|
tagInteger = 0x03
|
||||||
|
tagUtf8 = 0x01
|
||||||
|
|
||||||
|
accessPublic = 0x01
|
||||||
|
accessPrivate = 0x02
|
||||||
|
accessProtected = 0x04
|
Loading…
Reference in New Issue
Block a user