Skip to content

Commit bd749ea

Browse files
committed
Use more platform checks
1 parent afd7a33 commit bd749ea

3 files changed

Lines changed: 80 additions & 64 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ clap = "2.31.2"
2525
rustpython-compiler = {path = "compiler", version = "0.1.0"}
2626
rustpython-parser = {path = "parser", version = "0.1.0"}
2727
rustpython-vm = {path = "vm", version = "0.1.0"}
28-
#rustyline = "4.1.0"
2928
xdg = "2.2.0"
3029

3130
flame = { version = "0.2", optional = true }
3231
flamescope = { version = "0.1", optional = true }
3332

33+
[target.'cfg(not(target_os = "redox"))'.dependencies]
34+
rustyline = "4.1.0"
35+
3436
[dev-dependencies.cpython]
3537
version = "0.2"
3638

src/main.rs

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustpython_vm::{
1616
util, VirtualMachine,
1717
};
1818

19-
//use rustyline::{error::ReadlineError, Editor};
2019
use std::io::{self, BufRead, Write};
2120
use std::path::PathBuf;
2221
use std::process;
@@ -299,76 +298,90 @@ fn get_prompt(vm: &VirtualMachine, prompt_name: &str) -> String {
299298
.unwrap_or_else(String::new)
300299
}
301300

301+
#[cfg(not(target_os = "redox"))]
302302
fn run_shell(vm: &VirtualMachine) -> PyResult {
303+
use rustyline::{error::ReadlineError, Editor};
304+
303305
println!(
304306
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
305307
crate_version!()
306308
);
307309
let vars = vm.new_scope_with_builtins();
308310

309-
// // Read a single line:
310-
// let mut input = String::new();
311-
// let mut repl = Editor::<()>::new();
312-
313-
// // Retrieve a `history_path_str` dependent on the OS
314-
// let repl_history_path_str = &get_history_path();
315-
// if repl.load_history(repl_history_path_str).is_err() {
316-
// println!("No previous history.");
317-
// }
318-
319-
// let mut continuing = false;
320-
321-
// loop {
322-
// let prompt = if continuing {
323-
// get_prompt(vm, "ps2")
324-
// } else {
325-
// get_prompt(vm, "ps1")
326-
// };
327-
// match repl.readline(&prompt) {
328-
// Ok(line) => {
329-
// debug!("You entered {:?}", line);
330-
// input.push_str(&line);
331-
// input.push('\n');
332-
// repl.add_history_entry(line.trim_end());
333-
334-
// if continuing {
335-
// if line.is_empty() {
336-
// continuing = false;
337-
// } else {
338-
// continue;
339-
// }
340-
// }
341-
342-
// match shell_exec(vm, &input, vars.clone()) {
343-
// Err(CompileError {
344-
// error: CompileErrorType::Parse(ParseErrorType::EOF),
345-
// ..
346-
// }) => {
347-
// continuing = true;
348-
// continue;
349-
// }
350-
// _ => {
351-
// input = String::new();
352-
// }
353-
// }
354-
// }
355-
// Err(ReadlineError::Interrupted) => {
356-
// // TODO: Raise a real KeyboardInterrupt exception
357-
// println!("^C");
358-
// continuing = false;
359-
// continue;
360-
// }
361-
// Err(ReadlineError::Eof) => {
362-
// break;
363-
// }
364-
// Err(err) => {
365-
// println!("Error: {:?}", err);
366-
// break;
367-
// }
368-
// };
369-
// }
370-
// repl.save_history(repl_history_path_str).unwrap();
311+
// Read a single line:
312+
let mut input = String::new();
313+
let mut repl = Editor::<()>::new();
371314

315+
// Retrieve a `history_path_str` dependent on the OS
316+
let repl_history_path_str = &get_history_path();
317+
if repl.load_history(repl_history_path_str).is_err() {
318+
println!("No previous history.");
319+
}
320+
321+
let mut continuing = false;
322+
323+
loop {
324+
let prompt = if continuing {
325+
get_prompt(vm, "ps2")
326+
} else {
327+
get_prompt(vm, "ps1")
328+
};
329+
match repl.readline(&prompt) {
330+
Ok(line) => {
331+
debug!("You entered {:?}", line);
332+
input.push_str(&line);
333+
input.push('\n');
334+
repl.add_history_entry(line.trim_end());
335+
336+
if continuing {
337+
if line.is_empty() {
338+
continuing = false;
339+
} else {
340+
continue;
341+
}
342+
}
343+
344+
match shell_exec(vm, &input, vars.clone()) {
345+
Err(CompileError {
346+
error: CompileErrorType::Parse(ParseErrorType::EOF),
347+
..
348+
}) => {
349+
continuing = true;
350+
continue;
351+
}
352+
_ => {
353+
input = String::new();
354+
}
355+
}
356+
}
357+
Err(ReadlineError::Interrupted) => {
358+
// TODO: Raise a real KeyboardInterrupt exception
359+
println!("^C");
360+
continuing = false;
361+
continue;
362+
}
363+
Err(ReadlineError::Eof) => {
364+
break;
365+
}
366+
Err(err) => {
367+
println!("Error: {:?}", err);
368+
break;
369+
}
370+
};
371+
}
372+
repl.save_history(repl_history_path_str).unwrap();
373+
374+
Ok(vm.get_none())
375+
}
376+
377+
#[cfg(target_os = "redox")]
378+
fn run_shell(vm: &VirtualMachine) -> PyResult {
379+
println!(
380+
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
381+
crate_version!()
382+
);
383+
let vars = vm.new_scope_with_builtins();
384+
372385
let stdin = io::stdin();
373386
let stdout = io::stdout();
374387
let mut stdout = stdout.lock();

vm/src/stdlib/os.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ fn os_stat(
612612
target_os = "linux",
613613
target_os = "macos",
614614
target_os = "android",
615+
target_os = "redox",
615616
windows
616617
)))]
617618
fn os_stat(

0 commit comments

Comments
 (0)