Interpreter - Use Value.to_string() for print statements

This commit is contained in:
Emmanuel BENOîT 2023-01-07 14:14:24 +01:00
parent 621ca9d9f1
commit afb465d6df

View file

@ -172,14 +172,7 @@ impl StmtNode {
/// Handle the `print` statement. /// Handle the `print` statement.
fn on_print(&self, es: &mut InterpreterState, expr: &ExprNode) -> InterpreterResult { fn on_print(&self, es: &mut InterpreterState, expr: &ExprNode) -> InterpreterResult {
let value = expr.interpret(es)?.result(); let value = expr.interpret(es)?.result();
let output = match value { let output = value.to_string();
Value::Nil => String::from("nil"),
Value::Boolean(true) => String::from("true"),
Value::Boolean(false) => String::from("false"),
Value::Number(n) => n.to_string(),
Value::String(s) => s,
Value::Callable(c) => c.borrow().to_string(),
};
println!("{}", output); println!("{}", output);
Ok(InterpreterFlowControl::default()) Ok(InterpreterFlowControl::default())
} }