Skip to content

Commit

Permalink
Keep black's fingers off some sections of code
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Jul 4, 2021
1 parent af2d741 commit ae35f3b
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 142 deletions.
4 changes: 3 additions & 1 deletion xdis/opcodes/opcode_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

# This is used from outside this module
from xdis.cross_dis import findlabels
from xdis.cross_dis import findlabels # noqa

import xdis.opcodes.opcode_11 as opcode_11
from xdis.opcodes.base import (
Expand All @@ -43,9 +43,11 @@
l = locals()
init_opdata(l, opcode_11, version)

# fmt: off
# 1.0 - 1.1 bytecodes differences
rm_op(l, "LOAD_GLOBALS", 84)
rm_op(l, "EXEC_STMT", 85)
# fmt: on

update_pj2(globals(), l)

Expand Down
4 changes: 2 additions & 2 deletions xdis/opcodes/opcode_11.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright 2019-2020 by Rocky Bernstein
# (C) Copyright 2019-2021 by Rocky Bernstein
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -36,7 +36,7 @@
update_pj2,
)

version = 1.1 # 1.2 is the same
version = 1.1 # 1.2 is the same
python_implementation = "CPython"

l = locals()
Expand Down
195 changes: 99 additions & 96 deletions xdis/opcodes/opcode_15.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright 2017, 2019-2020 by Rocky Bernstein
# (C) Copyright 2017, 2019-2021 by Rocky Bernstein
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -31,11 +31,11 @@
extended_format_MAKE_FUNCTION_older,
extended_format_RAISE_VARARGS_older,
extended_format_RETURN_VALUE,
finalize_opcodes,
format_RAISE_VARARGS_older,
format_extended_arg,
jabs_op,
jrel_op,
finalize_opcodes,
format_extended_arg,
local_op,
name_op,
nargs_op,
Expand Down Expand Up @@ -80,16 +80,16 @@

hascompare = []
hascondition = [] # conditional operator; has jump offset
hasconst = []
hasfree = []
hasjabs = []
hasjrel = []
haslocal = []
hasname = []
hasnargs = [] # For function-like calls
hasstore = [] # Some sort of store operation
hasvargs = [] # Similar but for operators BUILD_xxx
nofollow = [] # Instruction doesn't fall to the next opcode
hasconst = []
hasfree = []
hasjabs = []
hasjrel = []
haslocal = []
hasname = []
hasnargs = [] # For function-like calls
hasstore = [] # Some sort of store operation
hasvargs = [] # Similar but for operators BUILD_xxx
nofollow = [] # Instruction doesn't fall to the next opcode

# oppush[op] => number of stack entries pushed
# -9 means handle special. Note his forces oppush[i] - oppop[i] negative
Expand All @@ -108,133 +108,136 @@
# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

# fmt: off
def_op(l, "STOP_CODE", 0, 0, 0, fallthrough=False)
def_op(l, "POP_TOP", 1)
def_op(l, "ROT_TWO", 2)
def_op(l, "ROT_THREE", 3)
def_op(l, "DUP_TOP", 4)

def_op(l, "UNARY_POSITIVE", 10, 1, 1)
def_op(l, "UNARY_NEGATIVE", 11, 1, 1)
def_op(l, "UNARY_NOT", 12, 1, 1)
def_op(l, "UNARY_CONVERT", 13, 1, 1)
def_op(l, "UNARY_POSITIVE", 10, 1, 1)
def_op(l, "UNARY_NEGATIVE", 11, 1, 1)
def_op(l, "UNARY_NOT", 12, 1, 1)
def_op(l, "UNARY_CONVERT", 13, 1, 1)

def_op(l, "UNARY_INVERT", 15, 1, 1)
def_op(l, "UNARY_INVERT", 15, 1, 1)

def_op(l, "BINARY_POWER", 19, 1, 1)
def_op(l, "BINARY_POWER", 19, 1, 1)

def_op(l, "BINARY_MULTIPLY", 20, 2, 1)
def_op(l, "BINARY_DIVIDE", 21, 2, 1)
def_op(l, "BINARY_MODULO", 22, 2, 1)
def_op(l, "BINARY_ADD", 23, 2, 1)
def_op(l, "BINARY_DIVIDE", 21, 2, 1)
def_op(l, "BINARY_MODULO", 22, 2, 1)
def_op(l, "BINARY_ADD", 23, 2, 1)
def_op(l, "BINARY_SUBTRACT", 24, 2, 1)
def_op(l, "BINARY_SUBSCR", 25, 2, 1)
def_op(l, "BINARY_SUBSCR", 25, 2, 1)

