fixed stack op depth for getfield
This commit is contained in:
parent
98735fd6ba
commit
946a1f374c
@ -279,14 +279,14 @@ operationStackCost constants (Opiload _) = 1
|
|||||||
operationStackCost constants (Opastore _) = -1
|
operationStackCost constants (Opastore _) = -1
|
||||||
operationStackCost constants (Opistore _) = -1
|
operationStackCost constants (Opistore _) = -1
|
||||||
operationStackCost constants (Opputfield _) = -2
|
operationStackCost constants (Opputfield _) = -2
|
||||||
operationStackCost constants (Opgetfield _) = -1
|
operationStackCost constants (Opgetfield _) = 0
|
||||||
|
|
||||||
simulateStackOperation :: [ConstantInfo] -> Operation -> (Int, Int) -> (Int, Int)
|
simulateStackOperation :: (Int, Int) -> [ConstantInfo] -> Operation -> (Int, Int)
|
||||||
simulateStackOperation constants op (cd, md) = let
|
simulateStackOperation (cd, md) constants op = let
|
||||||
depth = cd + operationStackCost constants op
|
depth = cd + operationStackCost constants op
|
||||||
in if depth < 0
|
in if depth < 0
|
||||||
then error ("Consuming value off of empty stack: " ++ show op)
|
then error ("Consuming value off of empty stack: " ++ show op)
|
||||||
else (depth, max depth md)
|
else (depth, max depth md)
|
||||||
|
|
||||||
maxStackDepth :: [ConstantInfo] -> [Operation] -> Int
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user