Skip to content

Commit d87ac8f

Browse files
author
rocky
committed
Bang on RustPython
1 parent 3d91076 commit d87ac8f

File tree

8 files changed

+567
-65
lines changed

8 files changed

+567
-65
lines changed

xdis/magics.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
from importlib.util import MAGIC_NUMBER as MAGIC
3939
from typing import Dict, Set
4040

41-
from xdis.version_info import IS_GRAAL, IS_PYPY, version_tuple_to_str
41+
from xdis.version_info import IS_GRAAL, IS_PYPY, IS_RUST, version_tuple_to_str
4242

4343
PYPY3_MAGICS = (48, 64, 112, 160, 192, 240, 244, 256, 336, 384, 416)
4444
GRAAL3_MAGICS = (21150, 21280, 21290)
4545
RUSTPYTHON_MAGICS = (
46-
12641, # RustPython 3.13
47-
12897 # RustPython 3.12
46+
12641, # RustPython 3.12
47+
12897, # RustPython 3.12
48+
13413, # RustPython 3.13
4849
)
4950

5051

@@ -625,8 +626,9 @@ def __by_version(magic_versions: Dict[bytes, str]) -> dict:
625626
add_magic_from_int(384, "3.10pypy") # PyPy 3.10.12
626627
add_magic_from_int(416, "3.11.13pypy") # PyPy 3.11.13
627628

628-
add_magic_from_int(12897, "3.12.0rust") # RustPython 3.12.0
629-
add_magic_from_int(12641, "3.13.0rust") # RustPython 3.13.0
629+
add_magic_from_int(12641, "3.12.0a.rust") # RustPython 3.12.0
630+
add_magic_from_int(12897, "3.13.0b.rust") # RustPython 3.12.0
631+
add_magic_from_int(13413, "3.13.0.rust") # RustPython 3.13.0
630632

631633
# Graal uses JVM bytecode, not Python bytecode
632634
add_magic_from_int(21150, "3.8.5Graal")
@@ -831,12 +833,14 @@ def sysinfo2magic(version_info: tuple=tuple(sys.version_info)) -> bytes:
831833
vers_str += "pypy"
832834
elif IS_GRAAL:
833835
vers_str += "Graal"
836+
elif IS_RUST:
837+
vers_str += "Rust"
834838
else:
835839
try:
836840
import platform
837841

838842
platform_str = platform.python_implementation()
839-
if platform_str in ("Jython", "Pyston", "GraalVM"):
843+
if platform_str in ("GraalVM", "Jython", "Pyston", "RustPython"):
840844
vers_str += platform_str
841845
pass
842846
except ImportError:

xdis/opcodes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def local_op(loc, name, opcode: int, pop=0, push=1) -> None:
255255
loc["nullaryop"].add(opcode)
256256

257257

258-
def name_op(loc: int, op_name, opcode: int, pop=-2, push=-2) -> None:
258+
def name_op(loc: dict, op_name, opcode: int, pop=-2, push=-2) -> None:
259259
"""
260260
Put opcode in the class of instructions that index into the "name" table.
261261
"""
@@ -341,7 +341,7 @@ def rm_op(loc, name, op) -> None:
341341
del loc["opmap"][name]
342342

343343

344-
def store_op(loc: int, name, op, pop=0, push=1, is_type="def") -> None:
344+
def store_op(loc: dict, name: str, op, pop=0, push=1, is_type="def") -> None:
345345
if is_type == "name":
346346
name_op(loc, name, op, pop, push)
347347
loc["nullaryop"].remove(op)

xdis/opcodes/opcode_311.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
loc["nullaryloadop"].add(137)
174174

175175
store_op(loc, "STORE_DEREF", 138, 1, 0, is_type="free")
176-
def_op(loc, "DELETE_DEREF", 139, 0, 0)
176+
free_op(loc, "DELETE_DEREF", 139, 0, 0)
177177

178178
# These are added since 3.10...
179179
# OP NAME OPCODE POP PUSH
@@ -216,11 +216,11 @@
216216
# new jump
217217
jrel_op(loc, "JUMP_BACKWARD_NO_INTERRUPT", 134, 0, 0)
218218
# new create cells op
219-
jrel_op(loc, "MAKE_CELL", 135, 0, 0)
219+
free_op(loc, "MAKE_CELL", 135, 0, 0)
220220
# new exception handling
221+
jrel_op(loc, "PUSH_EXC_INFO", 35, 0, 1)
221222
jrel_op(loc, "CHECK_EG_MATCH", 37, 0, 0)
222223
jrel_op(loc, "PREP_RERAISE_STAR", 88, 1, 0)
223-
jrel_op(loc, "PUSH_EXC_INFO", 35, 0, 1)
224224
# resume, acts like a nop
225225
def_op(loc, "RESUME", 151, 0, 0)
226226

xdis/opcodes/opcode_312.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
finalize_opcodes,
1313
init_opdata,
1414
jrel_op,
15+
local_op,
1516
name_op,
1617
rm_op,
1718
update_pj3,
@@ -75,7 +76,7 @@
7576
def_op(loc , "CLEANUP_THROW" , 55 , 2, 1)
7677
def_op(loc , "LOAD_LOCALS" , 87 , 0, 1)
7778
def_op(loc , "RETURN_CONST" , 121, 0, 0)
78-
def_op(loc , "LOAD_FAST_CHECK" , 127, 0, 1)
79+
local_op(loc , "LOAD_FAST_CHECK" , 127, 0, 1)
7980

8081
jrel_op(loc , "POP_JUMP_IF_FALSE" , 114, 1, 0)
8182
jrel_op(loc , "POP_JUMP_IF_TRUE" , 115, 1, 0)

0 commit comments

Comments
 (0)