diff --git a/.idea/JavaClassFileParser.iml b/.idea/JavaClassFileParser.iml
index 8182136..faa5fb5 100644
--- a/.idea/JavaClassFileParser.iml
+++ b/.idea/JavaClassFileParser.iml
@@ -4,7 +4,7 @@
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c236a7a..e8081c9 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,7 +1,10 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/pjvm/opcodes.py b/pjvm/opcodes.py
index 4158a11..38e0c0b 100644
--- a/pjvm/opcodes.py
+++ b/pjvm/opcodes.py
@@ -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 = []
diff --git a/pjvm/vm.py b/pjvm/vm.py
index 14f3b35..589804f 100644
--- a/pjvm/vm.py
+++ b/pjvm/vm.py
@@ -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]
diff --git a/testclass/AdvancedTest.java b/testclass/AdvancedTest.java
index 1a33ccd..b3977d1 100644
--- a/testclass/AdvancedTest.java
+++ b/testclass/AdvancedTest.java
@@ -1,7 +1,12 @@
package testclass;
public class AdvancedTest {
- public static void Main(String[] args) throws Exception{
+ private static void method() {
+ System.out.println("Hello");
+ }
+
+ public static void main(String[] args) throws Exception{
+ method();
char c = (char) System.in.read();
if (c == 'a') {
System.out.println("Is a");
diff --git a/testclass/Test.java b/testclass/Test.java
index 8a818cc..8d2292b 100644
--- a/testclass/Test.java
+++ b/testclass/Test.java
@@ -3,7 +3,7 @@ package testclass;
public class Test {
String testfield;
public static int otherField;
- public static void Main(String[] args) {
+ public static void main(String[] args) {
System.out.println("Hello World!");
}
}