bytecode #7

Merged
mrab merged 11 commits from bytecode into master 2024-06-26 15:13:23 +00:00
Showing only changes of commit 946a1f374c - Show all commits

View File

@ -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