Skip to content

Commit c90cb45

Browse files
author
rocky
committed
Split out and redo opcode organization
This was already too large. Revise so we can grow even more.
1 parent f19046b commit c90cb45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+490
-294
lines changed

pytest/test_stack_effect.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from xdis import get_opcode
66
from xdis.cross_dis import op_has_argument, xstack_effect
77
from xdis.op_imports import get_opcode_module
8-
from xdis.version_info import PYTHON_IMPLEMENTATION, PYTHON_VERSION_TRIPLE
8+
from xdis.version_info import (
9+
PYTHON_IMPLEMENTATION,
10+
PYTHON_VERSION_TRIPLE,
11+
version_tuple_to_str,
12+
)
913

1014

1115
def get_srcdir() -> str:
@@ -78,7 +82,7 @@ def test_stack_effect_fixed() -> None:
7882
check_effect = opcode_stack_effect[opcode]
7983
assert check_effect == effect, (
8084
"in version %s %d (%s) not okay; effect xstack_effect is %d; C source has %d"
81-
% (opc.version, opcode, opname, effect, check_effect)
85+
% (version_tuple_to_str(opc.version_tuple), opcode, opname, effect, check_effect)
8286
)
8387
# print("version %s: %d (%s) is good: effect %d" % (version, opcode, opname, effect))
8488
pass

xdis/bytecode.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
from xdis.cross_types import UnicodeForPython3
3939
from xdis.instruction import Instruction
4040
from xdis.op_imports import get_opcode_module
41-
from xdis.opcodes.opcode_36 import format_CALL_FUNCTION, format_CALL_FUNCTION_EX
41+
from xdis.opcodes.opcode_3x.opcode_36 import (
42+
format_CALL_FUNCTION,
43+
format_CALL_FUNCTION_EX,
44+
)
4245
from xdis.util import code2num, num2code
4346
from xdis.version_info import PYTHON_IMPLEMENTATION, PythonImplementation
4447

