Files
PJVM/pjvm/mockimpl/system.py
2020-02-03 19:38:10 +01:00

32 lines
693 B
Python

"""
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))