@@ -38,25 +38,26 @@ fn main() {
3838 }
3939}
4040
41- fn run_script ( script_file : & String ) {
41+ fn _run_string ( source : & String ) {
4242 let mut vm = VirtualMachine :: new ( ) ;
43+ let code_obj = compile:: compile ( & mut vm, & source, compile:: Mode :: Exec ) . unwrap ( ) ;
44+ debug ! ( "Code object: {:?}" , code_obj. borrow( ) ) ;
45+ let builtins = vm. get_builtin_scope ( ) ;
46+ let vars = vm. new_scope ( Some ( builtins) ) ; // Keep track of local variables
47+ match vm. run_code_obj ( code_obj, vars) {
48+ Ok ( _value) => { }
49+ Err ( exc) => {
50+ panic ! ( "Exception: {:?}" , exc) ;
51+ }
52+ }
53+ }
54+
55+ fn run_script ( script_file : & String ) {
4356 debug ! ( "Running file {}" , script_file) ;
4457 // Parse an ast from it:
4558 let filepath = Path :: new ( script_file) ;
4659 match parser:: read_file ( filepath) {
47- Ok ( source) => {
48- let code_obj = compile:: compile ( & mut vm, & source, compile:: Mode :: Exec ) . unwrap ( ) ;
49- debug ! ( "Code object: {:?}" , code_obj. borrow( ) ) ;
50- let builtins = vm. get_builtin_scope ( ) ;
51- let vars = vm. new_scope ( Some ( builtins) ) ; // Keep track of local variables
52- match vm. run_code_obj ( code_obj, vars) {
53- Ok ( _value) => {
54- }
55- Err ( exc) => {
56- panic ! ( "Exception: {:?}" , exc) ;
57- }
58- }
59- }
60+ Ok ( source) => _run_string ( & source) ,
6061 Err ( msg) => {
6162 error ! ( "Parsing went horribly wrong: {}" , msg) ;
6263 std:: process:: exit ( 1 ) ;
0 commit comments