| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
|
|
||
| from test.support.bytecode_helper import CodegenTestCase | ||
|
|
||
| # Tests for the code-generation stage of the compiler. | ||
| # Examine the un-optimized code generated from the AST. | ||
|
|
||
| class IsolatedCodeGenTests(CodegenTestCase): | ||
|
|
||
| def codegen_test(self, snippet, expected_insts): | ||
| import ast | ||
| a = ast.parse(snippet, "my_file.py", "exec"); | ||
| insts = self.generate_code(a) | ||
| self.assertInstructionsMatch(insts, expected_insts) | ||
|
|
||
| def test_if_expression(self): | ||
| snippet = "42 if True else 24" | ||
| false_lbl = self.Label() | ||
| expected = [ | ||
| ('RESUME', 0, 0), | ||
| ('LOAD_CONST', 0, 1), | ||
| ('POP_JUMP_IF_FALSE', false_lbl := self.Label(), 1), | ||
| ('LOAD_CONST', 1, 1), | ||
| ('JUMP', exit_lbl := self.Label()), | ||
| false_lbl, | ||
| ('LOAD_CONST', 2, 1), | ||
| exit_lbl, | ||
| ('POP_TOP', None), | ||
| ] | ||
| self.codegen_test(snippet, expected) | ||
|
|
||
| def test_for_loop(self): | ||
| snippet = "for x in l:\n\tprint(x)" | ||
| false_lbl = self.Label() | ||
| expected = [ | ||
| ('RESUME', 0, 0), | ||
| ('LOAD_NAME', 0, 1), | ||
| ('GET_ITER', None, 1), | ||
| loop_lbl := self.Label(), | ||
| ('FOR_ITER', exit_lbl := self.Label(), 1), | ||
| ('STORE_NAME', None, 1), | ||
| ('PUSH_NULL', None, 2), | ||
| ('LOAD_NAME', None, 2), | ||
| ('LOAD_NAME', None, 2), | ||
| ('CALL', None, 2), | ||
| ('POP_TOP', None), | ||
| ('JUMP', loop_lbl), | ||
| exit_lbl, | ||
| ('END_FOR', None), | ||
| ] | ||
| self.codegen_test(snippet, expected) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDoes this (or the other functions) need to be an API function?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCan _testinternalcapi import them otherwise?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think so, that why it has "internal" in the name.
It defines Py_BUILD_CORE_BUILTIN
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt doesn't seem to work:
[ERROR] _testinternalcapi failed to import: dlopen(/Users/iritkatriel/src/cpython-654/build/lib.macosx-13.0-x86_64-3.12-pydebug/_testinternalcapi.cpython-312d-darwin.so, 0x0002): symbol not found in flat namespace '__PyCompile_CodeGen'
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI'll merge this PR now, it's getting into merge conflicts all the time. We can remove these from the API later if it's possible.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.