diff --git a/src/ByteCode/Util.hs b/src/ByteCode/Util.hs index f177342..7f48b17 100644 --- a/src/ByteCode/Util.hs +++ b/src/ByteCode/Util.hs @@ -279,14 +279,14 @@ operationStackCost constants (Opiload _) = 1 operationStackCost constants (Opastore _) = -1 operationStackCost constants (Opistore _) = -1 operationStackCost constants (Opputfield _) = -2 -operationStackCost constants (Opgetfield _) = -1 +operationStackCost constants (Opgetfield _) = 0 -simulateStackOperation :: [ConstantInfo] -> Operation -> (Int, Int) -> (Int, Int) -simulateStackOperation constants op (cd, md) = let +simulateStackOperation :: (Int, Int) -> [ConstantInfo] -> Operation -> (Int, Int) +simulateStackOperation (cd, md) constants op = let depth = cd + operationStackCost constants op in if depth < 0 then error ("Consuming value off of empty stack: " ++ show op) else (depth, max depth md) maxStackDepth :: [ConstantInfo] -> [Operation] -> Int -maxStackDepth constants ops = snd $ foldr (simulateStackOperation constants) (0, 0) (reverse ops) +maxStackDepth constants ops = snd $ foldl (`simulateStackOperation` constants) (0, 0) ops