Search in sources :

Example 1 with Result

use of io.nuls.contract.vm.Result in project nuls by nuls-io.

the class NativeAbstractStringBuilder method append.

/**
 * override
 *
 * @see AbstractStringBuilder#append(float)
 * @see AbstractStringBuilder#append(double)
 */
private static Result append(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    Object a = methodArgs.invokeArgs[0];
    ObjectRef ref = frame.heap.newString(a.toString());
    MethodCode append = frame.methodArea.loadMethod(TYPE, "append", "(Ljava/lang/String;)Ljava/lang/AbstractStringBuilder;");
    frame.vm.run(append, new Object[] { objectRef, ref }, false);
    Result result = NativeMethod.result(methodCode, objectRef, frame);
    return result;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) MethodCode(io.nuls.contract.vm.code.MethodCode) Result(io.nuls.contract.vm.Result)

Example 2 with Result

use of io.nuls.contract.vm.Result in project nuls by nuls-io.

the class NativeClass method getInterfaces.

/**
 * override
 *
 * @see Class#getInterfaces()
 */
private static Result getInterfaces(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    VariableType variableType;
    if (objectRef.getVariableType().isArray()) {
        variableType = objectRef.getVariableType();
    } else {
        variableType = VariableType.valueOf(objectRef.getRef());
    }
    ObjectRef array;
    if (!variableType.isPrimitiveType()) {
        ClassCode classCode = frame.methodArea.loadClass(variableType.getType());
        List<String> interfaces = classCode.interfaces;
        int length = interfaces.size();
        array = frame.heap.newArray(VariableType.valueOf("[Ljava/lang/Class;"), length);
        for (int i = 0; i < length; i++) {
            String interfaceName = interfaces.get(i);
            VariableType interfaceType = VariableType.valueOf(interfaceName);
            ObjectRef ref = frame.heap.getClassRef(interfaceType.getDesc());
            frame.heap.putArray(array, i, ref);
        }
    } else {
        array = frame.heap.newArray(VariableType.valueOf("[Ljava/lang/Class;"), 0);
    }
    Result result = NativeMethod.result(methodCode, array, frame);
    return result;
}
Also used : ClassCode(io.nuls.contract.vm.code.ClassCode) VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 3 with Result

use of io.nuls.contract.vm.Result in project nuls by nuls-io.

the class NativeClass method isInterface.

/**
 * native
 *
 * @see Class#isInterface()
 */
private static Result isInterface(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    VariableType variableType;
    if (objectRef.getVariableType().isArray()) {
        variableType = objectRef.getVariableType();
    } else {
        variableType = VariableType.valueOf(objectRef.getRef());
    }
    boolean b = false;
    if (!variableType.isArray() && !variableType.isPrimitiveType()) {
        ClassCode classCode = frame.methodArea.loadClass(variableType.getType());
        b = classCode.isInterface;
    }
    Result result = NativeMethod.result(methodCode, b, frame);
    return result;
}
Also used : ClassCode(io.nuls.contract.vm.code.ClassCode) VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 4 with Result

use of io.nuls.contract.vm.Result in project nuls by nuls-io.

the class NativeClass method getGenericSignature0.

/**
 * native
 *
 * @see Class#getGenericSignature0()
 */
private static Result getGenericSignature0(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    VariableType variableType;
    if (objectRef.getVariableType().isArray()) {
        variableType = objectRef.getVariableType();
    } else {
        variableType = VariableType.valueOf(objectRef.getRef());
    }
    ObjectRef ref = null;
    if (!variableType.isPrimitiveType()) {
        ClassCode classCode = frame.methodArea.loadClass(variableType.getType());
        String signature = classCode.signature;
        ref = frame.heap.newString(signature);
    }
    Result result = NativeMethod.result(methodCode, ref, frame);
    return result;
}
Also used : ClassCode(io.nuls.contract.vm.code.ClassCode) VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 5 with Result

use of io.nuls.contract.vm.Result in project nuls by nuls-io.

the class NativeClass method getComponentType.

/**
 * native
 *
 * @see Class#getComponentType()
 */
private static Result getComponentType(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    VariableType variableType;
    if (objectRef.getVariableType().isArray()) {
        variableType = objectRef.getVariableType();
    } else {
        variableType = VariableType.valueOf(objectRef.getRef());
    }
    ObjectRef classRef = null;
    if (variableType.isArray()) {
        classRef = frame.heap.getClassRef(variableType.getComponentType().getDesc());
    }
    Result result = NativeMethod.result(methodCode, classRef, frame);
    return result;
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Aggregations

Result (io.nuls.contract.vm.Result)63 ObjectRef (io.nuls.contract.vm.ObjectRef)35 VariableType (io.nuls.contract.vm.code.VariableType)12 MethodCode (io.nuls.contract.vm.code.MethodCode)6 ClassCode (io.nuls.contract.vm.code.ClassCode)5 MethodArgs (io.nuls.contract.vm.MethodArgs)3 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)3 Frame (io.nuls.contract.vm.Frame)1 VM (io.nuls.contract.vm.VM)1 ErrorException (io.nuls.contract.vm.exception.ErrorException)1 ArrayList (java.util.ArrayList)1 AccountState (org.ethereum.core.AccountState)1 DataWord (org.ethereum.vm.DataWord)1