@@ -872,9 +875,9 @@ def list2bytecode(
872875

873876

874877
if __name__ == "__main__":
875-
import xdis.opcodes.opcode_27 as opcode_27
876-
import xdis.opcodes.opcode_34 as opcode_34
877-
import xdis.opcodes.opcode_36 as opcode_36
878+
import xdis.opcodes.opcode_2x.opcode_27 as opcode_27
879+
import xdis.opcodes.opcode_3x.opcode_34 as opcode_34
880+
import xdis.opcodes.opcode_3x.opcode_36 as opcode_36
878881
from xdis.version_info import PYTHON3
879882

880883
my_constants = (None, 2)

xdis/bytecode_graal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from xdis.cross_dis import get_code_object
55
from xdis.instruction import Instruction
66
from xdis.lineoffsets_graal import find_linestarts_graal
7-
from xdis.opcodes.base_graal import (
7+
from xdis.opcodes.opcode_graal.base_graal import (
88
BINARY_OPS,
99
UNARY_OPS,
1010
collection_to_str,

xdis/op_imports.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,24 @@
5151
opcode_37,
5252
opcode_37pypy,
5353
opcode_38,
54-
opcode_38graal,
5554
opcode_38pypy,
5655
opcode_39,
5756
opcode_39pypy,
5857
opcode_310,
59-
opcode_310graal,
6058
opcode_310pypy,
6159
opcode_311,
62-
opcode_311graal,
6360
opcode_311pypy,
6461
opcode_312,
65-
opcode_312graal,
6662
opcode_313,
6763
opcode_313rust,
6864
opcode_314,
6965
)
66+
from xdis.opcodes.opcode_graal import (
67+
opcode_38graal,
68+
opcode_310graal,
69+
opcode_311graal,
70+
opcode_312graal,
71+
)
7072
from xdis.version_info import PythonImplementation, version_tuple_to_str
7173

7274
# FIXME

xdis/opcodes/__init__.py

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Copyright 2023 by Rocky Bernstein
1+
# (C) Copyright 2023, 2025 by Rocky Bernstein
22
#
33
# This program is free software; you can redistribute it and/or
44
# modify it under the terms of the GNU General Public License
@@ -18,3 +18,114 @@
1818
of stack usage and information for formatting instructions.
1919
This covers information from the Python stdlib opcodes.py.
2020
"""
21+
22+
from xdis.opcodes.opcode_1x import (
23+
opcode_10,
24+
opcode_11,
25+
opcode_12,
26+
opcode_13,
27+
opcode_14,
28+
opcode_15,
29+
opcode_16,
30+
)
31+
from xdis.opcodes.opcode_2x import (
32+
opcode_20,
33+
opcode_21,
34+
opcode_22,
35+
opcode_23,
36+
opcode_24,
37+
opcode_25,
38+
opcode_26,
39+
opcode_27,
40+
)
41+
from xdis.opcodes.opcode_3x import (
42+
opcode_30,
43+
opcode_31,
44+
opcode_32,
45+
opcode_33,
46+
opcode_34,
47+
opcode_35,
48+
opcode_36,
49+
opcode_37,
50+
opcode_38,
51+
opcode_39,
52+
opcode_310,
53+
opcode_311,
54+
opcode_312,
55+
opcode_313,
56+
opcode_314,
57+
)
58+
from xdis.opcodes.opcode_pypy import (
59+
opcode_26pypy,
60+
opcode_27pypy,
61+
opcode_32pypy,
62+
opcode_33pypy,
63+
opcode_35pypy,
64+
opcode_36pypy,
65+
opcode_37pypy,
66+
opcode_38pypy,
67+
opcode_39pypy,
68+
opcode_310pypy,
69+
opcode_311pypy,
70+
)
71+
from xdis.opcodes.opcode_rust import opcode_313rust # opcode_312rust,
72+
73+
# from xdis.opcodes.opcode_graal import (
74+
# opcode_310graal,
75+
# opcode_311graal,
76+
# opcode_312graal,
77+
# opcode_38graal,
78+
# )
79+
80+
81+
82+
__all__ = [
83+
"opcode_10",
84+
"opcode_11",
85+
"opcode_12",
86+
"opcode_13",
87+
"opcode_14",
88+
"opcode_15",
89+
"opcode_16",
90+
"opcode_20",
91+
"opcode_21",
92+
"opcode_22",
93+
"opcode_23",
94+
"opcode_24",
95+
"opcode_25",
96+
"opcode_26",
97+
"opcode_26pypy",
98+
"opcode_27",
99+
"opcode_27pypy",
100+
"opcode_30",
101+
"opcode_31",
102+
"opcode_310",
103+
"opcode_311",
104+
"opcode_312",
105+
"opcode_313",
106+
"opcode_314",
107+
"opcode_32",
108+
"opcode_33",
109+
"opcode_34",
110+
"opcode_35",
111+
"opcode_36",
112+
"opcode_37",
113+
"opcode_38",
114+
"opcode_39",
115+
"opcode_310pypy",
116+
"opcode_311pypy",
117+
"opcode_32pypy",
118+
"opcode_33pypy",
119+
"opcode_35pypy",
120+
"opcode_36pypy",
121+
"opcode_37pypy",
122+
"opcode_38pypy",
123+
"opcode_39pypy",
124+
# "opcode_310graal",
125+
# "opcode_311graal",
126+
# "opcode_312graal",
127+
"opcode_38graal",
128+
# "opcode_312rust",
129+
"opcode_313rust",
130+
131+
]

xdis/opcodes/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def init_opdata(loc, from_mod, version_tuple=None, is_pypy: bool=False) -> None:
142142
if version_tuple >= (3,14):
143143
fields2copy.extend(fields2copy_314)
144144
for field in fields2copy:
145-
loc[field] = getattr(from_mod, field).copy()
145+
if hasattr(from_mod, field):
146+
loc[field] = getattr(from_mod, field).copy()
146147
pass
147148
else:
148149
# FIXME: DRY with above

xdis/opcodes/opcode_1x/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
of stack usage and information for formatting instructions.
2121
"""
2222

23-
import xdis.opcodes.opcode_11 as opcode_11
23+
import xdis.opcodes.opcode_1x.opcode_11 as opcode_11
2424

2525
# This is used from outside this module
2626
from xdis.cross_dis import findlabels # noqa
@@ -32,7 +32,7 @@
3232
rm_op,
3333
update_pj2,
3434
)
35-
from xdis.opcodes.opcode_11 import opcode_arg_fmt11, opcode_extended_fmt11
35+
from xdis.opcodes.opcode_1x.opcode_11 import opcode_arg_fmt11, opcode_extended_fmt11
3636

3737
version_tuple = (1, 0)
3838
python_implementation = cpython_implementation
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
opcodes in Python's dis.py library.
2121
"""
2222

23-
import xdis.opcodes.opcode_12 as opcode_12
23+
import xdis.opcodes.opcode_1x.opcode_12 as opcode_12
2424

2525
# This is used from outside this module
2626
from xdis.cross_dis import findlabels
@@ -30,7 +30,7 @@
3030
init_opdata,
3131
update_pj2,
3232
)
33-
from xdis.opcodes.opcode_12 import opcode_arg_fmt12, opcode_extended_fmt12
33+
from xdis.opcodes.opcode_1x.opcode_12 import opcode_arg_fmt12, opcode_extended_fmt12
3434

3535
version_tuple = (1, 1) # 1.2 is the same
3636
python_implementation = cpython_implementation
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Copyright 2019-2023 by Rocky Bernstein
1+
# (C) Copyright 2019-2023, 2025 by Rocky Bernstein
22
#
33
# This program is free software; you can redistribute it and/or
44
# modify it under the terms of the GNU General Public License
@@ -20,10 +20,8 @@
2020
opcodes in Python's dis.py library.
2121
"""
2222

23-
import xdis.opcodes.opcode_13 as opcode_13
24-
25-
# This is used from outside this module
26-
from xdis.cross_dis import findlabels # noqa
23+
import xdis.cross_dis
24+
import xdis.opcodes.opcode_1x.opcode_13 as opcode_13
2725
from xdis.opcodes.base import ( # Although these aren't used here, they are exported; noqa
2826
cpython_implementation,
2927
finalize_opcodes,
@@ -33,10 +31,11 @@
3331
store_op,
3432
update_pj2,
3533
)
36-
from xdis.opcodes.opcode_13 import opcode_arg_fmt13, opcode_extended_fmt13
34+
from xdis.opcodes.opcode_1x.opcode_13 import opcode_arg_fmt13, opcode_extended_fmt13
3735

3836
version_tuple = (1, 2)
3937
python_implementation = cpython_implementation
38+
findlabels = xdis.cross_dis.findlabels
4039

4140
loc = locals()
4241
init_opdata(loc, opcode_13, version_tuple)

0 commit comments

Comments
 (0)