Skip to content

Commit b7acae5

Browse files
authored
Fix Shell on Python 3 (#55)
2 parents f014a1e + 21a20b5 commit b7acae5

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
SOM_INTERP=BC pytest
5757
SOM_INTERP=AST ./som.sh -cp Smalltalk TestSuite/TestHarness.som
5858
SOM_INTERP=BC ./som.sh -cp Smalltalk TestSuite/TestHarness.som
59+
echo "[system exit: 0] value" | SOM_INTERP=AST ./som.sh -cp Smalltalk
60+
echo "[system exit: 0] value" | SOM_INTERP=BC ./som.sh -cp Smalltalk
5961
6062
- name: Full Tests
6163
if: matrix.id != 'basic'

src/rlib/osext.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
from rlib.string_stream import decode_str
4+
35

46
def path_split(path):
57
"""
@@ -21,15 +23,15 @@ def path_split(path):
2123

2224

2325
def _read_raw(answer):
24-
buf = os.read(1, 32)
26+
buf = os.read(0, 32)
2527
if len(buf) == 0:
2628
return answer, False
27-
if buf[-1] == "\n":
28-
return answer + buf[:-1], False
29-
return answer + buf, True
29+
if buf[-1] == b"\n"[0]:
30+
return answer + decode_str(buf[:-1]), False
31+
return answer + decode_str(buf), True
3032

3133

32-
def raw_input(msg=""):
34+
def raw_input(msg=b""):
3335
os.write(1, msg)
3436
answer, cont = _read_raw("")
3537
while cont:

src/rlib/string_stream.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
def encode_to_bytes(str_value):
55
return str_value
66

7+
def decode_str(str_value):
8+
return str_value
9+
710
except ImportError:
811
"NOT_RPYTHON"
912

@@ -20,11 +23,17 @@ class StreamError(Exception):
2023
def encode_to_bytes(str_value):
2124
return str_value.encode("utf-8")
2225

26+
def decode_str(str_value):
27+
return str_value.decode("utf-8")
28+
2329
else:
2430

2531
def encode_to_bytes(str_value):
2632
return str_value
2733

34+
def decode_str(str_value):
35+
return str_value
36+
2837

2938
class StringStream(Stream):
3039
def __init__(self, string):

src/som/vm/shell.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from rlib.exit import Exit
12
from rlib.objectmodel import we_are_translated
23
from rlib.osext import raw_input
4+
from som.compiler.parse_error import ParseError
35
from som.vm.globals import nilObject
46
from som.vm.symbols import symbol_for
57

@@ -19,7 +21,7 @@ def start(self):
1921
while True:
2022
try:
2123
# Read a statement from the keyboard
22-
stmt = raw_input("---> ")
24+
stmt = raw_input(b"---> ")
2325
if stmt == "quit" or stmt == "":
2426
return it
2527
if stmt == "\n":
@@ -44,6 +46,10 @@ def start(self):
4446
shell_method = shell_class.lookup_invokable(symbol_for("run:"))
4547

4648
it = shell_method.invoke_2(shell_object, it)
49+
except ParseError as ex:
50+
error_println(str(ex))
51+
except Exit as ex:
52+
raise ex
4753
except Exception as ex: # pylint: disable=broad-except
4854
if not we_are_translated(): # this cannot be done in rpython
4955
import traceback

0 commit comments

Comments
 (0)