Comments (8)
Now that I gave more thoughts I like the idea of splitting the interpreter in its own crate.
I imagnie the API will looks something like
pub struct Repl{/**/}
impl Repl {
pub fn new() -> Self {/**/}
pub fn append(&mut self, code: &str) {/**/}
pub fn eval(&self, code: &str) -> Result<String> {/**/}
pub fn eval_without_context(&self, code: &str) -> Result<String> {/**/}
/**/
}
#[test]
fn test_repl() {
let mut repl = Repl::new();
repl.append(stringify!(let x = "hello";))
assert_eq!(repl.eval("x"),Ok("hello"))
assert!(repl.eval_without_context("x").is_err())
}
The main logic is in two files https://github.com/sigmaSd/IRust/blob/master/src/irust/repl.rs https://github.com/sigmaSd/IRust/blob/master/src/irust/cargo_cmds.rs
from irust.
Btw the above interactive example is equivalant to using IRust :load
/:reload
commands
from irust.
Hello,
Thanks for cheking this out!
IRust interpeter is just println!("{}", expression)
for a real repl in this regard check out https://github.com/google/evcxr/ it has jupyter notrbook support which might be what you want
Basicly the idea behind IRust is instead of focusing on the interpeter (since its relly hard for a compiled language) it focus on the exprience Ipython like, also the advantage is even the output is a slow compared to what someone is used to like from other repls, it is guatenteed to be correct ( also I tried cranelift backend and it improves the situation)
So back to your question, here are a couple of ideas:
There are crates that run the rust code like cargo script, alternatively with IRust here is whats currently possible:
- first there is the
:edit
command that you can use to edit the repl content in an external editor - there is also
:load
that takes a rust file and put it as is inside the repl :add
is actually useful here you can use it inside the project your editing like this ':add .' and it will add it as a dependency
from irust.
Here is a prototype https://github.com/sigmaSd/IRust/tree/irust_repl
There is now a split crate irust_repl
(The only required dependency for now is once_cell)
There are a lot of functions in the API due to how to IRust uses it, but for normal usage it would look something like:
use irust_repl::Repl;
use irust_repl::cargo_cmds::ToolChain;
let mut repl = Repl::new();
repl.insert("let a = 5+4;");
assert_eq!(repl.eval("a", ToolChain::Stable), 9);
assert_eq!(repl.eval(1+1, ToolChain::Beta), 2);
For the interactive usage use case it would be something like
//in psuedo code
let repl = Arc::new(Mutex::new(Repl::new()));
spawn_thread:
loop {
watch(script_file)
if file_changed:
// Invalidate the repl on any change
repl.reset();
repl.insert(std::fs::read_file(script_file))
}
main_thread:
loop {
let input = read_stdin();
let output = repl.eval(input);
print(output)
}
from irust.
from irust.
I evaluated the options and the one that seems the most convenient with IRust is using :add $Path_to_project
Here is a little guide https://sigmasd.github.io/irust_book/interactive-usage/
from irust.
@Boscop You might look into Rune or Rhai, both of which are Rust-like scripting languages designed for easy embedding into Rust programs.
from irust.
I believe this can be closed now, feel free to reopen if needed.
from irust.
Related Issues (20)
- Use `rustyline` or `reedline` for input? HOT 1
- Move theme settings from config.toml to themes config
- Improve Jupyter kernel support HOT 7
- typing twice in windows with crossterm-0.26+ HOT 2
- Can irust repl evaluate code with release mode instead of debug mode? HOT 3
- Cannot use two `irust_repl`s at the same time. HOT 27
- Rust analyzer is not working on Windows HOT 6
- Interactive usage HOT 3
- IRust installation fails due to use of unstable library feature 'once_cell' HOT 3
- FileNotFoundError while `python -m irust_kernel.install` HOT 1
- cargo-edit requires --path argument for a local dependency after version 0.9.1 HOT 2
- irust doesn't display Thai text properly. HOT 1
- Unclear documentation on importing local crates HOT 5
- Autocomplete doesn't work HOT 10
- untitled issue HOT 4
- Proposal: Split eval output HOT 3
- Option to specify config.toml path HOT 6
- Support nREPL protocol? HOT 2
- Failed to format error output HOT 2
- Logo missing on Jupyter lab launcher page HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from irust.