-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
345 additions
and
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
use dash_middle::parser::error::IntoFormattableErrors; | ||
use dash_optimizer::OptLevel; | ||
use dash_rt::format_value; | ||
use dash_rt::runtime::Runtime; | ||
use dash_vm::eval::EvalError; | ||
use dash_vm::value::Root; | ||
use dash_vm::Vm; | ||
use rustyline::Editor; | ||
|
||
pub fn repl() -> anyhow::Result<()> { | ||
let mut rl = Editor::<()>::new(); | ||
|
||
let mut vm = Vm::new(Default::default()); | ||
let mut scope = vm.scope(); | ||
tokio::runtime::Runtime::new()?.block_on(async move { | ||
let mut rt = Runtime::new(None); | ||
|
||
while let Ok(input) = rl.readline("> ") { | ||
if input.is_empty() { | ||
continue; | ||
} | ||
while let Ok(input) = rl.readline("> ") { | ||
if input.is_empty() { | ||
continue; | ||
} | ||
|
||
rl.add_history_entry(&input); | ||
rl.add_history_entry(&input); | ||
|
||
match scope.eval(&input, OptLevel::Aggressive) { | ||
Ok(value) => println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap()), | ||
Err(EvalError::Exception(value)) => { | ||
println!("{}", format_value(value.root(&mut scope), &mut scope).unwrap()) | ||
} | ||
Err(EvalError::Middle(errs)) => println!("{}", errs.formattable(&input, true)), | ||
} | ||
rt.vm_mut().with_scope(|scope| { | ||
match scope.eval(&input, OptLevel::Aggressive) { | ||
Ok(value) => println!("{}", format_value(value.root(scope), scope).unwrap()), | ||
Err(EvalError::Exception(value)) => { | ||
println!("{}", format_value(value.root(scope), scope).unwrap()) | ||
} | ||
Err(EvalError::Middle(errs)) => println!("{}", errs.formattable(&input, true)), | ||
} | ||
|
||
scope.process_async_tasks(); | ||
} | ||
scope.process_async_tasks(); | ||
}); | ||
} | ||
}); | ||
|
||
Ok(()) | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.