From 34d4071c0f470b68a42336126e2660a9df117a92 Mon Sep 17 00:00:00 2001 From: Alexander Wood Date: Tue, 5 Dec 2023 22:38:38 +0000 Subject: [PATCH] aload is zero indexed you dunce --- src/JVM/Data/Analyse/StackMap.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/JVM/Data/Analyse/StackMap.hs b/src/JVM/Data/Analyse/StackMap.hs index f5ff201..bf33621 100644 --- a/src/JVM/Data/Analyse/StackMap.hs +++ b/src/JVM/Data/Analyse/StackMap.hs @@ -79,13 +79,13 @@ analyseBlockDiff current block = foldl' (flip analyseInstruction) current (takeW analyseInstruction :: Instruction -> Frame -> Frame analyseInstruction (Label _) ba = error "Label should not be encountered in analyseInstruction" analyseInstruction (ALoad i) ba = - if i - 1 > genericLength ba.locals + if i > genericLength ba.locals then error $ "ALoad index out of bounds. Given: " <> show i <> " Locals: " <> show ba.locals - else ba{stack = lvToStackEntry (ba.locals !! fromIntegral (i - 1)) : ba.stack} + else ba{stack = lvToStackEntry (ba.locals !! fromIntegral i) : ba.stack} analyseInstruction (ILoad i) ba = - if i - 1 > genericLength ba.locals + if i > genericLength ba.locals then error $ "ILoad index out of bounds. Given: " <> show i <> " Locals: " <> show ba.locals - else ba{stack = lvToStackEntry (ba.locals !! fromIntegral (i - 1)) : ba.stack} + else ba{stack = lvToStackEntry (ba.locals !! fromIntegral i) : ba.stack} analyseInstruction (AStore i) ba = ba{locals = replaceAtOrGrow (fromIntegral (i - 1)) (stackEntryToLV $ head ba.stack) ba.locals, stack = tail ba.stack} analyseInstruction (IStore i) ba = ba{locals = replaceAtOrGrow (fromIntegral (i - 1)) (stackEntryToLV $ head ba.stack) ba.locals, stack = tail ba.stack} analyseInstruction AReturn ba = ba{stack = tail ba.stack}