Add is_pypy parameter to places that need it

This commit is contained in:
rocky 2016-07-27 16:08:40 -04:00
parent 5ffd9b2be7
commit f33f425692
4 changed files with 14 additions and 13 deletions

View File

@ -1,9 +1,9 @@
import pytest
from uncompyle6 import PYTHON_VERSION, PYTHON3 # , PYTHON_VERSION
from uncompyle6 import PYTHON_VERSION, PYTHON3, IS_PYPY # , PYTHON_VERSION
from uncompyle6.parser import get_python_parser
def test_grammar():
p = get_python_parser(PYTHON_VERSION)
p = get_python_parser(PYTHON_VERSION, is_pypy=IS_PYPY)
lhs, rhs, tokens, right_recursive = p.checkSets()
expect_lhs = set(['expr1024', 'pos_arg'])
unused_rhs = set(['build_list', 'call_function', 'mkfunc', 'mklambda',
@ -19,5 +19,6 @@ def test_grammar():
assert expect_lhs == set(lhs)
assert unused_rhs == set(rhs)
assert expect_right_recursive == right_recursive
expect_tokens =
# FIXME: check that tokens are in list of opcodes
# print(tokens)

View File

@ -28,7 +28,7 @@ from xdis.code import iscode
from xdis.load import check_object_path, load_module
from uncompyle6.scanner import get_scanner
def disco(version, co, out=None):
def disco(version, co, out=None, is_pypy=False):
"""
diassembles and deparses a given code block 'co'
"""
@ -42,7 +42,7 @@ def disco(version, co, out=None):
print('# Embedded file name: %s' % co.co_filename,
file=real_out)
scanner = get_scanner(version)
scanner = get_scanner(version, is_pypy=is_pypy)
queue = deque([co])
disco_loop(scanner.disassemble, queue, real_out)
@ -82,7 +82,7 @@ def disassemble_file(filename, outstream=None, native=False):
for con in co:
disco(version, con, outstream)
else:
disco(version, co, outstream)
disco(version, co, outstream, is_pypy=is_pypy)
co = None
def _test():

View File

@ -18,7 +18,7 @@ from __future__ import print_function
import sys
from uncompyle6 import PYTHON3
from uncompyle6 import PYTHON3, IS_PYPY
from uncompyle6.scanners.tok import Token
# The byte code versions we support
@ -255,7 +255,7 @@ class Scanner(object):
def parse_fn_counts(argc):
return ((argc & 0xFF), (argc >> 8) & 0xFF, (argc >> 16) & 0x7FFF)
def get_scanner(version, show_asm=None, is_pypy=False):
def get_scanner(version, is_pypy=False, show_asm=None):
# Pick up appropriate scanner
if version in PYTHON_VERSIONS:
v_str = "%s" % (int(version * 10))
@ -282,5 +282,5 @@ def get_scanner(version, show_asm=None, is_pypy=False):
if __name__ == "__main__":
import inspect, uncompyle6
co = inspect.currentframe().f_code
scanner = get_scanner(uncompyle6.PYTHON_VERSION, True)
scanner = get_scanner(uncompyle6.PYTHON_VERSION, IS_PYPY, True)
tokens, customize = scanner.disassemble(co, {})

View File

@ -55,7 +55,7 @@ from __future__ import print_function
import re, sys
from uncompyle6 import PYTHON3
from uncompyle6 import PYTHON3, IS_PYPY
from xdis.code import iscode
from uncompyle6.semantics import pysource
from uncompyle6 import parser
@ -1730,7 +1730,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
pass
def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
showgrammar=False):
showgrammar=False, is_pypy=False):
"""
Convert the code object co into a python source fragment.
@ -1756,7 +1756,7 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
assert iscode(co)
# store final output stream for case of error
scanner = get_scanner(version)
scanner = get_scanner(version, is_pypy=is_pypy)
tokens, customize = scanner.disassemble(co)
@ -1798,10 +1798,10 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
if __name__ == '__main__':
def deparse_test(co):
def deparse_test(co, is_pypy=IS_PYPY):
sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
walk = deparse_code(sys_version, co, showasm=False, showast=False,
showgrammar=False)
showgrammar=False, is_pypy=IS_PYPY)
print("deparsed source")
print(walk.text, "\n")
print('------------------------')