Search in sources :

Example 56 with ObjectRef

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

the class NativeClass method getSuperclass.

/**
 * native
 *
 * @see Class#getSuperclass()
 */
private static Result getSuperclass(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());
    }
    ClassCode classCode = frame.methodArea.loadClass(variableType.getType());
    VariableType superVariableType = VariableType.valueOf(classCode.superName);
    ObjectRef classRef = frame.heap.getClassRef(superVariableType.getDesc());
    Result result = NativeMethod.result(methodCode, classRef, 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 57 with ObjectRef

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

the class NativeClass method isArray.

/**
 * native
 *
 * @see Class#isArray()
 */
private static Result isArray(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 = variableType.isArray();
    Result result = NativeMethod.result(methodCode, b, 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 58 with ObjectRef

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

the class NativeClass method getPrimitiveClass.

/**
 * native
 *
 * @see Class#getPrimitiveClass(String)
 */
private static Result getPrimitiveClass(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = (ObjectRef) methodArgs.invokeArgs[0];
    String name = frame.heap.runToString(objectRef);
    VariableType variableType = VariableType.valueOf(name);
    ObjectRef classRef = frame.heap.getClassRef(variableType.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 59 with ObjectRef

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

the class NativeClass method isPrimitive.

/**
 * native
 *
 * @see Class#isPrimitive()
 */
private static Result isPrimitive(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 = variableType.isPrimitive();
    Result result = NativeMethod.result(methodCode, b, 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 60 with ObjectRef

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

the class JsonUtils method encode.

public static String encode(Object value, BiMap<String, String> classNames) {
    if (value == null) {
        return null;
    } else if (value.getClass().isArray()) {
        Class clazz = value.getClass().getComponentType();
        if (clazz == Integer.TYPE) {
            return "[I_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Long.TYPE) {
            return "[J_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Float.TYPE) {
            return "[F_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Double.TYPE) {
            return "[D_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Boolean.TYPE) {
            return "[Z_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Byte.TYPE) {
            return "[B_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Character.TYPE) {
            return "[C_" + encodeArray(value, clazz, classNames);
        } else if (clazz == Short.TYPE) {
            return "[S_" + encodeArray(value, clazz, classNames);
        } else {
            return "[R_" + encodeArray(value, clazz, classNames);
        }
    } else if (value instanceof Map) {
        Map map = (Map) value;
        Map map1 = new LinkedHashMap(hashMapInitialCapacity(map.size()));
        map.forEach((k, v) -> {
            map1.put(k, encode(v, classNames));
        });
        return toJson(map1);
    } else if (value instanceof Integer) {
        return "I_" + value;
    } else if (value instanceof Long) {
        return "J_" + value;
    } else if (value instanceof Float) {
        return "F_" + value;
    } else if (value instanceof Double) {
        return "D_" + value;
    } else if (value instanceof Boolean) {
        return "Z_" + value;
    } else if (value instanceof Byte) {
        return "B_" + value;
    } else if (value instanceof Character) {
        return "C_" + value;
    } else if (value instanceof Short) {
        return "S_" + value;
    } else if (value instanceof String) {
        return "s_" + value;
    } else if (value instanceof ObjectRef) {
        return "R_" + ((ObjectRef) value).getEncoded(classNames);
    } else {
        throw new IllegalArgumentException("unknown value");
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ObjectRef(io.nuls.contract.vm.ObjectRef) LinkedHashMap(java.util.LinkedHashMap) BiMap(com.google.common.collect.BiMap) Map(java.util.Map)

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