def_op(l, "SLICE+0", 30, 1, 1)
def_op(l, "SLICE+1", 31, 2, 1)
def_op(l, "SLICE+2", 32, 2, 1)
def_op(l, "SLICE+3", 33, 3, 1)

store_op(l, "STORE_SLICE+0", 40, 2, 0)
store_op(l, "STORE_SLICE+1", 41, 3, 0)
store_op(l, "STORE_SLICE+2", 42, 3, 0)
store_op(l, "STORE_SLICE+3", 43, 4, 0)
store_op(l, "STORE_SLICE+0", 40, 2, 0)
store_op(l, "STORE_SLICE+1", 41, 3, 0)
store_op(l, "STORE_SLICE+2", 42, 3, 0)
store_op(l, "STORE_SLICE+3", 43, 4, 0)

def_op(l, "DELETE_SLICE+0", 50, 1, 0)
def_op(l, "DELETE_SLICE+1", 51, 2, 0)
def_op(l, "DELETE_SLICE+2", 52, 2, 0)
def_op(l, "DELETE_SLICE+3", 53, 3, 0)
def_op(l, "DELETE_SLICE+0", 50, 1, 0)
def_op(l, "DELETE_SLICE+1", 51, 2, 0)
def_op(l, "DELETE_SLICE+2", 52, 2, 0)
def_op(l, "DELETE_SLICE+3", 53, 3, 0)

store_op(l, "STORE_SUBSCR", 60, 3, 0) # Implements TOS1[TOS] = TOS2.
def_op(l, "DELETE_SUBSCR", 61, 2, 0) # Implements del TOS1[TOS].
store_op(l, "STORE_SUBSCR", 60, 3, 0) # Implements TOS1[TOS] = TOS2.
def_op(l, "DELETE_SUBSCR", 61, 2, 0) # Implements del TOS1[TOS].

def_op(l, "BINARY_LSHIFT", 62, 2, 1)
def_op(l, "BINARY_RSHIFT", 63, 2, 1)
def_op(l, "BINARY_AND", 64, 2, 1)
def_op(l, "BINARY_XOR", 65, 2, 1)
def_op(l, "BINARY_OR", 66, 2, 1)
def_op(l, "BINARY_LSHIFT", 62, 2, 1)
def_op(l, "BINARY_RSHIFT", 63, 2, 1)
def_op(l, "BINARY_AND", 64, 2, 1)
def_op(l, "BINARY_XOR", 65, 2, 1)
def_op(l, "BINARY_OR", 66, 2, 1)

def_op(l, "PRINT_EXPR", 70, 1, 0)
def_op(l, "PRINT_ITEM", 71, 1, 0)
def_op(l, "PRINT_NEWLINE", 72, 0, 0)
def_op(l, "PRINT_EXPR", 70, 1, 0)
def_op(l, "PRINT_ITEM", 71, 1, 0)
def_op(l, "PRINT_NEWLINE", 72, 0, 0)

def_op(l, "BREAK_LOOP", 80, 0, 0, fallthrough=False)
def_op(l, "BREAK_LOOP", 80, 0, 0, fallthrough=False)

def_op(l, "LOAD_LOCALS", 82, 0, 1)
def_op(l, "RETURN_VALUE", 83, 1, 0, fallthrough=False)
def_op(l, "LOAD_LOCALS", 82, 0, 1)
def_op(l, "RETURN_VALUE", 83, 1, 0, fallthrough=False)

def_op(l, "EXEC_STMT", 85, 3, 0)
def_op(l, "EXEC_STMT", 85, 3, 0)

def_op(l, "POP_BLOCK", 87, 0, 0)
def_op(l, "END_FINALLY", 88, 1, 0)
def_op(l, "BUILD_CLASS", 89, 3, 0)
def_op(l, "POP_BLOCK", 87, 0, 0)
def_op(l, "END_FINALLY", 88, 1, 0)
def_op(l, "BUILD_CLASS", 89, 3, 0)

# HAVE_ARGUMENT = 90 # Opcodes from here have an argument:

store_op(l, "STORE_NAME", 90, 1, 0, is_type="name") # Operand is in name list
name_op(l, "DELETE_NAME", 91, 0, 0) # ""
varargs_op(l, "UNPACK_TUPLE", 92) # Number of tuple items
def_op(l, "UNPACK_LIST", 93) # Number of list items
store_op(l, "STORE_ATTR", 95, 2, 0, is_type="name") # Operand is in name list
name_op(l, "DELETE_ATTR", 96, 1, 0) # ""
store_op(l, "STORE_GLOBAL", 97, 1, 0, is_type="name") # ""
name_op(l, "DELETE_GLOBAL", 98, 0, 0) # ""

