Reputation: 1894
I am just starting with Rust and was wondering: is a Rust interpreter? With an interpreter the Rust compiler would not need to compile all the source files every time it is invoked and would only interpret the code as it changed. It's how JavaScript and Python have no real compile time.
There's incremental compilation with Rust but it's still very slow with big projects. It would be a boon to GUI development with rust for the web IMO.
Upvotes: 22
Views: 12946
Reputation: 241
You can use evcxr. Try cargo install evcxr_repl. Then, in a new terminal, run evcxr. Then, type your rust code to evaluate. Panic does not cause the console to crash the entire program. Simply, you get an error and an explanation and you can retype the last part where you made the mistake. I find this useful when I want to test something small alongside my project where doing compilations would be too much of a hassle. E.g., to test how path joining works etc.
Upvotes: 19
Reputation: 88916
No, there is currently no Rust interpreter that can simply be used as a replacement for compiling with rustc
.
There is miri
which is an interpreter for MIR, the Rust "mid-level intermediate representation" (basically defining a control flow graph). The Rust compiler generates MIR code as part of its usual pipeline. This MIR code is usually translated to LLVM-IR next, which is then translated to machine code by LLVM. Miri allows to interpret that MIR code directly.
However, Miri is not really build for programmers to interpret their project instead of compiling it. At least not yet. Instead, it is built mainly to check unsafe code for undefined behavior: a dynamic code analysis tool/sanitizer. Additionally, Miri is still notably limited. In particular, last time I checked, extern "C"
calls were not supported.
I would also say that Rust is not as well suited to be completely interpret as other languages. The Rust compiler performs a fair amount of heavy analysis on the source code which has to be done at some point one way or another.
Upvotes: 7
Reputation: 1260
I think the closest thing to what you'd like to see is the Rust Language Server. Specifically, IDEs use this to feed in just the changes so that code compiles much faster.
There's also work on RLS 2.0 that you might be interested in watching / contributing to.
As far as UI / Web, that's a different ball of wax that I haven't had much luck with yet.
Upvotes: 5