Skip to content

Commit cc99c38

Browse files
committed
Add subsections to Understanding Internals
1 parent 2426440 commit cc99c38

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

DEVELOPMENT.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ code accordingly. We also use [clippy](https://github.com/rust-lang/rust-clippy)
4141
to detect rust code issues.
4242

4343
Python code should follow the
44-
[PEP 8](https://www.python.org/dev/peps/pep-0008/) style.
44+
[PEP 8](https://www.python.org/dev/peps/pep-0008/) style. We also use
45+
[flake8](http://flake8.pycqa.org/en/latest/) to check Python code style.
4546

4647
## Testing
4748

@@ -107,22 +108,46 @@ repository's structure:
107108

108109
## Understanding Internals
109110

110-
Rust crates
111-
rustpython: top level crate
112-
rustpython_parser
113-
rustpython-vm (source is found in `vm/src`)
111+
The RustPython package is the `rustpython` top-level crate. The `Cargo.toml`
112+
file in the root of the repo provide configuration of the crate and the
113+
implementation is found in the `src` directory (specifically,
114+
`src/main.rs`).
114115

115-
Lexer, Parser, AST (Abstract Syntax Tree)
116+
The top-level `rustpython` depends on several lower-level crates including:
117+
118+
- `rustpython-parser` (source: `parser/src`)
119+
- `rustpython-compiler` (source:`compiler/src`)
120+
- `rustpython-vm` (source: `vm/src`)
121+
122+
Together, these crates provide the functions of a programming language and
123+
enable a line of code to go through a series of steps:
124+
125+
- parse the line of source code into tokens
126+
- determine if the tokens are valid syntax
127+
- create an Abstract Syntax Tree (AST)
128+
- compile the AST into bytecode
129+
- execute the bytecode in the virtual machine (VM).
130+
131+
### rustpython-parser
132+
133+
This crate contains the lexer and parser to convert a line of code to
134+
an Abstract Syntax Tree (AST):
116135
- Lexer: `parser/lexer.rs` converts Python source code into tokens
117136
- Parser: Takes the tokens generated by the lexer and parses the tokens
118137
into an AST (Abstract Syntax Tree) where the nodes of the syntax tree
119-
are Rust structs and enums
138+
are Rust structs and enums.
120139
- The Parser relies on `LALRPOP`, a Rust parser generator framework
121140
- More information on parsers and a tutorial can be found in the
122141
[LALRPOP book](https://lalrpop.github.io/lalrpop/README.html).
142+
- AST: `parser/ast.rs` implements Python types and expressions
143+
represented in by the AST nodes in Rust.
144+
145+
### rustpython-compiler
123146

124-
Compiler
125147
Generates bytecode from the AST
148+
(source is found in `compiler/src`) is primarily used to transform AST (Abstract Syntax Tree to bytecode)
149+
150+
### rustpython-vm
126151

127152
VM (Virtual Machine)
128153
Fetch and dispatch loop

0 commit comments

Comments
 (0)