pub fn repl(streams: Vec<(&str, RefCell<Stream>)>) {
    let mut globals: Vec<RefValue> = Vec::new();

    let mut compiler = Compiler::new();
    compiler.interactive = true;

    // todo: Implement a completer?
    let mut readline = Editor::<()>::new();

    // todo: Implement a history in $HOME for production?
    if cfg!(debug_assertions) {
        readline.load_history(".tokayhist").ok();
    }

    loop {
        let code = match readline.readline(">>> ") {
            Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break,

            Err(err) => {
                println!("Error {:?}", err);
                break;
            }

            Ok(code) => code,
        };

        // Stop when program is empty.
        if code.trim().is_empty() {
            continue;
        }

        //println!("code = {:?}", code);

        readline.add_history_entry(code.as_str());

        match code.as_str() {
            /*
            "#debug" => {
                compiler.debug = 1;
                println!("<<< Debug switched on")
            }
            "#nodebug" => {
                compiler.debug = 0;
                println!("<<< Debug switched off")
            }
            */
            _ => {
                if let Ok(program) = compiler.compile(Reader::new(Box::new(io::Cursor::new(code))))
                {
                    for (name, stream) in &streams {
                        let mut reader = stream.borrow_mut().get_reader();
                        let mut runtime = Runtime::new(&program, &mut reader);
                        runtime.debug = compiler.debug;
                        runtime.load_stack(globals);

                        let ret = program.run(&mut runtime);

                        if streams.len() > 1 {
                            print!("{}: ", name);
                        }

                        match ret {
                            Ok(None) => {
                                if streams.len() > 1 {
                                    print!("\n")
                                }
                            }
                            Ok(Some(value)) => println!("{}", value),
                            Err(error) => println!("{}", error),
                        }

                        globals = runtime.save_stack();
                    }
                }
            }
        }
    }

    if cfg!(debug_assertions) {
        readline.save_history(".tokayhist").unwrap();
    }
}
// A first simple REPL for Tokay
A first simple REPL for Tokay
A first simple REPL for Tokay
pub fn repl(streams: Vec<(&str, RefCell<Stream>)>) {
    let mut globals: Vec<RefValue> = Vec::new();
    let mut compiler = Compiler::new();
    compiler.interactive = true;
    // todo: Implement a completer?
    let mut readline = Editor::<()>::new();
    // todo: Implement a history in $HOME for production?
    if cfg!(debug_assertions) {
        readline.load_history(".tokayhist").ok();
    }
    loop {
        let code = match readline.readline(">>> ") {
            Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break,
            Err(err) => {
                println!("Error {:?}", err);
                break;
            }
            Ok(code) => code,
        };
        // Stop when program is empty.
        if code.trim().is_empty() {
            continue;
        }
        //println!("code = {:?}", code);
        readline.add_history_entry(code.as_str());
        match code.as_str() {
            /*
            "#debug" => {
                compiler.debug = 1;
                println!("<<< Debug switched on")
            }
            "#nodebug" => {
                compiler.debug = 0;
                println!("<<< Debug switched off")
            }
            */
            _ => {
                if let Ok(program) = compiler.compile(Reader::new(Box::new(io::Cursor::new(code))))
                {
                    for (name, stream) in &streams {
                        let mut reader = stream.borrow_mut().get_reader();
                        let mut runtime = Runtime::new(&program, &mut reader);
                        runtime.debug = compiler.debug;
                        runtime.load_stack(globals);
                        let ret = program.run(&mut runtime);
                        if streams.len() > 1 {
                            print!("{}: ", name);
                        }
                        match ret {
                            Ok(None) => {
                                if streams.len() > 1 {
                                    print!("\n")
                                }
                            }
                            Ok(Some(value)) => println!("{}", value),
                            Err(error) => println!("{}", error),
                        }
                        globals = runtime.save_stack();
                    }
                }
            }
        }
    }
    if cfg!(debug_assertions) {
        readline.save_history(".tokayhist").unwrap();
    }
}
pub fn repl ( streams : Vec < ( & str , RefCell < Stream > ) > ) { let mut globals : Vec < RefValue > = Vec :: new ( ) ; let mut compiler = Compiler :: new ( ) ; compiler . interactive = true ; // todo: Implement a completer? let mut readline = Editor :: < ( ) > :: new ( ) ; // todo: Implement a history in $HOME for production? if cfg ! ( debug_assertions ) { readline . load_history ( " " ) . ok ( ) ; } loop { let code = match readline . readline ( " " ) { Err ( ReadlineError :: Interrupted ) | Err ( ReadlineError :: Eof ) => break , Err ( err ) => { println ! ( " " err ) ; break ; } Ok ( code ) => code , } ; // Stop when program is empty. if code . trim ( ) . is_empty ( ) { continue ; } //println!("code = {:?}", code); readline . add_history_entry ( code . as_str ( ) ) ; match code . as_str ( ) { /*
            "#debug" => {
                compiler.debug = 1;
                println!("<<< Debug switched on")
            }
            "#nodebug" => {
                compiler.debug = 0;
                println!("<<< Debug switched off")
            }
            */ _ => { if let Ok ( program ) = compiler . compile ( Reader :: new ( Box :: new ( io :: Cursor :: new ( code ) ) ) ) { for ( name , stream ) in & streams { let mut reader = stream . borrow_mut ( ) . get_reader ( ) ; let mut runtime = Runtime :: new ( & program , & mut reader ) ; runtime . debug = compiler . debug ; runtime . load_stack ( globals ) ; let ret = program . run ( & mut runtime ) ; if streams . len ( ) > 1 { print ! ( " " name ) ; } match ret { Ok ( None ) => { if streams . len ( ) > 1 { print ! ( " \n " ) } } Ok ( Some ( value ) ) => println ! ( " " value ) , Err ( error ) => println ! ( " " error ) , } globals = runtime . save_stack ( ) ; } } } } } if cfg ! ( debug_assertions ) { readline . save_history ( " " ) . unwrap ( ) ; } }
A first simple REPL for Tokay
A first simple REPL for Tokay
streams
Vec<(&str, RefCell<Stream>)>
streams
Vec<(&str, RefCell<Stream>)>