From b1bc9ff0d1fe8a1be7e87a218259d4bef72de35f Mon Sep 17 00:00:00 2001 From: olwmc Date: Sun, 24 Apr 2022 14:01:51 -0400 Subject: [PATCH 1/2] Added expression printing to REPL --- asteroid/repl.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/asteroid/repl.py b/asteroid/repl.py index a09bc0e4..00cd9cac 100644 --- a/asteroid/repl.py +++ b/asteroid/repl.py @@ -2,6 +2,7 @@ from asteroid.version import VERSION from asteroid.state import state from asteroid.globals import ExpectationError +from asteroid.walk import function_return_value from sys import stdin import readline @@ -66,6 +67,15 @@ def run_repl(): # Try to line = "" + # Check for return value + if function_return_value: + # Get the last return value + val = function_return_value[-1] + + # If it isn't none, print out the value + if val: + print(val[1]) + except ExpectationError as e: # If we expected something but found EOF, it's a continue if e.found_EOF: From ba341ef347bfa4345cfee28ec378c1ef1be9c3fc Mon Sep 17 00:00:00 2001 From: olwmc Date: Sun, 24 Apr 2022 14:16:09 -0400 Subject: [PATCH 2/2] REPL no longer prints None as a return value --- asteroid/repl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/asteroid/repl.py b/asteroid/repl.py index 00cd9cac..ae455d87 100644 --- a/asteroid/repl.py +++ b/asteroid/repl.py @@ -68,13 +68,13 @@ def run_repl(): line = "" # Check for return value - if function_return_value: - # Get the last return value - val = function_return_value[-1] + if function_return_value[-1]: + # Get the last return value (type, value) + (_, val) = function_return_value[-1] # If it isn't none, print out the value - if val: - print(val[1]) + if val is not None: + print(val) except ExpectationError as e: # If we expected something but found EOF, it's a continue