Search in sources :

Example 6 with VariableType

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

use of io.nuls.contract.vm.code.VariableType in project nuls by nuls-io.

the class Instanceof method instanceof_.

public static void instanceof_(Frame frame) {
    TypeInsnNode typeInsnNode = frame.typeInsnNode();
    VariableType variableType = VariableType.valueOf(typeInsnNode.desc);
    ObjectRef objectRef = frame.operandStack.popRef();
    boolean result = instanceof_(objectRef, variableType, frame);
    frame.operandStack.pushInt(result ? 1 : 0);
// Log.result(frame.getCurrentOpCode(), result, objectRef, variableType);
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) ObjectRef(io.nuls.contract.vm.ObjectRef)

Example 8 with VariableType

use of io.nuls.contract.vm.code.VariableType in project nuls by nuls-io.

the class Checkcast method checkcast.

public static void checkcast(Frame frame) {
    TypeInsnNode typeInsnNode = frame.typeInsnNode();
    String desc = typeInsnNode.desc;
    VariableType variableType = VariableType.valueOf(desc);
    ObjectRef objectRef = frame.operandStack.popRef();
    if (objectRef == null || Instanceof.instanceof_(objectRef, variableType, frame)) {
        frame.operandStack.pushRef(objectRef);
    } else {
        frame.throwClassCastException();
    }
// Log.opcode(frame.getCurrentOpCode(), objectRef, desc);
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) ObjectRef(io.nuls.contract.vm.ObjectRef)

Example 9 with VariableType

use of io.nuls.contract.vm.code.VariableType in project nuls by nuls-io.

the class Multianewarray method multianewarray.

public static void multianewarray(final Frame frame) {
    MultiANewArrayInsnNode multiANewArrayInsnNode = frame.multiANewArrayInsnNode();
    int[] dimensions = new int[multiANewArrayInsnNode.dims];
    for (int i = multiANewArrayInsnNode.dims - 1; i >= 0; i--) {
        int length = frame.operandStack.popInt();
        if (length < 0) {
            frame.throwNegativeArraySizeException();
            return;
        }
        dimensions[i] = length;
    }
    VariableType variableType = VariableType.valueOf(multiANewArrayInsnNode.desc);
    ObjectRef arrayRef = frame.heap.newArray(variableType, dimensions);
    frame.operandStack.pushRef(arrayRef);
// Log.result(frame.getCurrentOpCode(), arrayRef);
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) ObjectRef(io.nuls.contract.vm.ObjectRef)

Example 10 with VariableType

use of io.nuls.contract.vm.code.VariableType in project nuls by nuls-io.

the class Newarray method newarray.

public static void newarray(Frame frame) {
    VariableType type;
    int length = frame.operandStack.popInt();
    if (length < 0) {
        frame.throwNegativeArraySizeException();
        return;
    } else {
        switch(frame.intInsnNode().operand) {
            case Opcodes.T_BOOLEAN:
                type = VariableType.BOOLEAN_ARRAY_TYPE;
                break;
            case Opcodes.T_CHAR:
                type = VariableType.CHAR_ARRAY_TYPE;
                break;
            case Opcodes.T_FLOAT:
                type = VariableType.FLOAT_ARRAY_TYPE;
                break;
            case Opcodes.T_DOUBLE:
                type = VariableType.DOUBLE_ARRAY_TYPE;
                break;
            case Opcodes.T_BYTE:
                type = VariableType.BYTE_ARRAY_TYPE;
                break;
            case Opcodes.T_SHORT:
                type = VariableType.SHORT_ARRAY_TYPE;
                break;
            case Opcodes.T_INT:
                type = VariableType.INT_ARRAY_TYPE;
                break;
            case Opcodes.T_LONG:
                type = VariableType.LONG_ARRAY_TYPE;
                break;
            default:
                throw new IllegalArgumentException("unknown operand");
        }
    }
    ObjectRef arrayRef = frame.heap.newArray(type, length);
    frame.operandStack.pushRef(arrayRef);
// Log.result(frame.getCurrentOpCode(), arrayRef);
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef)

Aggregations

VariableType (io.nuls.contract.vm.code.VariableType)21 ObjectRef (io.nuls.contract.vm.ObjectRef)18 Result (io.nuls.contract.vm.Result)12 ClassCode (io.nuls.contract.vm.code.ClassCode)4 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)3 MethodArgs (io.nuls.contract.vm.MethodArgs)2 MethodCode (io.nuls.contract.vm.code.MethodCode)2 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 ProgramMethodArg (io.nuls.contract.vm.program.ProgramMethodArg)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)1