Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand ERROR_IF(), to include SHRINK_STACK()
  • Loading branch information
gvanrossum committed Nov 5, 2022
commit 4c990fde08902022b57bd2b6313f782b8866edb0
2 changes: 0 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,6 @@ GETITEM(PyObject *v, Py_ssize_t i) {

#define DEOPT_IF(cond, instname) if (cond) { goto miss; }

#define ERROR_IF(cond, label) if (cond) { goto label; }


#define GLOBALS() frame->f_globals
#define BUILTINS() frame->f_builtins
Expand Down
16 changes: 8 additions & 8 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@ def write_cases(f: io.TextIOBase, instrs: list[InstDef]):
while blocklines and not blocklines[-1].strip():
blocklines.pop()
# Write the body
ninputs = len(instr.inputs or ())
for line in blocklines:
f.write(line)
diff = len(instr.outputs or ()) - len(instr.inputs or ())
if m := re.match(r"(\s*)ERROR_IF\(([^,]+), (\w+)\);\s$", line):
space, cond, label = m.groups()
# ERROR_IF() must remove the inputs from the stack.
# The code block is responsible for DECREF()ing them.
if ninputs:
f.write(f"{space}if ({cond}) {{ STACK_SHRINK({ninputs}); goto {label}; }}\n")
else:
f.write(f"{space}if ({cond}) {{ goto {label}; }}\n")
else:
f.write(line)
noutputs = len(instr.outputs or ())
diff = noutputs - ninputs
if diff != 0:
f.write(f"{indent} STACK_GROW({diff});\n")
for i, output in enumerate(reversed(instr.outputs or ()), 1):
Expand Down