@@ -12,7 +12,6 @@ use rustpython_parser::parser;
1212use rustpython_vm:: { VirtualMachine , Executor } ;
1313use rustpython_vm:: compile;
1414use rustpython_vm:: eval:: eval;
15- use rustpython_vm:: pyobject:: PyObjectRef ;
1615use std:: io;
1716use std:: io:: prelude:: * ;
1817use std:: path:: Path ;
@@ -49,7 +48,13 @@ fn run_script(script_file: &String) {
4948 let code_obj = compile:: compile ( & mut vm, & source, compile:: Mode :: Exec ) . unwrap ( ) ;
5049 debug ! ( "Code object: {:?}" , code_obj. borrow( ) ) ;
5150 let vars = vm. new_dict ( ) ; // Keep track of local variables
52- vm. run_code_obj ( code_obj, vars) ;
51+ match vm. run_code_obj ( code_obj, vars) {
52+ Ok ( _value) => {
53+ }
54+ Err ( exc) => {
55+ panic ! ( "Exception: {:?}" , exc) ;
56+ }
57+ }
5358 }
5459 Err ( msg) => {
5560 error ! ( "Parsing went horribly wrong: {}" , msg) ;
@@ -70,13 +75,20 @@ fn run_shell() {
7075 let mut input = String :: new ( ) ;
7176 print ! ( ">>>>> " ) ; // Use 5 items. pypy has 4, cpython has 3.
7277 io:: stdout ( ) . flush ( ) . ok ( ) . expect ( "Could not flush stdout" ) ;
73- io:: stdin ( ) . read_line ( & mut input) ;
74- // input = input.trim().to_string();
75- debug ! ( "You entered {:?}" , input) ;
76- let result = eval ( & mut vm, & input, vars. clone ( ) ) ;
77- match result {
78- Ok ( value) => println ! ( "{}" , vm. to_str( value) ) ,
79- Err ( value) => println ! ( "Error: {:?}" , value) ,
78+ match io:: stdin ( ) . read_line ( & mut input) {
79+ Ok ( 0 ) => {
80+ break ;
81+ }
82+ Ok ( _) => {
83+ debug ! ( "You entered {:?}" , input) ;
84+ match eval ( & mut vm, & input, vars. clone ( ) ) {
85+ Ok ( value) => println ! ( "{}" , vm. to_str( value) ) ,
86+ Err ( value) => println ! ( "Error: {:?}" , value) ,
87+ } ;
88+ }
89+ Err ( msg) => {
90+ panic ! ( "Error: {:?}" , msg)
91+ }
8092 } ;
8193 }
8294}
0 commit comments