Skip to content

GH-99104: Update headers for bytecodes.c and generate_cases.py #99112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 16 additions & 7 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This file contains instruction definitions.
// It is read by Tools/cases_generator/generate_cases.py
// to generate Python/generated_cases.c.h.
// Note that there is some dummy C code at the top and bottom of the file
// to fool text editors like VS Code into believing this is valid C code.
// The actual instruction definitions start at // BEGIN BYTECODES //.
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: It's really the top and middle of this file. Might be worth mentioning the // Families go below this point // section, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to leave finding that as an exercise for the reader, since that is work in progress. The generator currently doesn't actually see the families because it stops reading after // END BYTECODES // -- I was planning to fix that once families are actually used for anything.

// See Tools/cases_generator/README.md for more information.

#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
Expand Down Expand Up @@ -3976,13 +3984,14 @@ dummy_func(
// END BYTECODES //

}
error:;
exception_unwind:;
handle_eval_breaker:;
resume_frame:;
resume_with_error:;
start_frame:;
unbound_local_error:;
error:
exception_unwind:
handle_eval_breaker:
resume_frame:
resume_with_error:
start_frame:
unbound_local_error:
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this semicolon really needed? My IDE (VS Code) doesn't complain...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an error to real C compilers, so better safe than sorry.

}

// Families go below this point //
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

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

3 changes: 2 additions & 1 deletion Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import argparse
import io
import os
import re
import sys

Expand Down Expand Up @@ -67,7 +68,7 @@ def write_cases(f: io.TextIOBase, instrs: list[InstDef]):
for target in re.findall(r"(?:PREDICT|GO_TO_INSTRUCTION)\((\w+)\)", inst.block.text):
predictions.add(target)
indent = " "
f.write("// This file is generated by Tools/scripts/generate_cases.py\n")
f.write(f"// This file is generated by {os.path.relpath(__file__)}\n")
f.write("// Do not edit!\n")
for instr in instrs:
assert isinstance(instr, InstDef)
Expand Down