diff --git a/test/bytecode_2.3/03_if1.pyc b/test/bytecode_2.3/03_if1.pyc new file mode 100644 index 00000000..de82a585 Binary files /dev/null and b/test/bytecode_2.3/03_if1.pyc differ diff --git a/uncompyle6/parsers/parse23.py b/uncompyle6/parsers/parse23.py index 160c4de1..b2072e16 100644 --- a/uncompyle6/parsers/parse23.py +++ b/uncompyle6/parsers/parse23.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Rocky Bernstein +# Copyright (c) 2016-2017 Rocky Bernstein # Copyright (c) 2000-2002 by hartmut Goebel # Copyright (c) 1999 John Aycock @@ -14,6 +14,17 @@ class Python23Parser(Python24Parser): def p_misc23(self, args): ''' + # Python 2.4 only adds something like the below for if 1: + # However we will just treat it as a noop (which of course messes up + # simple verify of bytecode. + # See also below in reduce_is_invalid where we check that the JUMP_FORWARD + # target matches the COME_FROM target + stmt ::= if1_stmt + if1_stmt ::= JUMP_FORWARD JUMP_IF_FALSE THEN POP_TOP COME_FROM + stmts + JUMP_FORWARD COME_FROM POP_TOP COME_FROM + + # Used to keep semantic positions the same across later versions # of Python _while1test ::= SETUP_LOOP JUMP_FORWARD JUMP_IF_FALSE POP_TOP COME_FROM @@ -33,6 +44,23 @@ class Python23Parser(Python24Parser): lc_body ::= LOAD_FAST expr LIST_APPEND ''' + def add_custom_rules(self, tokens, customize): + super(Python23Parser, self).add_custom_rules(tokens, customize) + + def reduce_is_invalid(self, rule, ast, tokens, first, last): + invalid = super(Python24Parser, + self).reduce_is_invalid(rule, ast, + tokens, first, last) + if invalid: + return invalid + + # FiXME: this code never gets called... + lhs = rule[0] + if lhs == 'nop_stmt': + return not int(tokens[first].pattr) == tokens[last].offset + + return False + class Python23ParserSingle(Python23Parser, PythonParserSingle): pass diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 6570f330..cc70aaf6 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -218,6 +218,11 @@ class SourceWalker(GenericASTTraversal, object): 'importlist2': ( '%C', (0, maxint, ', ') ), }) if version <= 2.4: + if version == 2.3: + TABLE_DIRECT.update({ + 'if1_stmt': ( '%|if 1\n%+%c%-', 5 ) + }) + global NAME_MODULE NAME_MODULE = AST('stmt', [ AST('assign',