diff --git a/src/repl.py b/src/repl.py index 67e158e..cbc581c 100644 --- a/src/repl.py +++ b/src/repl.py @@ -2,8 +2,9 @@ import atexit import readline from pathlib import Path -from src.ast.stmt import Stmt +from src.ast.stmt import Stmt, ExpressionStmt from src.completer.completer import Completer +from src.interpreter.error import PebbleRuntimeError from src.interpreter.interpreter import Interpreter from src.interpreter.resolver import Resolver from src.parser.parser import Parser @@ -91,7 +92,15 @@ class REPL: continue try: - self.interpreter.interpret(program) + if len(program) == 1 and isinstance(program[0], ExpressionStmt): + stmt: ExpressionStmt = program[0] # type: ignore + try: + value = self.interpreter.evaluate(stmt.expression) + print(self.interpreter.stringify(value)) + except PebbleRuntimeError as e: + Pebble.runtime_error(e) + else: + self.interpreter.interpret(program) except KeyboardInterrupt: print()