You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
… interpreter (#4884)
# Description
## Problem\*
Resolves#4590
## Summary\*
This PR links up the comptime interpreter with the rest of the codebase.
It does so by adding a scanning step where the Hir is scanned for
`comptime` expressions to execute. When one of these is found, the
interpreter switches to evaluation mode and evaluates the expression.
Afterward, the result of the expression is inlined into the Hir via
`Value::into_expression`. For `Code` values, this means the entire code
block is spliced in (a macro expansion).
You can now run simple programs at compile-time now as long as they
don't have expansion of `quote`d values (macros) since those would
require the full loop back to name resolution again. Anyway, here's an
example that works now:
```rs
fn main() {
let x = comptime { 2 * 4 };
println(x);
}
```
By monomorphization the compiler sees
```rs
fn main() {
let x = 8;
println(x);
}
```
More complex expressions within the `comptime` block should also work.
Just note that this scanning + evaluation is currently only within
functions. So comptime globals won't be evaluated.
## Additional Context
I may try splitting out this PR into several smaller ones but need to
look into where to make the split more. Leaving this up for now in case
people find it useful or it's not as big as I expected.
Future changes:
Architecture-wise we're only missing the ability to make the full loop
and go back to name resolution after a macro expansion now. Since we
already have the Hir -> Ast pass (although it can be considerably
improved since it is rather broken still), we only need to call it after
the comptime interpreter and run name resolution again.
## Documentation\*
Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.
# PR Checklist\*
- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
Problem
After code is quoted, it needs a way to be unquoted to be inserted back into the program as runtime code.
Happy Case
Implement unquoting as described in https://hackmd.io/Tkzo_ryvTsWMPESmWHPiZw?view
Project Impact
None
Impact Context
No response
Workaround
None
Workaround Description
No response
Additional Context
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: