@@ -8,9 +8,7 @@ use clap::{App, AppSettings, Arg, ArgMatches};
8
8
use rustpython_compiler:: { compile, error:: CompileError , error:: CompileErrorType } ;
9
9
use rustpython_parser:: error:: ParseErrorType ;
10
10
use rustpython_vm:: {
11
- import,
12
- obj:: objstr:: PyStringRef ,
13
- print_exception,
11
+ import, print_exception,
14
12
pyobject:: { ItemProtocol , PyObjectRef , PyResult } ,
15
13
scope:: Scope ,
16
14
util, PySettings , VirtualMachine ,
@@ -463,13 +461,6 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul
463
461
}
464
462
}
465
463
466
- fn get_prompt ( vm : & VirtualMachine , prompt_name : & str ) -> Option < PyStringRef > {
467
- vm. get_attribute ( vm. sys_module . clone ( ) , prompt_name)
468
- . and_then ( |prompt| vm. to_str ( & prompt) )
469
- . ok ( )
470
- }
471
-
472
- #[ cfg( not( target_os = "redox" ) ) ]
473
464
fn run_shell ( vm : & VirtualMachine , scope : Scope ) -> PyResult < ( ) > {
474
465
use rustyline:: { error:: ReadlineError , Editor } ;
475
466
@@ -505,14 +496,13 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
505
496
let mut continuing = false ;
506
497
507
498
loop {
508
- let prompt = if continuing {
509
- get_prompt ( vm, "ps2" )
510
- } else {
511
- get_prompt ( vm, "ps1" )
512
- } ;
499
+ let prompt_name = if continuing { "ps2" } else { "ps1" } ;
500
+ let prompt = vm
501
+ . get_attribute ( vm. sys_module . clone ( ) , prompt_name)
502
+ . and_then ( |prompt| vm. to_str ( & prompt) ) ;
513
503
let prompt = match prompt {
514
- Some ( ref s) => s. as_str ( ) ,
515
- None => "" ,
504
+ Ok ( ref s) => s. as_str ( ) ,
505
+ Err ( _ ) => "" ,
516
506
} ;
517
507
let result = match repl. readline ( prompt) {
518
508
Ok ( line) => {
@@ -577,39 +567,3 @@ fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
577
567
578
568
Ok ( ( ) )
579
569
}
580
-
581
- #[ cfg( target_os = "redox" ) ]
582
- fn run_shell ( vm : & VirtualMachine , scope : Scope ) -> PyResult < ( ) > {
583
- use std:: io:: { self , BufRead , Write } ;
584
-
585
- println ! (
586
- "Welcome to the magnificent Rust Python {} interpreter!" ,
587
- crate_version!( )
588
- ) ;
589
-
590
- fn print_prompt ( vm : & VirtualMachine ) {
591
- let prompt = get_prompt ( vm, "ps1" ) ;
592
- let prompt = match prompt {
593
- Some ( ref s) => s. as_str ( ) ,
594
- None => "" ,
595
- } ;
596
- print ! ( "{}" , prompt) ;
597
- io:: stdout ( ) . lock ( ) . flush ( ) . expect ( "flush failed" ) ;
598
- }
599
-
600
- let stdin = io:: stdin ( ) ;
601
-
602
- print_prompt ( vm) ;
603
- for line in stdin. lock ( ) . lines ( ) {
604
- let mut line = line. expect ( "line failed" ) ;
605
- line. push_str ( "\n " ) ;
606
- match shell_exec ( vm, & line, scope. clone ( ) ) {
607
- ShellExecResult :: Ok => { }
608
- ShellExecResult :: Continue => println ! ( "Unexpected EOF" ) ,
609
- ShellExecResult :: PyErr ( exc) => print_exception ( vm, & exc) ,
610
- }
611
- print_prompt ( vm) ;
612
- }
613
-
614
- Ok ( ( ) )
615
- }
0 commit comments