From 9f7d36f8fb6db170195d9818879c0b2adf8ab52a Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 7 Apr 2016 07:11:35 -0400 Subject: [PATCH] Handle Ternary "or". Remove mention of uncompyle3 uncompyle3 removed per Mysterie's request [Fixes Issue #5] --- HISTORY.md | 4 ---- README.rst | 1 - test/bytecode_2.5/10_if_else_ternary.pyc | Bin 0 -> 311 bytes test/bytecode_2.6/10_if_else_ternary.pyc | Bin 0 -> 309 bytes test/bytecode_2.7/10_if_else_ternary.pyc | Bin 0 -> 306 bytes test/bytecode_3.5/10_if_else_ternary.pyc_notyet | Bin 0 -> 251 bytes .../simple_source/branching/10_if_else_ternary.py | 11 +++++++++++ uncompyle6/parsers/parse2.py | 10 +++++----- uncompyle6/parsers/parse3.py | 8 ++++---- 9 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 test/bytecode_2.5/10_if_else_ternary.pyc create mode 100644 test/bytecode_2.6/10_if_else_ternary.pyc create mode 100644 test/bytecode_2.7/10_if_else_ternary.pyc create mode 100644 test/bytecode_3.5/10_if_else_ternary.pyc_notyet create mode 100644 test/simple_source/branching/10_if_else_ternary.py diff --git a/HISTORY.md b/HISTORY.md index 0611ff01..59c90c7b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -90,10 +90,6 @@ Hartmut a decade an a half ago: NB. This is not a masterpiece of software, but became more like a hack. Probably a complete rewrite would be sensefull. hG/2000-12-27 -One of the attempts to modernize it and make it available for Python3 -is [the one by Anton Vorobyov (DarkFenX)](https://github.com/DarkFenX/uncompyle3). I've -followed some of the ideas there in this project. - Lastly, I should mention [unpyc](https://code.google.com/p/unpyc3/) and most especially [pycdc](https://github.com/zrax/pycdc), largely by Michael Hansen and Darryl Pogue. If they supported getting source-code diff --git a/README.rst b/README.rst index 31890542..e236d948 100644 --- a/README.rst +++ b/README.rst @@ -93,7 +93,6 @@ See Also * https://github.com/zrax/pycdc * https://github.com/Mysterie/uncompyle2 -* https://github.com/DarkFenX/uncompyle3 * https://code.google.com/p/unpyc3/ The HISTORY file. diff --git a/test/bytecode_2.5/10_if_else_ternary.pyc b/test/bytecode_2.5/10_if_else_ternary.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aad37cf50b138a798680550e1267912fdacdef83 GIT binary patch literal 311 zcmdn|iI;1;En9dp0~9aWd3=Ay{3{gM^BSWwT6Hp`>M8L2!NS!>8s9|6z zkYHd0QZ|jnF3y=co1R3h50VEi}hLnK#6=1RwA_|f!)&&unxdl0?@x}S2 zMail9Nkxfy$r+h>>H3BS@tJAysX4`|@g=E6d5J}pdIgmw96%kpnR%JHnN_J=Al)FB iF);dpEery25XOU9q}x#pvco1fKczG$)edY2$O-@w+C3`( literal 0 HcmV?d00001 diff --git a/test/bytecode_2.6/10_if_else_ternary.pyc b/test/bytecode_2.6/10_if_else_ternary.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1a483ec7ce9afacb7cc8fe9130d3ce84c5bb9207 GIT binary patch literal 309 zcmcckiI;1;En9dp0~9aWd3=Ay{3{gM^BSWwT6Hp`>M8L2!NS!Q@s9|6z z5My8jQZ%()A4u;xp6YQ*(+_<4aPD@)C}hA1F|ks(-v2`G{bB4F4Vq)rM*)G#m< zNP@^3Muuz#h9WT#I~d3b)&QC3rvW4w!1_x-{0cBx2@wTJ73+eC%-n*U)cE53(xT*4 z{iLGAyyT3`ymWm-gZRv}_|%-@)cBIrqP)bSO1*;05)Pn_+|0bp+{~&}E|6}JqZklIL%NFj*$iVQJ0SPbx*$zNlEC3`@fQXTyg@GXo$Y5d!)?`iw$%6oh24QC) zE|vlkH4F>|k|45%ks+Ibp-2qG4hC|9H5vU@GH5d0Vyw8uSXl(LkO55m(k;%+EyziY zFU~J5N>0^JDoV^t&dAJ5*EckX&rFL?%_&ZeFG(%RODw9?E2zB1k(-&9nVVUa$_26# k><-2vRv_C?6G9`5hOk(Ga<@2aa`RJ4b5iZVx_}}K0G`Y*!2kdN literal 0 HcmV?d00001 diff --git a/test/simple_source/branching/10_if_else_ternary.py b/test/simple_source/branching/10_if_else_ternary.py new file mode 100644 index 00000000..7f1b02ea --- /dev/null +++ b/test/simple_source/branching/10_if_else_ternary.py @@ -0,0 +1,11 @@ +# Tests: + +# ret_expr_or_cond ::= ret_expr +# ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond +# ret_expr_or_cond ::= ret_cond +# ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + +# See https://github.com/rocky/python-uncompyle6/issues/5 + +def minimize(x, y): + return x or (x if x < y else y) diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 66e845b4..35d5c170 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -581,8 +581,8 @@ class Python2Parser(PythonParser): _mklambda ::= load_closure mklambda _mklambda ::= mklambda - or ::= expr jmp_true expr _come_from or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM + or ::= expr jmp_true expr _come_from and ::= expr jmp_false expr _come_from and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM and2 ::= _jump jmp_false COME_FROM expr COME_FROM @@ -601,10 +601,10 @@ class Python2Parser(PythonParser): ret_expr_or_cond ::= ret_cond ret_expr_or_cond ::= ret_cond_not - ret_and ::= expr jmp_false ret_expr_or_cond COME_FROM - ret_or ::= expr jmp_true ret_expr_or_cond COME_FROM - ret_cond ::= expr jmp_false expr RETURN_END_IF ret_expr_or_cond - ret_cond_not ::= expr jmp_true expr RETURN_END_IF ret_expr_or_cond + ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM + ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond + ret_cond_not ::= expr POP_JUMP_IF_TRUE expr RETURN_END_IF ret_expr_or_cond stmt ::= return_lambda stmt ::= conditional_lambda diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 24f8075e..10ab24c9 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -631,10 +631,10 @@ class Python3Parser(PythonParser): ret_expr_or_cond ::= ret_cond ret_expr_or_cond ::= ret_cond_not - ret_and ::= expr jmp_false ret_expr_or_cond COME_FROM - ret_or ::= expr jmp_true ret_expr_or_cond COME_FROM - ret_cond ::= expr jmp_false expr RETURN_END_IF ret_expr_or_cond - ret_cond_not ::= expr jmp_true expr RETURN_END_IF ret_expr_or_cond + ret_and ::= expr JUMP_IF_FALSE_OR_POP ret_expr_or_cond COME_FROM + ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM + ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF ret_expr_or_cond + ret_cond_not ::= expr POP_JUMP_IF_TRUE expr RETURN_END_IF ret_expr_or_cond stmt ::= return_lambda stmt ::= conditional_lambda