const_op(l, "LOAD_CONST", 100, 0, 1) # Operand is in const list
name_op(l, "LOAD_NAME", 101, 0, 1) # Operand is in name list
varargs_op(l, "BUILD_TUPLE", 102, -1, 1) # Number of tuple items
varargs_op(l, "BUILD_LIST", 103, -1, 1) # Number of list items
varargs_op(l, "BUILD_MAP", 104, -1, 1) # Always zero for now
name_op(l, "LOAD_ATTR", 105, 1, 1) # Operand is in name list
compare_op(l, "COMPARE_OP", 106, 2, 1) # Comparison operator

name_op(l, "IMPORT_NAME", 107, 2, 1) # Operand is in name list
name_op(l, "IMPORT_FROM", 108, 0, 1) # Operand is in name list

jrel_op(l, "JUMP_FORWARD", 110, 0, 0, fallthrough=False) # Number of bytes to skip
jrel_op(l, "JUMP_IF_FALSE", 111, 1, 1, True) # ""
jrel_op(l, "JUMP_IF_TRUE", 112, 1, 1, True) # ""
jabs_op(l, "JUMP_ABSOLUTE", 113, 0, 0, fallthrough=False) # Target byte offset from beginning of code
def_op(l, "FOR_LOOP", 114) # Number of bytes to skip

name_op(l, "LOAD_GLOBAL", 116, 0, 1) # Operand is in name list

jrel_op(l, "SETUP_LOOP", 120, 0, 0, conditional=True) # Distance to target address
jrel_op(l, "SETUP_EXCEPT", 121, 0, 0) # ""
jrel_op(l, "SETUP_FINALLY", 122, 0, 0) # ""

local_op(l, "LOAD_FAST", 124, 0, 1) # Local variable number
store_op(l, "STORE_FAST", 125, 1, 0, is_type="local") # Local variable number
local_op(l, "DELETE_FAST", 126) # Local variable number

def_op(l, "SET_LINENO", 127) # Current line number

def_op(l, "RAISE_VARARGS", 130, -1, 0, fallthrough=False)
store_op(l, "STORE_NAME", 90, 1, 0, is_type="name") # Operand is in name list
name_op(l, "DELETE_NAME", 91, 0, 0) # ""
varargs_op(l, "UNPACK_TUPLE", 92) # Number of tuple items
def_op(l, "UNPACK_LIST", 93) # Number of list items
store_op(l, "STORE_ATTR", 95, 2, 0, is_type="name") # Operand is in name list
name_op(l, "DELETE_ATTR", 96, 1, 0) # ""
store_op(l, "STORE_GLOBAL", 97, 1, 0, is_type="name") # ""
name_op(l, "DELETE_GLOBAL", 98, 0, 0) # ""

const_op(l, "LOAD_CONST", 100, 0, 1) # Operand is in const list
name_op(l, "LOAD_NAME", 101, 0, 1) # Operand is in name list
varargs_op(l, "BUILD_TUPLE", 102, -1, 1) # Number of tuple items
varargs_op(l, "BUILD_LIST", 103, -1, 1) # Number of list items
varargs_op(l, "BUILD_MAP", 104, -1, 1) # Always zero for now
name_op(l, "LOAD_ATTR", 105, 1, 1) # Operand is in name list
compare_op(l, "COMPARE_OP", 106, 2, 1) # Comparison operator

name_op(l, "IMPORT_NAME", 107, 2, 1) # Operand is in name list
name_op(l, "IMPORT_FROM", 108, 0, 1) # Operand is in name list

jrel_op(l, "JUMP_FORWARD", 110, 0, 0, fallthrough=False) # Number of bytes to skip
jrel_op(l, "JUMP_IF_FALSE", 111, 1, 1, True) # ""
jrel_op(l, "JUMP_IF_TRUE", 112, 1, 1, True) # ""
jabs_op(l, "JUMP_ABSOLUTE", 113, 0, 0, fallthrough=False) # Target byte offset from beginning of code
def_op(l, "FOR_LOOP", 114) # Number of bytes to skip

name_op(l, "LOAD_GLOBAL", 116, 0, 1) # Operand is in name list

jrel_op(l, "SETUP_LOOP", 120, 0, 0, conditional=True) # Distance to target address
jrel_op(l, "SETUP_EXCEPT", 121, 0, 0) # ""
jrel_op(l, "SETUP_FINALLY", 122, 0, 0) # ""

local_op(l, "LOAD_FAST", 124, 0, 1) # Local variable number
store_op(l, "STORE_FAST", 125, 1, 0, is_type="local") # Local variable number
local_op(l, "DELETE_FAST", 126) # Local variable number

