mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #19722: Added opcode.stack_effect(), which accurately
computes the stack effect of bytecode instructions.
This commit is contained in:
parent
8d0d369067
commit
3a9079742f
8 changed files with 177 additions and 8 deletions
22
Lib/test/test__opcode.py
Normal file
22
Lib/test/test__opcode.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import dis
|
||||
import _opcode
|
||||
from test.support import run_unittest
|
||||
import unittest
|
||||
|
||||
class OpcodeTests(unittest.TestCase):
|
||||
|
||||
def test_stack_effect(self):
|
||||
self.assertEqual(_opcode.stack_effect(dis.opmap['POP_TOP']), -1)
|
||||
self.assertEqual(_opcode.stack_effect(dis.opmap['DUP_TOP_TWO']), 2)
|
||||
self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 0), -1)
|
||||
self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 1), -1)
|
||||
self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 3), -2)
|
||||
self.assertRaises(ValueError, _opcode.stack_effect, 30000)
|
||||
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE'])
|
||||
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0)
|
||||
|
||||
def test_main():
|
||||
run_unittest(OpcodeTests)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
Loading…
Add table
Add a link
Reference in a new issue