Skip to content

Commit

Permalink
update READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 28, 2023
1 parent aff2fc1 commit a37fc0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
20 changes: 0 additions & 20 deletions vyper/ast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ and parsing NatSpec docstrings.

* [`annotation.py`](annotation.py): Contains the `AnnotatingVisitor` class, used to
annotate and modify the Python AST prior to converting it to a Vyper AST.
* [`folding.py`](folding.py): Functions for evaluating and replacing literal
nodes within the Vyper AST.
* [`natspec.py`](natspec.py): Functions for parsing NatSpec docstrings within the
source.
* [`nodes.py`](nodes.py): Contains the Vyper node classes, and the `get_node`
Expand Down Expand Up @@ -70,24 +68,6 @@ or parents that match a desired pattern.
To learn more about these methods, read their docstrings in the `VyperNode` class
in [`nodes.py`](nodes.py).

### Modifying the AST

[`folding.py`](folding.py) contains the `fold` function, a high-level method called
to evaluating and replacing literal nodes within the AST. Some examples of literal
folding include:

* arithmetic operations (`3+2` becomes `5`)
* references to literal arrays (`["foo", "bar"][1]` becomes `"bar"`)
* builtin functions applied to literals (`min(1,2)` becomes `1`)

The process of literal folding includes:

1. Foldable node classes are evaluated via their `fold` method, which attempts to create a new `Constant` from the content of the given node.
2. Replacement nodes are generated using the `from_node` class method within the new
node class.
3. The modification of the tree is handled by `Module.replace_in_tree`, which locates
the existing node and replaces it with a new one.

## Design

### `__slots__`
Expand Down
2 changes: 0 additions & 2 deletions vyper/compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ The compilation process includes the following broad phases:

1. In [`vyper.ast`](../ast), the source code is parsed and converted to an
abstract syntax tree.
1. In [`vyper.ast.folding`](../ast/folding.py), literal Vyper AST nodes are
evaluated and replaced with the resulting values.
1. The [`GlobalContext`](../codegen/global_context.py) object is generated from the
Vyper AST, analyzing and organizing the nodes prior to IR generation.
1. In [`vyper.codegen.module`](../codegen/module.py), the contextualized nodes are
Expand Down
29 changes: 20 additions & 9 deletions vyper/semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Vyper abstract syntax tree (AST).
* [`data_positions`](analysis/data_positions.py): Functions for tracking storage variables and allocating storage slots
* [`levenhtein_utils.py`](analysis/levenshtein_utils.py): Helper for better error messages
* [`local.py`](analysis/local.py): Validates the local namespace of each function within a contract
* [`pre_typecheck.py`](analysis/pre_typecheck.py): Evaluate foldable nodes and populate their metadata with the replacement nodes.
* [`module.py`](analysis/module.py): Validates the module namespace of a contract.
* [`utils.py`](analysis/utils.py): Functions for comparing and validating types
* [`data_locations.py`](data_locations.py): `DataLocation` object for type location information
Expand All @@ -35,13 +36,23 @@ Vyper abstract syntax tree (AST).

The [`analysis`](analysis) subpackage contains the top-level `validate_semantics`
function. This function is used to verify and type-check a contract. The process
consists of three steps:
consists of four steps:

1. Preparing the builtin namespace
2. Validating the module-level scope
3. Annotating and validating local scopes
1. Populating the metadata of foldable nodes with their replacement nodes
2. Preparing the builtin namespace
3. Validating the module-level scope
4. Annotating and validating local scopes

### 1. Preparing the builtin namespace
### 1. Populating the metadata of foldable nodes with their replacement nodes

[`analysis/pre_typecheck.py`](analysis/pre_typecheck.py) populates the metadata of foldable nodes with their replacement nodes.

This process includes:
1. Foldable node classes and builtin functions are evaluated via their `fold` method, which attempts to create a new `Constant` from the content of the given node.
2. Replacement nodes are generated using the `from_node` class method within the new
node class.

### 2. Preparing the builtin namespace

The [`Namespace`](namespace.py) object represents the namespace for a contract.
Builtins are added upon initialization of the object. This includes:
Expand All @@ -51,19 +62,19 @@ Builtins are added upon initialization of the object. This includes:
* Adding builtin functions from the [`functions`](../builtins/functions.py) package
* Adding / resetting `self` and `log`

### 2. Validating the Module Scope
### 3. Validating the Module Scope

[`validation/module.py`](validation/module.py) validates the module-level scope
[`analysis/module.py`](analysis/module.py) validates the module-level scope
of a contract. This includes:

* Generating user-defined types (e.g. structs and interfaces)
* Creating type definitions for storage variables, user-defined constants, events
and functions
* Validating import statements and function signatures

### 3. Annotating and validating the Local Scopes
### 4. Annotating and validating the Local Scopes

[`validation/local.py`](validation/local.py) validates the local scope within each
[`analysis/local.py`](analysis/local.py) validates the local scope within each
function in a contract. `FunctionNodeVisitor` is used to iterate over the statement
nodes in each function body, annotate them and apply appropriate checks.

Expand Down

0 comments on commit a37fc0e

Please sign in to comment.