feat: restructured code

This commit is contained in:
2020-02-03 19:38:10 +01:00
parent d4b4be940c
commit f290edd40c
8 changed files with 154 additions and 130 deletions

19
pjvm/mockimpl/__init__.py Normal file
View File

@@ -0,0 +1,19 @@
from .system import JMockSystemIn, JMockSystemOut, mock_inputstream_read, mock_printstream_println
mock_static_objects = {
'java/lang/System': {
'out': JMockSystemOut(),
'in': JMockSystemIn()
}
}
mock_instance_methods = {
'java/io/PrintStream': {
'println': mock_printstream_println
},
'java/io/InputStream': {
'read': mock_inputstream_read
}
}
__all__ = ['mock_instance_methods', 'mock_static_objects']

31
pjvm/mockimpl/system.py Normal file
View File

@@ -0,0 +1,31 @@
"""
In here the System module is partially implemented
"""
import sys
from typing import List
from ..old_jtypes import JObj, JInteger
class JMockSystemOut(JObj):
type = "Ljava/io/PrintStream;"
value = None
class JMockSystemIn(JObj):
type = "Ljava/io/InputStream;"
value = None
def mock_printstream_println(self: JObj, args: List[JObj]):
if len(args) != 1:
raise ValueError("Argument length mismatch")
if args[0].type != 'java/lang/String':
raise ValueError("Argument type mismatch")
print(args[0].value)
def mock_inputstream_read(self: JObj, args: List[JObj]):
character = sys.stdin.read(1).strip()
return JInteger(ord(character))