def_op(l, "SET_LINENO", 127) # Current line number

def_op(l, "RAISE_VARARGS", 130, -1, 0, fallthrough=False)
# Number of raise arguments (1, 2, or 3)
nargs_op(l, "CALL_FUNCTION", 131, -1, 1) # #args + (#kwargs << 8)
nargs_op(l, "CALL_FUNCTION", 131, -1, 1) # #args + (#kwargs << 8)

def_op(l, "MAKE_FUNCTION", 132, -1, 1) # Number of args with default values
varargs_op(l, "BUILD_SLICE", 133, -1, 1) # Number of items

def_op(l, "MAKE_FUNCTION", 132, -1, 1) # Number of args with default values
varargs_op(l, "BUILD_SLICE", 133, -1, 1) # Number of items
def_op(l, "EXTENDED_ARG", 143)

def_op(l, "EXTENDED_ARG", 143)
EXTENDED_ARG = 143

fields2copy = """cmp_op hasjabs""".split()

update_pj2(globals(), l)

opcode_arg_fmt = {
"EXTENDED_ARG": format_extended_arg,
"RAISE_VARARGS": format_RAISE_VARARGS_older
"EXTENDED_ARG": format_extended_arg,
"RAISE_VARARGS": format_RAISE_VARARGS_older,
}

finalize_opcodes(l)

opcode_extended_fmt = {
"CALL_FUNCTION": extended_format_CALL_FUNCTION,
"LOAD_ATTR": extended_format_ATTR,
"LOAD_ATTR": extended_format_ATTR,
"MAKE_FUNCTION": extended_format_MAKE_FUNCTION_older,
"RAISE_VARARGS": extended_format_RAISE_VARARGS_older,
"RETURN_VALUE": extended_format_RETURN_VALUE,
"STORE_ATTR": extended_format_ATTR,
"RETURN_VALUE": extended_format_RETURN_VALUE,
"STORE_ATTR": extended_format_ATTR,
}
# fmt: on
8 changes: 5 additions & 3 deletions xdis/opcodes/opcode_25.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright 2017, 2020 by Rocky Bernstein
# (C) Copyright 2017, 2021 by Rocky Bernstein
"""
CPython 2.5 bytecode opcodes
Expand All @@ -14,25 +14,27 @@
extended_format_MAKE_FUNCTION_older,
extended_format_RAISE_VARARGS_older,
extended_format_RETURN_VALUE,
init_opdata,
finalize_opcodes,
format_CALL_FUNCTION_pos_name_encoded,
format_MAKE_FUNCTION_default_argc,
format_RAISE_VARARGS_older,
format_extended_arg,
init_opdata,
update_pj2,
)
)

version = 2.5
python_implementation = "CPython"

l = locals()
init_opdata(l, opcode_24, version)

# fmt: off
# Bytecodes added in 2.5 from 2.4
# OP NAME OPCODE POP PUSH
#--------------------------------------------
def_op(l, 'WITH_CLEANUP', 81, 4, 3)
# fmt: on

# FIXME remove (fix uncompyle6)
update_pj2(globals(), l)
Expand Down
20 changes: 13 additions & 7 deletions xdis/opcodes/opcode_26pypy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright 2017, 2020 by Rocky Bernstein
# (C) Copyright 2017, 2021 by Rocky Bernstein
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -26,9 +26,12 @@
extended_format_RETURN_VALUE,
finalize_opcodes,
init_opdata,
jrel_op, name_op, nargs_op, varargs_op,
update_pj2
)
jrel_op,
name_op,
nargs_op,
update_pj2,
varargs_op,
)

version = 2.6
python_implementation = "PyPy"
Expand All @@ -38,17 +41,20 @@

# FIXME: DRY common PYPY opcode additions

# fmt: off
# PyPy only
# ----------
name_op(l, 'LOOKUP_METHOD', 201, 1, 2)
nargs_op(l, 'CALL_METHOD', 202, -1, 1)
l['hasnargs'].append(202)
# fmt: on

l["hasnargs"].append(202)

# Used only in single-mode compilation list-comprehension generators
varargs_op(l, 'BUILD_LIST_FROM_ARG', 203)
varargs_op(l, "BUILD_LIST_FROM_ARG", 203)

# Used only in assert statements
jrel_op(l, 'JUMP_IF_NOT_DEBUG', 204, conditional=True)
jrel_op(l, "JUMP_IF_NOT_DEBUG", 204, conditional=True)

# FIXME remove (fix uncompyle6)
update_pj2(globals(), l)
Expand Down
Loading

0 comments on commit ae35f3b

Please sign in to comment.