asm: `goto' has an word16 immediate
[hs-java.git] / JVM / Assembler.hs
index db036dba44b9ee629b5ec9fee98d051a07dabd9f..10bfd174489c75dd2719ee0ec43c833dfbd47870 100644 (file)
@@ -54,7 +54,7 @@ data Code = Code {
     codeExceptionsN :: Word16,
     codeExceptions :: [CodeException],
     codeAttrsN :: Word16,
-    codeAttributes :: Attributes Pointers }
+    codeAttributes :: Attributes File }
   deriving (Eq, Show)
 
 -- | Exception descriptor
@@ -116,7 +116,7 @@ readInstructions = do
           next <- readInstructions
           return (x: next)
 
--- | JVM instruction set
+-- | JVM instruction set. For comments, see JVM specification.
 data Instruction =
     NOP            -- ^ 0
   | ACONST_NULL    -- ^ 1
@@ -242,7 +242,7 @@ data Instruction =
   | IF CMP                 -- ^ 153, 154, 155, 156, 157, 158
   | IF_ICMP CMP Word16     -- ^ 159, 160, 161, 162, 163, 164
   | IF_ACMP CMP Word16     -- ^ 165, 166
-  | GOTO                   -- ^ 167
+  | GOTO Word16            -- ^ 167
   | JSR Word16             -- ^ 168
   | RET                    -- ^ 169
   | TABLESWITCH Word32 Word32 Word32 [Word32]     -- ^ 170
@@ -480,7 +480,7 @@ instance BinaryState Integer Instruction where
   put (IF_ACMP C_NE x) = put1 166 x
   put (IF_ACMP c _)   = fail $ "No such instruction: IF_ACMP " ++ show c
   put (IF_ICMP c x)   = putByte (fromIntegral $ 159 + fromEnum c) >> put x
-  put  GOTO           = putByte 167
+  put (GOTO x)        = put1 167 x
   put (JSR x)         = put1 168 x
   put  RET            = putByte 169
   put (TABLESWITCH def low high offs) = do
@@ -646,7 +646,7 @@ instance BinaryState Integer Instruction where
       152 -> return $ DCMP C_GT
       165 -> IF_ACMP C_EQ <$> get
       166 -> IF_ACMP C_NE <$> get
-      167 -> return GOTO
+      167 -> GOTO <$> get
       168 -> JSR <$> get
       169 -> return RET
       170 -> do
@@ -708,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
 
+-- | Encode list of instructions
 encodeInstructions :: [Instruction] -> B.ByteString
 encodeInstructions code =
   let p list = forM_ list put