Add a "quiet" mode.

This brings the Python Joy interpreter into better congruence with the
Nim interpreter for ease of automated testing.
This commit is contained in:
Simon Forman
2021-04-06 11:28:30 -07:00
parent 1cf82b8bcb
commit c00c6a4e32
3 changed files with 37 additions and 3 deletions
+22
View File
@@ -107,3 +107,25 @@ def repl(stack=(), dictionary=None):
print_exc()
print()
return stack
def interp(stack=(), dictionary=None):
'''
Simple REPL with no extra output, suitable for use in scripts.
'''
if dictionary is None:
dictionary = {}
try:
while True:
try:
text = input()
except (EOFError, KeyboardInterrupt):
break
try:
stack, _, dictionary = run(text, stack, dictionary)
except:
print_exc()
print(stack_to_string(stack))
except:
print_exc()
return stack