-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macros: make
quote
a proper quasi-quoting operator (#1393)
## Summary `quote` now keeps the quoted block as is, which means that: * no symbols are bound or mixed in automatically from the enclosing scopes * identifiers in definition positions aren't turned into gensyms; they stay as is * `.gensym` and `.inject` pragmas within the quoted block don't affect the AST Symbols thus need to be bound or created explicitly, via `bindSym` and `genSym`, respectively. **This is a breaking change.** ## Details ### Motivation For The Change * symbols from the `quote`'s scope being bound is error-prone, leading to confusing compilation errors * the intention of documentation of `quote` already said it does quasi- quoting (even though it didn't) * the implementation relied on the intricacies of templates and template evaluation ### New Behaviour * quoted AST is not modified. No symbols are bound and no identifiers are turned into gensyms ### Implementation * `semQuoteAst` transforms the `quote` call into a call to the internal `quoteImpl` procedure * the pre-processed quoted AST is passed as the first arguments; the extracted unquoted expression are passed as the remaining arguments * the internal-only `evalToAst` magic procedure is used for evaluating the unquoted expressions. `newLit` cannot be used here, as the trees it produces for `object` values are only valid when all the type's fields are exported * placing the AST is of the evaluated unqouted expressions is handled in-VM, by `quoteImpl` ### Standard Library And Test Changes * multiple modules from the standard library relied on the previous symbol binding and gensym behaviour; they're changed to use `bindSym` or `genSym`. Outside-visible behaviour doesn't change * the `t7875.nim` test relied on the gensym behaviour. The definition outside the macro is not relevant to the issue the test guards against, so it can just be removed * the quoted ASTs in `tsizeof.nim` are wrapped in blocks in order to prevent the identifiers from colliding
- Loading branch information
Showing
16 changed files
with
135 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.