From d32e67891b8f63463cf0c0d4ff12865f72c5e533 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 12 Jun 2018 12:19:43 -0400 Subject: [PATCH] More 3.0 bug fixing and tollerance and... add some 1.4 bytecode tests --- test/bytecode_1.4/addpack.pyc | Bin 0 -> 1302 bytes test/bytecode_1.4/anydbm.pyc | Bin 0 -> 1778 bytes test/bytecode_3.0/02_ifelse_lambda.pyc | Bin 0 -> 1339 bytes uncompyle6/parsers/parse30.py | 9 +++++++ uncompyle6/scanner.py | 33 ++++++++++++------------- uncompyle6/scanners/scanner3.py | 7 +++++- 6 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 test/bytecode_1.4/addpack.pyc create mode 100644 test/bytecode_1.4/anydbm.pyc create mode 100644 test/bytecode_3.0/02_ifelse_lambda.pyc diff --git a/test/bytecode_1.4/addpack.pyc b/test/bytecode_1.4/addpack.pyc new file mode 100644 index 0000000000000000000000000000000000000000..578b6ec5695e5b3217efd39d6a5f624a9a990ab8 GIT binary patch literal 1302 zcmbtUTTj$b5dKcP7j7yhCW{XyJQ%G}C@3NtE=J=6FT4;X;f0iKVY>_Gl%7i1q??nV zul@^vo%0 zVkNSN*u#F{lXF*L3T@cmN}Szu41kdb7ohZzDx@At;D>^F4CP+b)<$I=`Oq_T@RD^> z+$$6^6b)Ph^B zbIze`39g4x8}2nqO4CHY4Koi_(Y?=Bru&G}z2WopL1j`*;o=t#+#0hbhJ7FA35AmK zADnU7jPtg}5tHD!b+*l!1v*|wG0!a}oKEbcbL~N@ea9};4$8FYHgL7YI@h*=d_`(_ zFEvQfTt>o|DG4jw&> zwH%T~Mb9=#NNsdno4NzRIF4+hqw_=@S+Om0JYr~T+a&fPdo)OfmKVkjtppvNoJB>E zXgf{DGt-TV)MzU%qzP2tq*^$f=qh!b=7Jq%S)yY*OQE~xnaPVUd2aH63#!;s>f69K zY7vSxmw&~vfitrsCETD_*fZxzn49ik7%peSL|=xNNp6{FxVpR+o~6fOHY|EZvlhiM zmrRaQbfwY-@#$+V;n59pTe7$`!);uBC8)>QUC)TIeoyT1oF-k`eny**X!|*tL*lOd&%5-<+^62puiRtW z4ynfn^tvGbkUIEnpV03o2oBYTe~$nzDMg3JRl zefqOYlS2aZS@}LV$Fm;M59~PDN?DgU%yq>od8O-Gnb}HJwRapxMe)ML#M&r7FN(fh zt$j%1Q1p%ZR*aEfvn%Je=Ak;iIv%R0r>CcbqG%%D257h0$F%ls7<|u{tOBPdI7Xt` zYp#;AQEA{WbzBbB0@1_F%Liqe)ePS|$6;X@3=F%Zyi@v8+gi_TZPNyvRRZ+No2KTd z%EYL}pkOQm-v`5CAT=h1JlS{d>)Kygx46@m@`5)?JEM$FTIs+lrT~{X_y#4KU$On0 zGy}W+PqF9W(Yhujq2)@0%O!_k&3>oo_usuJOuQ^&Xw~mTx_c44HRRLH#mlCPCJy$&nUg)mcim4t;NZZ>JHkx)(asvLZ7DK zDlHj+U}b;{ltP_diz9PPItXvI@wS4JXMFtk;8y1Z; zWu(-(h`oZ(49evMI>m7~&gBb|aJfwbE&=CVH0fQv$>G@NxkkxyDiJ!w5Yeq1h=aJ> z1iN^M%cVWE5jPCUxs3;TZ58j!yFI%WCdCi%*xe{c@tK;UThPo=d>J2O$N7BV^F^fQ zzH#Om-i#0vc{ Jn!@h8e*q-m55E8a literal 0 HcmV?d00001 diff --git a/test/bytecode_3.0/02_ifelse_lambda.pyc b/test/bytecode_3.0/02_ifelse_lambda.pyc new file mode 100644 index 0000000000000000000000000000000000000000..880e5100e37507a3e87311f175c169e8be1202c1 GIT binary patch literal 1339 zcmb`GK~LL25QS%Lr%oVgIiLbLp!Q~|QmMGMLZGTqPh1=cDVNB2H)IkvX8pC>+xj^DKg#LB2w!M=%lmI z`1u<2MGEdBp)k5_SU*islpik2s?ZkhLx8hKx0N}X{^JBozNbz9nSC(yM`)CF%>`%< zk-gF(`lu&|I3Es@_KJJr_$NE7Yg1j@a`B_8%1X4ml65MpZLr*$lmUOO*~EID%JWjY b!ua25A6Yx9uljLE?FE?OJ9VfIBYt-e8vyA^ literal 0 HcmV?d00001 diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index 721e0740..97b2a4df 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -12,6 +12,12 @@ class Python30Parser(Python31Parser): def p_30(self, args): """ + assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1 POP_TOP + return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP + compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP + JUMP_IF_FALSE POP_TOP compare_chained2 + compare_chained2 ::= expr COMPARE_OP RETURN_END_IF_LAMBDA + # FIXME: combine with parse3.2 whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP @@ -85,6 +91,9 @@ class Python30Parser(Python31Parser): jump_absolute_else ::= JUMP_ABSOLUTE ELSE whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK COME_FROM_LOOP + assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1 + return_if_lambda ::= RETURN_END_IF_LAMBDA + compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP compare_chained2 COME_FROM """) return diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 7b85eed8..06331bdb 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -503,25 +503,24 @@ 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)) - if PYTHON3: - if version == 3.0: - import uncompyle6.scanners.scanner30 as scan - else: - import importlib - if is_pypy: - scan = importlib.import_module("uncompyle6.scanners.pypy%s" % v_str) - else: - scan = importlib.import_module("uncompyle6.scanners.scanner%s" % v_str) - if False: print(scan) # Avoid unused scan - else: + try: + import importlib if is_pypy: - exec("import uncompyle6.scanners.pypy%s as scan" % v_str) + scan = importlib.import_module("uncompyle6.scanners.pypy%s" % v_str) else: - exec("import uncompyle6.scanners.scanner%s as scan" % v_str) - if is_pypy: - scanner = eval("scan.ScannerPyPy%s(show_asm=show_asm)" % v_str) - else: - scanner = eval("scan.Scanner%s(show_asm=show_asm)" % v_str) + scan = importlib.import_module("uncompyle6.scanners.scanner%s" % v_str) + if False: print(scan) # Avoid unused scan + except ImportError: + if is_pypy: + exec("import uncompyle6.scanners.pypy%s as scan" % v_str, + locals(), globals()) + scanner = eval("scan.ScannerPyPy%s(show_asm=show_asm)" % v_str, + locals(), globals()) + else: + exec("import uncompyle6.scanners.scanner%s as scan" % v_str, + locals(), globals()) + scanner = eval("scan.Scanner%s(show_asm=show_asm)" % v_str, + locals(), globals()) else: raise RuntimeError("Unsupported Python version %s" % version) return scanner diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index cc4c2058..21ababcd 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -211,7 +211,12 @@ class Scanner3(Scanner): # If we have a JUMP_FORWARD after the # RAISE_VARARGS then we have a "raise" statement # else we have an "assert" statement. - if inst.opname == 'POP_JUMP_IF_TRUE' and i+1 < n: + if self.version == 3.0: + # There is a an implied JUMP_IF_TRUE that we are not testing for (yet?) here + assert_can_follow = inst.opname == 'POP_TOP' and i+1 < n + else: + assert_can_follow = inst.opname == 'POP_JUMP_IF_TRUE' and i+1 < n + if assert_can_follow: next_inst = self.insts[i+1] if (next_inst.opname == 'LOAD_GLOBAL' and next_inst.argval == 'AssertionError'):