Use Data.Map.Map instead of Data.Array.Array for constants pool.
[hs-java.git] / JVM / ClassFile.hs
index ef4916cfc4f5f14e12b909bc59eb0d6257a25d54..e9b1377cdd5855c84cb7cf998ebf81bb5a95b819 100644 (file)
@@ -7,8 +7,9 @@ module JVM.ClassFile
    FieldInfo (..),
    MethodInfo (..),
    AttributeInfo (..),
-   FieldType,
-   FieldSignature, MethodSignature (..), ReturnSignature (..)
+   FieldType (..),
+   FieldSignature, MethodSignature (..), ReturnSignature (..),
+   ArgumentSignature (..)
   )
   where
 
@@ -84,7 +85,7 @@ instance Binary ClassFile where
     classMethodsCount <- get
     classMethods <- replicateM (fromIntegral classMethodsCount) get
     asCount <- get
-    as <- replicateM (fromIntegral $ asCount - 1) get
+    as <- replicateM (fromIntegral $ asCount) get
     return $ ClassFile magic minor major poolsize pool af this super
                interfacesCount ifaces classFieldsCount classFields classMethodsCount classMethods asCount as
 
@@ -98,8 +99,8 @@ data FieldType =
   | LongInt    -- ^ J
   | ShortInt   -- ^ S
   | BoolType   -- ^ Z
-  | ObjectType String -- ^ L <class name>
-  | Array (Maybe Int) FieldType -- ^ [<type>
+  | ObjectType String -- ^ L @{class name}@
+  | Array (Maybe Int) FieldType -- ^ @[{type}@
   deriving (Eq)
 
 instance Show FieldType where
@@ -136,6 +137,9 @@ getInt = do
              return (c: next)
         else return []
 
+putString :: String -> Put
+putString str = forM_ str put
+
 instance Binary FieldType where
   put SignedByte = put 'B'
   put CharByte   = put 'C'
@@ -145,7 +149,7 @@ instance Binary FieldType where
   put LongInt    = put 'J'
   put ShortInt   = put 'S'
   put BoolType   = put 'Z'
-  put (ObjectType name) = put 'L' >> put name
+  put (ObjectType name) = put 'L' >> putString name >> put ';'
   put (Array Nothing sig) = put '[' >> put sig
   put (Array (Just n) sig) = put '[' >> put (show n) >> put sig
 
@@ -374,4 +378,3 @@ instance Binary AttributeInfo where
     value <- getLazyByteString (fromIntegral len)
     return $ AttributeInfo name len value
 
-