projects
/
hs-java.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More docs.
[hs-java.git]
/
JVM
/
Assembler.hs
diff --git
a/JVM/Assembler.hs
b/JVM/Assembler.hs
index 31e00fea6ff1678c86bed9e76ef8cd10d7c962a3..7ac59c64a0915734a64e55f261d51ac32e9f95bf 100644
(file)
--- a/
JVM/Assembler.hs
+++ b/
JVM/Assembler.hs
@@
-10,6
+10,7
@@
module JVM.Assembler
Code (..),
IMM (..),
CMP (..),
Code (..),
IMM (..),
CMP (..),
+ atype2byte,
encodeInstructions,
encodeMethod,
decodeMethod
encodeInstructions,
encodeMethod,
decodeMethod
@@
-53,7
+54,7
@@
data Code = Code {
codeExceptionsN :: Word16,
codeExceptions :: [CodeException],
codeAttrsN :: Word16,
codeExceptionsN :: Word16,
codeExceptions :: [CodeException],
codeAttrsN :: Word16,
- codeAttributes ::
[AttributeInfo]
}
+ codeAttributes ::
Attributes File
}
deriving (Eq, Show)
-- | Exception descriptor
deriving (Eq, Show)
-- | Exception descriptor
@@
-73,7
+74,7
@@
instance BinaryState Integer CodeException where
get = CodeException <$> get <*> get <*> get <*> get
get = CodeException <$> get <*> get <*> get <*> get
-instance BinaryState Integer Attribute
Info
where
+instance BinaryState Integer Attribute where
put a = do
let sz = 6 + attributeLength a -- full size of AttributeInfo structure
liftOffset (fromIntegral sz) Binary.put a
put a = do
let sz = 6 + attributeLength a -- full size of AttributeInfo structure
liftOffset (fromIntegral sz) Binary.put a
@@
-89,7
+90,7
@@
instance BinaryState Integer Code where
put codeExceptionsN
forM_ codeExceptions put
put codeAttrsN
put codeExceptionsN
forM_ codeExceptions put
put codeAttrsN
- forM_
codeAttributes
put
+ forM_
(attributesList codeAttributes)
put
get = do
stackSz <- get
get = do
stackSz <- get
@@
-102,7
+103,7
@@
instance BinaryState Integer Code where
excs <- replicateM (fromIntegral excn) get
nAttrs <- get
attrs <- replicateM (fromIntegral nAttrs) get
excs <- replicateM (fromIntegral excn) get
nAttrs <- get
attrs <- replicateM (fromIntegral nAttrs) get
- return $ Code stackSz locals len code excn excs nAttrs
attrs
+ return $ Code stackSz locals len code excn excs nAttrs
(AP attrs)
-- | Read sequence of instructions (to end of stream)
readInstructions :: GetState Integer [Instruction]
-- | Read sequence of instructions (to end of stream)
readInstructions :: GetState Integer [Instruction]
@@
-115,7
+116,7
@@
readInstructions = do
next <- readInstructions
return (x: next)
next <- readInstructions
return (x: next)
--- | JVM instruction set
+-- | JVM instruction set
. For comments, see JVM specification.
data Instruction =
NOP -- ^ 0
| ACONST_NULL -- ^ 1
data Instruction =
NOP -- ^ 0
| ACONST_NULL -- ^ 1
@@
-707,6
+708,7
@@
instance BinaryState Integer Instruction where
| inRange (159, 164) c -> IF_ICMP (toEnum $ fromIntegral $ c-159) <$> get
| otherwise -> fail $ "Unknown instruction byte code: " ++ show c
| inRange (159, 164) c -> IF_ICMP (toEnum $ fromIntegral $ c-159) <$> get
| otherwise -> fail $ "Unknown instruction byte code: " ++ show c
+-- | Encode list of instructions
encodeInstructions :: [Instruction] -> B.ByteString
encodeInstructions code =
let p list = forM_ list put
encodeInstructions :: [Instruction] -> B.ByteString
encodeInstructions code =
let p list = forM_ list put