Skip to content

Commit

Permalink
aload is zero indexed you dunce
Browse files Browse the repository at this point in the history
bristermitten committed Dec 5, 2023
1 parent 3f8224a commit 34d4071
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/JVM/Data/Analyse/StackMap.hs
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 34d4071

Please sign in to comment.