Skip to content

Add support for dis module #367

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

Closed
cthulahoops opened this issue Feb 6, 2019 · 4 comments
Closed

Add support for dis module #367

cthulahoops opened this issue Feb 6, 2019 · 4 comments
Labels
A-design About RustPython's own implementation

Comments

@cthulahoops
Copy link
Collaborator

Lack of this makes compiler debugging more painful than it should be.

Will need us to make the code object work fully.

@cthulahoops cthulahoops self-assigned this Feb 6, 2019
@ksunden
Copy link

ksunden commented Mar 6, 2019

dis module is pure python and appears to work, at least as far as my simple test goes

>>>>> def fib(a):
.....     return a if a < 2 else fib(a-1) + fib(a-2)
>>>>> for i in range(10):
.....    print(fib(i))
0
1
1
2
3
5
8
13
21
34
>>>>> dis.dis(fib)
                 0 LoadName             (a)
                 1 LoadConst            (2)
                 2 CompareOperation     (Less)
                 3 Duplicate
                 4 JumpIfFalse          (8)
                 5 Pop
                 6 LoadName             (a)
                 7 Jump                 (19)
          >>     8 LoadName             (fib)
                 9 LoadName             (a)
                10 LoadConst            (1)
                11 BinaryOperation      (Subtract, false)
                12 CallFunction         (Positional(1))
                13 LoadName             (fib)
                14 LoadName             (a)
                15 LoadConst            (2)
                16 BinaryOperation      (Subtract, false)
                17 CallFunction         (Positional(1))
                18 BinaryOperation      (Add, false)
          >>    19 ReturnValue
                20 LoadConst            (None)
                21 ReturnValue

(I have PYTHONPATH=/usr/lib/python3.6/:/usr/lib/python3.6/site-packages, just my distro provided python 3.6 standard lib)

for comparison, though, here is the same function in CPython 3.6.8 (same dis module)

>>> dis.dis(fib)
  2           0 LOAD_FAST                0 (a)
              2 LOAD_CONST               1 (2)
              4 COMPARE_OP               0 (<)
              6 POP_JUMP_IF_FALSE       12
              8 LOAD_FAST                0 (a)
             10 RETURN_VALUE
        >>   12 LOAD_GLOBAL              0 (fib)
             14 LOAD_FAST                0 (a)
             16 LOAD_CONST               2 (1)
             18 BINARY_SUBTRACT
             20 CALL_FUNCTION            1
             22 LOAD_GLOBAL              0 (fib)
             24 LOAD_FAST                0 (a)
             26 LOAD_CONST               1 (2)
             28 BINARY_SUBTRACT
             30 CALL_FUNCTION            1
             32 BINARY_ADD
             34 RETURN_VALUE

@cthulahoops
Copy link
Collaborator Author

I really should have linked to this issue with my pull requests:

#512 and #555 add the beginnings of a rust implementation of the dis module, which is what you're seeing there.

Only dis and disassemble are implemented. (And dis doesn't support everything it should yet.)

As discussed in #445, the internals of the VM are too different to make compatibility with the python implementation of dis sensible at the moment.

This is still open as I'm still planning on fleshing out the dis module a bit more.

@youknowone
Copy link
Member

is this still open?

@youknowone
Copy link
Member

basic one is implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-design About RustPython's own implementation
Projects
None yet
Development

No branches or pull requests

3 participants