Commit 32335bea authored by Stefan Marr's avatar Stefan Marr

Fix style to sync with RTruffleSOM

- remove redundant parentheses
- simplify string for warning
- make _is_binary_signature protected
- remove unused imports
- fixed whitespace and capitalization in tests
Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent c58f7079
......@@ -15,16 +15,16 @@ def path_split(path):
else:
ext = file_and_ext[-1]
file_name = file_and_ext[0]
return (path, file_name, ext)
return path, file_name, ext
def _read_raw(answer):
buf = os.read(1, 32)
if len(buf) == 0:
return (answer, False)
return answer, False
elif buf[-1] == "\n":
return (answer + buf[:-1], False)
return answer + buf[:-1], False
else:
return (answer + buf, True)
return answer + buf, True
def raw_input(msg = ""):
os.write(1, msg)
......
from som.vmobjects.object import Object
class Class(Object):
_immutable_fields_ = ["_super_class"
......
from som.vmobjects.abstract_object import AbstractObject
class Object(AbstractObject):
_immutable_fields_ = ["_class", "_fields"]
......
......@@ -46,4 +46,4 @@ def empty_primitive(signature_string, universe):
def _invoke(ivkbl, frame, interpreter):
""" Write a warning to the screen """
print "Warning: undefined primitive", ivkbl.get_signature().get_string(), " called"
print "Warning: undefined primitive %s called" % ivkbl.get_signature().get_string()
......@@ -14,7 +14,7 @@ class Symbol(AbstractObject):
def _determine_number_of_signature_arguments(self):
# Check for binary signature
if self.is_binary_signature():
if self._is_binary_signature():
return 2
else:
# Count the colons in the signature string
......@@ -31,7 +31,7 @@ class Symbol(AbstractObject):
def get_number_of_signature_arguments(self):
return self._number_of_signature_arguments
def is_binary_signature(self):
def _is_binary_signature(self):
# Check the individual characters of the string
for c in self._string:
if (c != '~' and c != '&' and c != '|' and c != '*' and c != '/' and
......
......@@ -4,8 +4,6 @@
import sys
from som.vm.universe import main, Exit
from rpython.rlib import jit
#from rpython.rlib.debug import debug_start, debug_stop, debug_print
# __________ Entry points __________
......
......@@ -6,42 +6,48 @@ from som.vm.universe import Universe
from som.vmobjects.integer import Integer
from som.vmobjects.clazz import Class
class BasicInterpreterTest(unittest.TestCase):
@parameterized.expand([
("MethodCall", "test", 42, Integer ),
("MethodCall", "test2", 42, Integer ),
("NonLocalReturn", "test", "NonLocalReturn", Class ),
("NonLocalReturn", "test1", 42, Integer ),
("NonLocalReturn", "test2", 43, Integer ),
("NonLocalReturn", "test3", 3, Integer ),
("NonLocalReturn", "test4", 42, Integer ),
("NonLocalReturn", "test5", 22, Integer ),
("Blocks", "arg1", 42, Integer ),
("Blocks", "arg2", 77, Integer ),
("Blocks", "argAndLocal", 8, Integer ),
("Blocks", "argAndContext", 8, Integer ),
("Return", "returnSelf", "Return", Class ),
("Return", "returnSelfImplicitly", "Return", Class ),
("Return", "noReturnReturnsSelf", "Return", Class ),
("Return", "blockReturnsImplicitlyLastValue", 4, Integer )])
def test_basic_interpreter_behavior(self, test_class, test_selector, expected_result, result_type):
("MethodCall", "test", 42, Integer),
("MethodCall", "test2", 42, Integer),
("NonLocalReturn", "test", "NonLocalReturn", Class),
("NonLocalReturn", "test1", 42, Integer),
("NonLocalReturn", "test2", 43, Integer),
("NonLocalReturn", "test3", 3, Integer),
("NonLocalReturn", "test4", 42, Integer),
("NonLocalReturn", "test5", 22, Integer),
("Blocks", "arg1", 42, Integer),
("Blocks", "arg2", 77, Integer),
("Blocks", "argAndLocal", 8, Integer),
("Blocks", "argAndContext", 8, Integer),
("Return", "returnSelf", "Return", Class),
("Return", "returnSelfImplicitly", "Return", Class),
("Return", "noReturnReturnsSelf", "Return", Class),
("Return", "blockReturnsImplicitlyLastValue", 4, Integer)])
def test_basic_interpreter_behavior(self, test_class, test_selector,
expected_result, result_type):
u = Universe()
u.setup_classpath("Smalltalk:TestSuite/BasicInterpreterTests")
actual_result = u.execute_method(test_class, test_selector)
self._assertEqualsSOMValue(expected_result, actual_result, result_type)
def _assertEqualsSOMValue(self, expected_result, actual_result, result_type):
self._assert_equals_SOM_value(expected_result, actual_result,
result_type)
def _assert_equals_SOM_value(self, expected_result, actual_result,
result_type):
if result_type is Integer:
self.assertEquals(expected_result, actual_result.get_embedded_integer())
self.assertEquals(expected_result,
actual_result.get_embedded_integer())
return
if result_type is Class:
self.assertEquals(expected_result, actual_result.get_name().get_string())
self.assertEquals(expected_result,
actual_result.get_name().get_string())
return
self.fail("SOM Value handler missing")
......
......@@ -2,6 +2,7 @@ import unittest
from parameterized import parameterized
from som.vm.universe import Universe
class SomTest(unittest.TestCase):
@parameterized.expand([
("ClassStructure",),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment