Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support jumps in Python 3.10+ #3

Closed
Svenskithesource opened this issue Aug 21, 2022 · 0 comments · Fixed by #6
Closed

Support jumps in Python 3.10+ #3

Svenskithesource opened this issue Aug 21, 2022 · 0 comments · Fixed by #6
Labels
enhancement New feature or request

Comments

@Svenskithesource
Copy link
Owner

In Python 3.10+ the arguments for all jump opcodes were divided by 2. We need to handle that in the unpacker.
See the example below:

Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> def demo(num):
...     if num == 1:
...         print("equal")
...     else:
...         print("not equal")
...
>>> dis.dis(demo.__code__)
  2           0 LOAD_FAST                0 (num)
              2 LOAD_CONST               1 (1)
              4 COMPARE_OP               2 (==)
              6 POP_JUMP_IF_FALSE       10 (to 20)

  3           8 LOAD_GLOBAL              0 (print)
             10 LOAD_CONST               2 ('equal')
             12 CALL_FUNCTION            1
             14 POP_TOP
             16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

  5     >>   20 LOAD_GLOBAL              0 (print)
             22 LOAD_CONST               3 ('not equal')
             24 CALL_FUNCTION            1
             26 POP_TOP
             28 LOAD_CONST               0 (None)
             30 RETURN_VALUE
>>>

We can see that the argument for instruction at index 6 (POP_JUMP_IF_FALSE) has argument 10. dis shows us it's actually pointing to index 20.

@Svenskithesource Svenskithesource added the enhancement New feature or request label Aug 21, 2022
@Svenskithesource Svenskithesource linked a pull request Aug 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant