Skip to content

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

Merged
merged 5 commits into from
Jul 3, 2017
Merged

Fix a number of issues with compiler.rst #192

merged 5 commits into from
Jul 3, 2017

Conversation

DimitrisJim
Copy link
Contributor

Closes #181.

The changes are:

  • Use :file: directives where necessary.
  • Use backticks for Function names/macros/types.
  • Add a code-block: c for the C snippet.
  • Add arguments to all macro/function signatures.
  • Remove obsolete macros NEW_BLOCK and rename asdl_seq_new to _Py_asdl_seq_new.

Some reformatting of the paragraphs also took place as needed when the previous changes where made.

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`)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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:

  1. Parse source code into a parse tree (Parser/pgen.c)
  2. Transform parse tree into an Abstract Syntax Tree (Python/ast.c)
  3. Transform AST into a Control Flow Graph (Python/compile.c)
  4. 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?

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

@terryjreedy terryjreedy left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

Delete these two lines.

@DimitrisJim
Copy link
Contributor Author

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

@DimitrisJim DimitrisJim May 8, 2017

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 :-)

Copy link
Member

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.

Copy link
Collaborator

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.

Copy link
Member

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. 😉

Copy link
Contributor Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

four?

@DimitrisJim
Copy link
Contributor Author

Anything else I need to address with this PR? (Bump)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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):
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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``.
Copy link
Member

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.
Copy link
Member

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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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?

@DimitrisJim
Copy link
Contributor Author

DimitrisJim commented Jun 27, 2017

Sorry for the delay, I've been swamped. Will address review by the weekend.

@serhiy-storchaka serhiy-storchaka merged commit 384bb4b into python:master Jul 3, 2017
@serhiy-storchaka
Copy link
Member

Thank you for your PR @DimitrisJim. In the following PR I'll rewrite some outdated parts.

@willingc
Copy link
Collaborator

willingc commented Jul 3, 2017

Thanks @DimitrisJim 🍰 and @serhiy-storchaka for reviewing and merging ☀️

AA-Turner pushed a commit to AA-Turner/devguide that referenced this pull request Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants