Working Rhai REPL

master
ondra05 2022-02-18 19:12:07 +01:00
parent 619e4061c7
commit 5910abb4f7
2 changed files with 21 additions and 8 deletions

View File

@ -90,6 +90,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
// Backspace
8 => {
WRITER.lock().backspace();
KEYBUFF.lock().push(8_u8 as _);
// print!(" ");
// WRITER.lock().backspace();
}

View File

@ -36,7 +36,7 @@ pub fn scratchpad() {
*/
// interp();
// rhai_shell();
rhai_shell();
}
pub struct PciIO {}
@ -94,16 +94,28 @@ impl ProcessMessage {
*/
pub fn rhai_shell() {
let mut engine = rhai::Engine::new();
let engine = rhai::Engine::new();
let mut buf = String::new();
print!("> ");
let ret = engine.eval::<i64>("1 + 2");
loop {
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
Some('\n') => {
match engine.eval::<rhai::Dynamic>(&buf) {
Ok(o) => println!("{o}"),
Err(e) => println!("Eval error: {e}"),
};
match ret {
Ok(x) => println!("{}", x),
Err(e) => println!("{}", e),
buf.clear();
print!("> ");
}
Some('\u{0008}') => {
buf.pop();
}
Some(chr) => buf.push(chr),
None => (),
}
}
loop {}
}
lazy_static::lazy_static!(
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(