Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements modules for the VM. (WIP)
Interruption
Rust
, in Motoko, all names in super scopes flow into subscopes.Unlike other constructs, modules require doing a lot of steps that do not correspond to ordinary execution, but rather, correspond to phases just before or during type checking.
These steps are necessary to resolve identifiers and module projections in real Motoko programs, and involve resolving nested recursive definitions.
Each named module definition introduces a recursive scope that we construct incrementally, in a step-wise manner. When they nest, additional steps propagate the recursion between the nested levels.
Why?
We could eschew a step-based approach, and do the module-level resolution of paths in a batch style, with batch-style errors each time an identifier is used twice. However, that has two drawbacks:
let box
; as with modules, they would step before the program evaluates.Scoping using nested
module
sConsider this nested
module
declaration:Notice:
X.M.g
can "see"Y.y
andY.Z.z
.Y.Z.z
can "see" function "y" and also see the same function asY.y
.X.N.g
can "see"Y.y
but notZ.z
(Y.Z.z()
works though)This example could be smaller and simpler. It's something I have been using as I poke at the compiler to test my understanding of the language, and having it be about this large as been helpful.