You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
Python 2.6 with as stmt
This commit is contained in:
BIN
test/bytecode_2.6/04_withas.pyc
Normal file
BIN
test/bytecode_2.6/04_withas.pyc
Normal file
Binary file not shown.
12
test/simple_source/stmts/04_withas.py
Normal file
12
test/simple_source/stmts/04_withas.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 2.6.9 calendar.py
|
||||||
|
# Bug in 2.6.9 was handling with as. Added rules
|
||||||
|
|
||||||
|
#
|
||||||
|
# withasstmt ::= expr setupwithas designator suite_stmts_opt
|
||||||
|
# POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||||
|
# setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 STORE_FAST
|
||||||
|
# SETUP_FINALLY LOAD_FAST DELETE_FAST
|
||||||
|
|
||||||
|
def formatweekday(self):
|
||||||
|
with self as encoding:
|
||||||
|
return encoding
|
@@ -192,15 +192,6 @@ class Python2Parser(PythonParser):
|
|||||||
|
|
||||||
jmp_abs ::= JUMP_ABSOLUTE
|
jmp_abs ::= JUMP_ABSOLUTE
|
||||||
jmp_abs ::= JUMP_BACK
|
jmp_abs ::= JUMP_BACK
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
|
||||||
WITH_CLEANUP END_FINALLY
|
|
||||||
|
|
||||||
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
|
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
|
||||||
WITH_CLEANUP END_FINALLY
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def p_dictcomp2(self, args):
|
def p_dictcomp2(self, args):
|
||||||
|
@@ -117,10 +117,17 @@ class Python26Parser(Python2Parser):
|
|||||||
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
|
# Semantic actions want designator to be at index 2
|
||||||
|
withasstmt ::= expr setupwithas designator suite_stmts_opt
|
||||||
|
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
# This is truly weird. 2.7 does this (not including POP_TOP) with
|
# This is truly weird. 2.7 does this (not including POP_TOP) with
|
||||||
# opcode SETUP_WITH
|
# opcode SETUP_WITH
|
||||||
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
||||||
|
|
||||||
|
setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 STORE_FAST
|
||||||
|
SETUP_FINALLY LOAD_FAST DELETE_FAST
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop POP_BLOCK COME_FROM
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop POP_BLOCK COME_FROM
|
||||||
|
@@ -28,13 +28,26 @@ class Python27Parser(Python2Parser):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def p_misc27(self, args):
|
def p_misc27(self, args):
|
||||||
|
"""
|
||||||
|
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def p_stmt27(self, args):
|
||||||
"""
|
"""
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
||||||
|
|
||||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||||
|
POP_BLOCK LOAD_CONST COME_FROM
|
||||||
|
WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
|
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
|
||||||
|
POP_BLOCK LOAD_CONST COME_FROM
|
||||||
|
WITH_CLEANUP END_FINALLY
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Python27ParserSingle(Python27Parser, PythonParserSingle):
|
class Python27ParserSingle(Python27Parser, PythonParserSingle):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user