Evaluator now only prints when a builtin print is called
This commit is contained in:
parent
a0bea0d55a
commit
5be53dc847
@ -110,8 +110,7 @@ fn run_noninteractive(filename: &str, languages: Vec<Box<ProgrammingLanguageInte
|
|||||||
compilation_sequence(llvm_bytecode, filename);
|
compilation_sequence(llvm_bytecode, filename);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let interpretor_output = language.evaluate_in_repl(&buffer, &options);
|
language.evaluate_in_repl(&buffer, &options);
|
||||||
interpretor_output.print_to_screen();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ fn main() {
|
|||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
print(main())
|
||||||
|
|
||||||
|
@ -167,6 +167,7 @@ impl<'a> State<'a> {
|
|||||||
fn eval_application(&mut self, f: Expression, arguments: Vec<FullyEvaluatedExpr>) -> EvalResult<FullyEvaluatedExpr> {
|
fn eval_application(&mut self, f: Expression, arguments: Vec<FullyEvaluatedExpr>) -> EvalResult<FullyEvaluatedExpr> {
|
||||||
use self::ExpressionType::*;
|
use self::ExpressionType::*;
|
||||||
match f {
|
match f {
|
||||||
|
Expression(Value(ref identifier), _) if self.is_builtin(identifier) => self.eval_builtin(identifier, arguments),
|
||||||
Expression(Value(identifier), _) => {
|
Expression(Value(identifier), _) => {
|
||||||
match self.lookup(&identifier) {
|
match self.lookup(&identifier) {
|
||||||
Some(&ValueEntry::Function { ref body, ref param_names }) => {
|
Some(&ValueEntry::Function { ref body, ref param_names }) => {
|
||||||
@ -190,7 +191,30 @@ impl<'a> State<'a> {
|
|||||||
x => Err(format!("Trying to apply {:?} which is not a function", x)),
|
x => Err(format!("Trying to apply {:?} which is not a function", x)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn is_builtin(&self, name: &Rc<String>) -> bool {
|
||||||
|
match &name.as_ref()[..] {
|
||||||
|
"print" | "println" => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn eval_builtin(&mut self, name: &Rc<String>, args: Vec<FullyEvaluatedExpr>) -> EvalResult<FullyEvaluatedExpr> {
|
||||||
|
use self::FullyEvaluatedExpr::*;
|
||||||
|
match &name.as_ref()[..] {
|
||||||
|
"print" => {
|
||||||
|
for arg in args {
|
||||||
|
print!("{}", arg.to_string());
|
||||||
|
}
|
||||||
|
Ok(Tuple(vec![]))
|
||||||
|
},
|
||||||
|
"println" => {
|
||||||
|
for arg in args {
|
||||||
|
println!("{}", arg.to_string());
|
||||||
|
}
|
||||||
|
Ok(Tuple(vec![]))
|
||||||
|
},
|
||||||
|
_ => unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
fn eval_value(&mut self, name: Rc<String>) -> EvalResult<FullyEvaluatedExpr> {
|
fn eval_value(&mut self, name: Rc<String>) -> EvalResult<FullyEvaluatedExpr> {
|
||||||
use self::ValueEntry::*;
|
use self::ValueEntry::*;
|
||||||
match self.lookup(&name) {
|
match self.lookup(&name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user