Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-46409: Make generators in bytecode#30633
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bf0394d23877ec381f3d3c2b141e8b73d0d7cb3dad79b6d11039b14dc33abbfd105cace7c4bf2c0800891b177e3243e441a79e36b739259317b453abaa100944d3f4706330b0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -942,6 +942,13 @@ All of the following opcodes use their arguments. | ||
| Set bytecode counter to *target*. | ||
| .. opcode:: JUMP_NO_INTERRUPT (target) | ||
| Set bytecode counter to *target*. Do not check for interrupts. | ||
| .. versionadded:: 3.11 | ||
| .. opcode:: FOR_ITER (delta) | ||
| TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If | ||
| @@ -1220,6 +1227,14 @@ All of the following opcodes use their arguments. | ||
| .. versionadded:: 3.11 | ||
| .. opcode:: RETURN_GENERATOR | ||
| Create a generator, coroutine, or async generator from the current frame. | ||
| Clear the current frame and return the newly created generator. | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| .. versionadded:: 3.11 | ||
| .. opcode:: HAVE_ARGUMENT | ||
| This is not really an opcode. It identifies the dividing line between | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,7 +13,6 @@ extern "C"{ | ||
| and coroutine objects. */ | ||
| #define _PyGenObject_HEAD(prefix) \ | ||
| PyObject_HEAD \ | ||
| /* Note: gi_frame can be NULL if the generator is "finished" */ \ | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a question about gi_iframe. Below (L31) it is defined as an array of length 1 of object pointers. But everywhere it's used, it is cast to MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a lie. We don't want to expose InterpreterFramegi_frame;as C won't allow incomplete types in structs, even as the last member. We could improve this by breaking up the header, so the public API sees a different definition. Still a lie, but a more elegant one. typedefstruct{_PyGenObject_HEAD(gi) } PyGenObject;Private header: typedefstruct{_PyGenObject_HEAD(gi) InterpreterFramegi_frame} PyGenObject;Probably best done in a different PR, though. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Any type other than PyObject* would be better though :-). And if you replace the casts with a macro it’s easier to fix later. I have an idea for the macro but it’s too painful to type on a phone. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first field of Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| /* The code object backing the generator */ \ | ||
| PyCodeObject *prefix##_code; \ | ||
| /* List of weak reference. */ \ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Add new ``RETURN_GENERATOR`` bytecode to make generators. | ||
| Simplifies calling Python functions in the VM, as they no | ||
| longer any need to special case generator functions. | ||
| Also add ``JUMP_NO_INTERRUPT`` bytecode that acts like | ||
| ``JUMP_ABSOLUTE``, but does not check for interrupts. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.