1
0
Fork 0
forked from AbleOS/ableos

Working Rhai REPL

This commit is contained in:
Erin 2022-02-18 19:12:07 +01:00 committed by ondra05
parent 38a8ae6e20
commit bdd866eafe
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(