Skip to content

Commit

Permalink
Fix Shell on Python 3 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr authored Oct 1, 2023
2 parents f014a1e + 21a20b5 commit b7acae5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 7 additions & 5 deletions src/rlib/osext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from rlib.string_stream import decode_str


def path_split(path):
"""
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/rlib/string_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion src/som/vm/shell.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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":
Expand All @@ -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
Expand Down

0 comments on commit b7acae5

Please sign in to comment.