Invoke instance method supported

This commit is contained in:
Andrey Breslav
2013-10-06 22:59:44 +04:00
parent 47fd67a9b0
commit e8ac8cd7fa
2 changed files with 24 additions and 11 deletions
+18 -10
View File
@@ -98,7 +98,7 @@ class TestData {
} }
} }
static int testSimpleFinally() { static int simpleFinally() {
int i = 5; int i = 5;
try { try {
return i; return i;
@@ -108,7 +108,7 @@ class TestData {
} }
} }
static int testSimpleFinallyWithReturn() { static int simpleFinallyWithReturn() {
int i = 5; int i = 5;
try { try {
return i; return i;
@@ -118,7 +118,7 @@ class TestData {
} }
} }
static int testSimpleFinallyWithContinueInLoop() { static int simpleFinallyWithContinueInLoop() {
int i = 5; int i = 5;
while (true) { while (true) {
try { try {
@@ -131,7 +131,7 @@ class TestData {
} }
} }
static int testSimpleFinallyWithBreakInLoop() { static int simpleFinallyWithBreakInLoop() {
int i = 5; int i = 5;
while (true) { while (true) {
try { try {
@@ -144,21 +144,21 @@ class TestData {
return i; return i;
} }
static Object testCall() { static Object call() {
return Integer.valueOf(1); return Integer.valueOf(1);
} }
static Object testCallWithObject() { static Object callWithObject() {
return String.valueOf("str"); return String.valueOf("str");
} }
static Object testGetStaticField() { static Object getStaticField() {
return String.CASE_INSENSITIVE_ORDER; return String.CASE_INSENSITIVE_ORDER;
} }
static int FIELD = 0; static int FIELD = 0;
static int testPutStaticField() { static int putStaticField() {
FIELD = 5; FIELD = 5;
int f1 = FIELD; int f1 = FIELD;
FIELD = 6; FIELD = 6;
@@ -169,16 +169,20 @@ class TestData {
static class C { static class C {
int y = 15; int y = 15;
int getY() {
return y;
}
static C newC() { static C newC() {
return new C(); return new C();
} }
} }
static int testGetInstanceField() { static int getInstanceField() {
return C.newC().y; return C.newC().y;
} }
static int testPutInstanceField() { static int putInstanceField() {
C c = C.newC(); C c = C.newC();
c.y = 5; c.y = 5;
int f1 = c.y; int f1 = c.y;
@@ -187,4 +191,8 @@ class TestData {
return f1 + f2; return f1 + f2;
} }
static int instanceMethod() {
return C.newC().getY();
}
} }
+6 -1
View File
@@ -185,7 +185,12 @@ object REFLECTION_EVAL : Eval {
} }
override fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean): Value { override fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean): Value {
throw UnsupportedOperationException() // TODO: INVOKESPECIAL
val obj = instance.obj
val method = obj.javaClass.findMethod(methodDesc)
assertNotNull("Method not found: $methodDesc", method)
val result = method!!.invoke(obj, *arguments.map { v -> v.obj }.copyToArray())
return objectToValue(result, methodDesc.returnType)
} }
} }