From 058c95979295f0dfcc49b0d0750aec4677f85d75 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Fri, 6 Feb 2026 16:50:16 +0100 Subject: [PATCH] feat(interpreter): add method to stringify values --- src/interpreter/interpreter.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/interpreter/interpreter.py b/src/interpreter/interpreter.py index 3aec41b..f4cb9b1 100644 --- a/src/interpreter/interpreter.py +++ b/src/interpreter/interpreter.py @@ -169,7 +169,7 @@ class Interpreter(Expr.Visitor[Any], Stmt.Visitor[None]): def visit_print_stmt(self, stmt: PrintStmt) -> None: value: Any = self.evaluate(stmt.expression) - print(value) + print(self.stringify(value)) def visit_return_stmt(self, stmt: ReturnStmt) -> None: value: Any = None @@ -280,3 +280,17 @@ class Interpreter(Expr.Visitor[Any], Stmt.Visitor[None]): if isinstance(value, (int, float)): return raise PebbleRuntimeError(clause, "For loop clauses must be numbers.") + + @staticmethod + def stringify(obj: Any) -> str: + if obj is None: + return "null" + if obj is True: + return "true" + if obj is False: + return "false" + if isinstance(obj, (int, float)): + if obj.is_integer(): + obj = int(obj) + return str(obj) + return obj