MCPcopy Index your code
hub / github.com/RustPython/RustPython / build_deopts

Function build_deopts

scripts/generate_opcode_metadata.py:75–118  ·  view source on GitHub ↗
(contents: str)

Source from the content-addressed store, hash-verified

73
74
75def build_deopts(contents: str) -> dict[str, list[str]]:
76 raw_body = re.search(
77 r"fn deopt\(self\) -> Option<Self>(.*)", contents, re.DOTALL
78 ).group(1)
79 body = "\n".join(
80 itertools.takewhile(
81 lambda l: not l.startswith("_ =>"), # Take until reaching fallback
82 filter(
83 lambda l: (
84 not l.startswith(
85 ("//", "Some(match")
86 ) # Skip comments or start of match
87 ),
88 map(str.strip, raw_body.splitlines()),
89 ),
90 )
91 ).removeprefix("{")
92
93 depth = 0
94 arms = []
95 buf = []
96 for char in body:
97 if char == "{":
98 depth += 1
99 elif char == "}":
100 depth -= 1
101
102 if depth == 0 and (char in ("}", ",")):
103 arm = "".join(buf).strip()
104 arms.append(arm)
105 buf = []
106 else:
107 buf.append(char)
108
109 # last arm
110 arms.append("".join(buf))
111 arms = [arm for arm in arms if arm]
112
113 deopts = {}
114 for arm in arms:
115 *specialized, deopt = map(to_pascal_case, re.findall(r"Self::(\w*)\b", arm))
116 deopts[deopt] = specialized
117
118 return deopts
119
120
121contents = BYTECODE_FILE.read_text(encoding="utf-8")

Callers 1

Calls 10

filterFunction · 0.85
groupMethod · 0.45
searchMethod · 0.45
removeprefixMethod · 0.45
joinMethod · 0.45
startswithMethod · 0.45
splitlinesMethod · 0.45
stripMethod · 0.45
appendMethod · 0.45
findallMethod · 0.45

Tested by

no test coverage detected