feat: added support for invoke static

This commit is contained in:
2024-03-29 15:29:40 +01:00
parent 58a40f3a24
commit c103ead828
6 changed files with 31 additions and 6 deletions

View File

@@ -85,13 +85,30 @@ def op_ldc(vm: "PJVirtualMachine", opcode: int, frame: Frame):
frame.stack.append(resulting_value)
@Opcode(0xb8, size=3, no_ret=True)
def op_invokestatic(vm: "PJVirtualMachine", opcode: int, frame: Frame):
index = frame.get_short(frame.ip + 1)
class_name, method_name, descriptor = frame.clazz.cp_get_methodref(index)
LOGGER.info(f"Calling static {class_name} -> {method_name} {descriptor}")
args_types = utils.get_argument_count_types_descriptor(descriptor)
# todo type check
args = []
for _ in args_types:
args.append(frame.stack.pop())
result = vm.execute_static_method(class_name, method_name, args)
if descriptor[-1] != 'V':
frame.stack.append(result)
@Opcode(0xb6, size=3, no_ret=True)
def op_invokevirtual(vm: "PJVirtualMachine", opcode: int, frame: Frame):
index = frame.get_short(frame.ip + 1)
result: JObj
class_name, method_name, descriptor = frame.clazz.cp_get_methodref(index)
LOGGER.info(f"Calling {class_name} -> {method_name} {descriptor}")
LOGGER.info(f"Calling virtual {class_name} -> {method_name} {descriptor}")
args_types = utils.get_argument_count_types_descriptor(descriptor)
# todo type check
args = []

View File

@@ -49,7 +49,7 @@ class PJVirtualMachine:
if main_class not in self.classes:
raise PJVMException("main_class not found!")
self.execute_static_method(main_class, 'Main', [j_args])
self.execute_static_method(main_class, 'main', [j_args])
def execute_static_method(self, class_name: str, method_name: str, args: List[JObj]):
clazz = self.classes[class_name]