Use buffered reader for stdout

Not sure ifthis is actually helping
This commit is contained in:
greg 2017-01-05 04:39:31 -08:00
parent 154839979b
commit 4cf165b408
2 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use parser::{AST, Statement, Expression, Function}; use parser::{AST, Statement, Expression, Function};
use std::rc::Rc; use std::rc::Rc;
use std::io::{Write, Stdout, BufWriter};
use parser::Expression::*; use parser::Expression::*;
use parser::Statement::*; use parser::Statement::*;
@ -21,6 +22,7 @@ pub struct Evaluator<'a> {
parent: Option<&'a Evaluator<'a>>, parent: Option<&'a Evaluator<'a>>,
functions: HashMap<String, Function>, functions: HashMap<String, Function>,
variables: HashMap<String, Expression>, variables: HashMap<String, Expression>,
stdout: BufWriter<Stdout>,
} }
impl<'a> Evaluator<'a> { impl<'a> Evaluator<'a> {
@ -29,6 +31,7 @@ impl<'a> Evaluator<'a> {
functions: HashMap::new(), functions: HashMap::new(),
variables: HashMap::new(), variables: HashMap::new(),
parent: parent, parent: parent,
stdout: BufWriter::new(::std::io::stdout()),
} }
} }
@ -125,7 +128,9 @@ impl<'a> Evaluator<'a> {
fn perform_side_effect(&mut self, side_effect: SideEffect) { fn perform_side_effect(&mut self, side_effect: SideEffect) {
use self::SideEffect::*; use self::SideEffect::*;
match side_effect { match side_effect {
Print(s) => println!("{}", s), Print(s) => {
write!(self.stdout, "{}\n", s).unwrap();
}
AddBinding(var, value) => { AddBinding(var, value) => {
self.add_binding((*var).clone(), value); self.add_binding((*var).clone(), value);
}, },

View File

@ -1,7 +1,7 @@
a = 0 a = 0
while a < 10 while a < 100000
print("hello", a) print("hello", a)
a = a + 1 a = a + 1
end end