-
-
Notifications
You must be signed in to change notification settings - Fork 862
Fix a number of issues with compiler.rst #192
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
Conversation
compiler.rst
Outdated
1. Parse the source code into a parse tree (Parser/pgen.c) | ||
2. Emit bytecode based on the parse tree (Python/compile.c) | ||
1. Parse the source code into a parse tree (:file:`Parser/pgen.c`) | ||
2. Emit bytecode based on the parse tree (:file:`Python/compile.c`) |
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.
Delete history. It is irrelevant to current development.
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.
This comment is meant to be part of review below. I clicked wrong button when submitting it.
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.
Hm, just to make sure I do the correct amendment, are you suggesting I drop all historical references? In short, the section can start out with:
In CPython, the compilation from source code to bytecode involves three steps:
- Parse source code into a parse tree (Parser/pgen.c)
- Transform parse tree into an Abstract Syntax Tree (Python/ast.c)
- Transform AST into a Control Flow Graph (Python/compile.c)
- Emit bytecode based on the Control Flow Graph (Python/compile.c)
The purpose of this document is to outline how these three steps of the process work.
and continue with the rest as-is?
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.
I think that makes sense - RHEL/CentOS 5 was the last major platform still running Python 2.4, and that went End-of-Life in March.
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.
Yes. We have dropped almost all references to 2.x from 3.x docs (but the devguide is not versioned) and Nick confirmed my suspicion that a 2.4 reference is no longer needed for 2.x either. Not knowing the history, I found the current text it initially confusing.
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.
Remove ancient history irrelevant to current development.
compiler.rst
Outdated
1. Parse source code into a parse tree (:file:`Parser/pgen.c`) | ||
2. Transform parse tree into an Abstract Syntax Tree (:file:`Python/ast.c`) | ||
3. Transform AST into a Control Flow Graph (:file:`Python/compile.c`) | ||
4. Emit bytecode based on the Control Flow Graph (:file:`Python/compile.c`) | ||
|
||
Starting with Python 2.5, the above steps are now used. This change | ||
was done to simplify compilation by breaking it into three steps. |
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.
Delete these two lines.
Thanks for the review, Terry! I updated the Abstract to remove the historical reference. |
compiler.rst
Outdated
@@ -7,23 +7,14 @@ Design of CPython's Compiler | |||
Abstract | |||
-------- | |||
|
|||
Historically (through 2.4), compilation from source code to bytecode | |||
involved two steps: | |||
In CPython, the compilation from source code to bytecode involves three steps: |
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.
Shouldn't this be four steps as written?
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.
I was confused by that too TBH. From what I understand, Brett (who originally wrote this from what I know) considered the last two as a single step because, as stated later:
The conversion process is initiated by a call to the function PyAST_Compile() in Python/compile.c . This function does both the conversion of the AST to a CFG and outputting final bytecode from the CFG.
Maybe a sub-list would do the trick? I'd like to wait for feed-back before doing it, though :-)
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.
From the original, it should be 'involves four steps' and 'the latter three steps'. I intended those two phrasings to be kept.
Note 1. I am aware that this is not a general review of content, just of markup, but this opening was too annoying to ignore. I intentionally did not look at content further on ;-).
Note 2. I have not reviewed rst markup (have forgotten too much). Hope someone else will, and say so.
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.
Note 2.
I've reviewed the rst markup as well as run the file through restructuredtext_lint. Looks good.
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.
Feel free to just say "few" or "several" to avoid counting disagreements. 😉
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.
Thanks for the review @willingc (nice tool, too!). I updated the text to use 'several'.
compiler.rst
Outdated
Starting with Python 2.5, the above steps are now used. This change | ||
was done to simplify compilation by breaking it into three steps. | ||
The purpose of this document is to outline how the latter three steps | ||
The purpose of this document is to outline how these three steps |
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.
four?
Anything else I need to address with this PR? (Bump) |
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.
Some information is outdated, but this can be changed by other PR.
compiler.rst
Outdated
numbers, etc.) are kept in Include/token.h. The parse tree is made up | ||
of ``node *`` structs (as defined in Include/node.h). | ||
numbers, etc.) are kept in :file:`Include/token.h`. The parse tree is made up | ||
of ``node *`` structs (as defined in :file:`Include/node.h`). | ||
|
||
Querying data from the node structs can be done with the following | ||
macros (which are all defined in Include/node.h): |
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.
Highlight Include/node.h?
compiler.rst
Outdated
stmt arguments for 'body', and zero or more expr arguments for | ||
'decorators'. | ||
Modifiers on the argument type specify the number of values needed; ``?`` | ||
means it is optional, ``*`` means 0 or more while no modifier means only one |
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.
Is a comma before "while" needed?
compiler.rst
Outdated
@@ -209,29 +201,29 @@ one is working with (e.g., if you are working with an 'if' statement | |||
you need to watch out for the ':' token to find the end of the conditional). | |||
|
|||
The functions called to generate AST nodes from the parse tree all have | |||
the name ast_for_xx where xx is the grammar rule that the function | |||
handles (alias_for_import_name is the exception to this). These in turn | |||
the name ``ast_for_xx`` where xx is the grammar rule that the function |
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.
Emphasize xx: *xx*
. And in other cases below.
Maybe ast_for_xx can be formatted as: ``ast_for_``*xx*. But I don't know whether this works and how it looks.
compiler.rst
Outdated
that break the task down by various AST node types. The functions are | ||
all named compiler_visit_xx where xx is the name of the node type (such | ||
all named ``compiler_visit_xx`` where xx is the name of the node type (such | ||
as stmt, expr, etc.). Each function receives a ``struct compiler *`` | ||
and xx_ty where xx is the AST node type. Typically these functions |
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.
Highlight xx_ty.
@@ -371,23 +361,24 @@ bytecode step of the compiler. Several pieces of code throughout Python depend | |||
on having correct information about what bytecode exists. | |||
|
|||
First, you must choose a name and a unique identifier number. The official | |||
list of bytecode can be found in Include/opcode.h . If the opcode is to take | |||
list of bytecode can be found in :file:`Include/opcode.h`. If the opcode is to take |
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.
Highlight Include/opcode.h below?
compiler.rst
Outdated
will also need a new case statement for the new opcode in the big switch | ||
statement in PyEval_EvalFrameEx(). | ||
statement in ``PyEval_EvalFrameDefault``. |
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.
_PyEval_EvalFrameDefault()
Parser for ASDL definition files. Reads in an ASDL | ||
description and parses it into an AST that describes it. | ||
Parser for ASDL definition files. Reads in an ASDL description | ||
and parses it into an AST that describes it. |
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.
Highlight file paths below and remove spaces before periods.
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.
Could you update the PR?
Sorry for the delay, I've been swamped. Will address review by the weekend. |
Thank you for your PR @DimitrisJim. In the following PR I'll rewrite some outdated parts. |
Thanks @DimitrisJim 🍰 and @serhiy-storchaka for reviewing and merging ☀️ |
Closes #181.
The changes are:
:file:
directives where necessary.code-block: c
for the C snippet.NEW_BLOCK
and renameasdl_seq_new
to_Py_asdl_seq_new
.Some reformatting of the paragraphs also took place as needed when the previous changes where made.