Search in sources :

Example 66 with ObjectRef

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

the class NativeDouble method parseDouble.

/**
 * override
 *
 * @see Double#parseDouble(String)
 */
private static Result parseDouble(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = (ObjectRef) methodArgs.invokeArgs[0];
    String s = frame.heap.runToString(objectRef);
    double d;
    try {
        d = Double.parseDouble(s);
    } catch (Exception e) {
        frame.throwNumberFormatException(e.getMessage());
        return null;
    }
    Result result = NativeMethod.result(methodCode, d, frame);
    return result;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 67 with ObjectRef

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

the class NativeDouble method toString.

/**
 * override
 *
 * @see Double#toString(double)
 */
private static Result toString(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    double d = (double) methodArgs.invokeArgs[0];
    String s = Double.toString(d);
    ObjectRef ref = frame.heap.newString(s);
    Result result = NativeMethod.result(methodCode, ref, frame);
    return result;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 68 with ObjectRef

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

the class NativeFloat method toHexString.

/**
 * override
 *
 * @see Float#toHexString(float)
 */
private static Result toHexString(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    float f = (float) methodArgs.invokeArgs[0];
    String s = Float.toHexString(f);
    ObjectRef ref = frame.heap.newString(s);
    Result result = NativeMethod.result(methodCode, ref, frame);
    return result;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 69 with ObjectRef

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

the class NativeArray method newArray.

/**
 * native
 *
 * @see Array#newArray(Class, int)
 */
private static Result newArray(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef componentType = (ObjectRef) methodArgs.invokeArgs[0];
    int length = (int) methodArgs.invokeArgs[1];
    VariableType variableType = VariableType.valueOf("[" + componentType.getRef());
    ObjectRef array = frame.heap.newArray(variableType, length);
    Result result = NativeMethod.result(methodCode, array, 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 70 with ObjectRef

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

the class NativeString method getBytes.

/**
 * override
 *
 * @see String#getBytes()
 */
private static Result getBytes(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    ObjectRef objectRef = methodArgs.objectRef;
    ObjectRef ref = null;
    if (objectRef != null) {
        String str = frame.heap.runToString(objectRef);
        if (str != null) {
            byte[] bytes = str.getBytes();
            ref = frame.heap.newArray(bytes);
        }
    }
    Result result = NativeMethod.result(methodCode, ref, frame);
    return result;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

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