Search in sources :

Example 6 with ObjectRef

use of io.nuls.contract.vm.ObjectRef 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 7 with ObjectRef

use of io.nuls.contract.vm.ObjectRef 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)

Example 8 with ObjectRef

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

the class NativeClass method getName0.

/**
 * native
 *
 * @see Class#getName0()
 */
private static Result getName0(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());
    }
    String name;
    if (variableType.isArray()) {
        name = variableType.getDesc();
    } else {
        name = variableType.getType();
        if (name.startsWith("L") && name.endsWith(";")) {
            name = name.substring(1, name.length() - 1);
        }
    }
    name = name.replace('/', '.');
    ObjectRef ref = frame.heap.newString(name);
    Result result = NativeMethod.result(methodCode, ref, frame);
    return result;
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 9 with ObjectRef

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

the class Athrow method athrow.

public static void athrow(final Frame frame) {
    ObjectRef objectRef = frame.operandStack.popRef();
    if (objectRef == null) {
        frame.throwNullPointerException();
        return;
    }
    // Log.opcode(frame.getCurrentOpCode(), objectRef);
    while (frame.vm.isNotEmptyFrame()) {
        final Frame lastFrame = frame.vm.lastFrame();
        TryCatchBlockNode tryCatchBlockNode = getTryCatchBlockNode(lastFrame, objectRef);
        if (tryCatchBlockNode != null) {
            lastFrame.operandStack.clear();
            lastFrame.operandStack.pushRef(objectRef);
            lastFrame.jump(tryCatchBlockNode.handler);
            return;
        } else {
            frame.vm.popFrame();
        }
    }
    frame.vm.getResult().exception(objectRef);
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) Frame(io.nuls.contract.vm.Frame) ObjectRef(io.nuls.contract.vm.ObjectRef)

Example 10 with ObjectRef

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

the class Getfield method getfield.

public static void getfield(Frame frame) {
    FieldInsnNode fieldInsnNode = frame.fieldInsnNode();
    String fieldName = fieldInsnNode.name;
    String fieldDesc = fieldInsnNode.desc;
    ObjectRef objectRef = frame.operandStack.popRef();
    if (objectRef == null) {
        frame.throwNullPointerException();
        return;
    }
    Object value = frame.heap.getField(objectRef, fieldName);
    if (Descriptors.LONG_DESC.equals(fieldDesc)) {
        frame.operandStack.pushLong((long) value);
    } else if (Descriptors.DOUBLE_DESC.equals(fieldDesc)) {
        frame.operandStack.pushDouble((double) value);
    } else {
        frame.operandStack.push(value);
    }
// Log.result(frame.getCurrentOpCode(), value, objectRef, fieldName);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) ObjectRef(io.nuls.contract.vm.ObjectRef)

Aggregations

ObjectRef (io.nuls.contract.vm.ObjectRef)74 Result (io.nuls.contract.vm.Result)35 VariableType (io.nuls.contract.vm.code.VariableType)18 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 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)3 Frame (io.nuls.contract.vm.Frame)2 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)2 BiMap (com.google.common.collect.BiMap)1 BlockHeaderDto (io.nuls.contract.entity.BlockHeaderDto)1 VM (io.nuls.contract.vm.VM)1 ErrorException (io.nuls.contract.vm.exception.ErrorException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AccountState (org.ethereum.core.AccountState)1 DataWord (org.ethereum.vm.DataWord)1 Type (org.objectweb.asm.Type)1