}
@Override
public void run(WeaselInterpreter interpreter, WeaselThread thread, WeaselMethodExecutor method) {
resolve(interpreter);
WeaselObject object = interpreter.getObject(thread.getObject(thread.getStackPointer()-this.method.getParamClasses().length-1));
WeaselMethodBody methodBody = this.method.getMethodFromClass(object.getWeaselClass());
if(methodBody.isNative()){
if(nativeMethod==null){
nativeMethod = interpreter.getNativeMethod(methodBody.getNameAndDesk());
}
Object[] params = new Object[this.method.getParamClasses().length];
for(int i=0; i<params.length; i++){
StackElement se = thread.pop();
if(se.value==null){
params[i] = interpreter.getObject(se.object);
}else{
params[i] = se.value;
}
}
thread.popObject();
Object ret = nativeMethod.invoke(interpreter, thread, method, methodBody.getNameAndDesk(), object, params);
WeaselClass rc = this.method.getReturnClasses();
switch(WeaselPrimitive.getPrimitiveID(rc)){
case WeaselPrimitive.BOOLEAN:
thread.pushValue((Boolean)ret);
break;
case WeaselPrimitive.CHAR:
thread.pushValue((Character)ret);
break;
case WeaselPrimitive.BYTE:
thread.pushValue((Byte)ret);
break;
case WeaselPrimitive.SHORT:
thread.pushValue((Short)ret);
break;
case WeaselPrimitive.INT:
thread.pushValue((Integer)ret);
break;
case WeaselPrimitive.LONG:
thread.pushValue((Long)ret);
break;
case WeaselPrimitive.FLOAT:
thread.pushValue((Float)ret);
break;
case WeaselPrimitive.DOUBLE:
thread.pushValue((Double)ret);
break;
case WeaselPrimitive.VOID:
if(ret!=null){
throw new WeaselNativeException("Got return parameter %s but expect a void value in %s", ret, methodDesk);
}
break;
default:
if(ret==null){
thread.pushObject(0);
}else{
int objPtr = (Integer)ret;
WeaselObject obj = interpreter.getObject(objPtr);
if(!obj.getWeaselClass().canCastTo(rc))
throw new WeaselNativeException("Got return parameter %s but expect a %s value in %s", ret, rc, methodDesk);
thread.pushObject(objPtr);
}
break;
}