From 4cf165b408c72dcf57b3e32266adf028f0578441 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 5 Jan 2017 04:39:31 -0800 Subject: [PATCH] Use buffered reader for stdout Not sure ifthis is actually helping --- src/eval.rs | 7 ++++++- while.schala | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index bdfd0c3..a48bd85 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use std::collections::VecDeque; use parser::{AST, Statement, Expression, Function}; use std::rc::Rc; +use std::io::{Write, Stdout, BufWriter}; use parser::Expression::*; use parser::Statement::*; @@ -21,6 +22,7 @@ pub struct Evaluator<'a> { parent: Option<&'a Evaluator<'a>>, functions: HashMap, variables: HashMap, + stdout: BufWriter, } impl<'a> Evaluator<'a> { @@ -29,6 +31,7 @@ impl<'a> Evaluator<'a> { functions: HashMap::new(), variables: HashMap::new(), 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) { use self::SideEffect::*; match side_effect { - Print(s) => println!("{}", s), + Print(s) => { + write!(self.stdout, "{}\n", s).unwrap(); + } AddBinding(var, value) => { self.add_binding((*var).clone(), value); }, diff --git a/while.schala b/while.schala index 5eb0866..54e2dc9 100644 --- a/while.schala +++ b/while.schala @@ -1,7 +1,7 @@ a = 0 -while a < 10 +while a < 100000 print("hello", a) a = a + 1 end