diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77124ea7..1c2987ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,8 @@ jobs: SOM_INTERP=BC pytest SOM_INTERP=AST ./som.sh -cp Smalltalk TestSuite/TestHarness.som SOM_INTERP=BC ./som.sh -cp Smalltalk TestSuite/TestHarness.som + echo "[system exit: 0] value" | SOM_INTERP=AST ./som.sh -cp Smalltalk + echo "[system exit: 0] value" | SOM_INTERP=BC ./som.sh -cp Smalltalk - name: Full Tests if: matrix.id != 'basic' diff --git a/src/rlib/osext.py b/src/rlib/osext.py index d9fae07a..e776195a 100644 --- a/src/rlib/osext.py +++ b/src/rlib/osext.py @@ -1,5 +1,7 @@ import os +from rlib.string_stream import decode_str + def path_split(path): """ @@ -21,15 +23,15 @@ def path_split(path): def _read_raw(answer): - buf = os.read(1, 32) + buf = os.read(0, 32) if len(buf) == 0: return answer, False - if buf[-1] == "\n": - return answer + buf[:-1], False - return answer + buf, True + if buf[-1] == b"\n"[0]: + return answer + decode_str(buf[:-1]), False + return answer + decode_str(buf), True -def raw_input(msg=""): +def raw_input(msg=b""): os.write(1, msg) answer, cont = _read_raw("") while cont: diff --git a/src/rlib/string_stream.py b/src/rlib/string_stream.py index 4a600744..33b571c4 100644 --- a/src/rlib/string_stream.py +++ b/src/rlib/string_stream.py @@ -4,6 +4,9 @@ def encode_to_bytes(str_value): return str_value + def decode_str(str_value): + return str_value + except ImportError: "NOT_RPYTHON" @@ -20,11 +23,17 @@ class StreamError(Exception): def encode_to_bytes(str_value): return str_value.encode("utf-8") + def decode_str(str_value): + return str_value.decode("utf-8") + else: def encode_to_bytes(str_value): return str_value + def decode_str(str_value): + return str_value + class StringStream(Stream): def __init__(self, string): diff --git a/src/som/vm/shell.py b/src/som/vm/shell.py index dfbc901c..68970814 100644 --- a/src/som/vm/shell.py +++ b/src/som/vm/shell.py @@ -1,5 +1,7 @@ +from rlib.exit import Exit from rlib.objectmodel import we_are_translated from rlib.osext import raw_input +from som.compiler.parse_error import ParseError from som.vm.globals import nilObject from som.vm.symbols import symbol_for @@ -19,7 +21,7 @@ def start(self): while True: try: # Read a statement from the keyboard - stmt = raw_input("---> ") + stmt = raw_input(b"---> ") if stmt == "quit" or stmt == "": return it if stmt == "\n": @@ -44,6 +46,10 @@ def start(self): shell_method = shell_class.lookup_invokable(symbol_for("run:")) it = shell_method.invoke_2(shell_object, it) + except ParseError as ex: + error_println(str(ex)) + except Exit as ex: + raise ex except Exception as ex: # pylint: disable=broad-except if not we_are_translated(): # this cannot be done in rpython import traceback