Search in sources :

Example 26 with ObjectRef

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

the class Aload method aload.

public static void aload(final Frame frame) {
    int index = frame.varInsnNode().var;
    ObjectRef objectRef = frame.localVariables.getRef(index);
    frame.operandStack.pushRef(objectRef);
// Log.result(frame.getCurrentOpCode(), objectRef, index);
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef)

Example 27 with ObjectRef

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

Example 28 with ObjectRef

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

the class NativeMethod method result.

public static Result result(MethodCode methodCode, Object resultValue, Frame frame) {
    VariableType variableType = methodCode.returnVariableType;
    Result result = new Result(variableType);
    if (variableType.isNotVoid()) {
        result.value(resultValue);
        if (resultValue == null) {
            frame.operandStack.pushRef(null);
        } else if (variableType.isPrimitive()) {
            frame.operandStack.push(resultValue, variableType);
        } else if (resultValue instanceof ObjectRef) {
            frame.operandStack.pushRef((ObjectRef) resultValue);
        } else {
            throw new IllegalArgumentException("unknown result value");
        }
    }
    return result;
}
Also used : VariableType(io.nuls.contract.vm.code.VariableType) ObjectRef(io.nuls.contract.vm.ObjectRef) Result(io.nuls.contract.vm.Result)

Example 29 with ObjectRef

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

the class NativeBlock method getBlockHeader.

private static ObjectRef getBlockHeader(long blockNumber, Frame frame) {
    String fieldName = "BlockHeader$" + blockNumber;
    Object object = frame.heap.getStatic(VariableType.BLOCK_HEADER_TYPE.getType(), fieldName);
    if (object != null) {
        return (ObjectRef) object;
    }
    BlockHeaderDto blockHeaderDto = frame.vm.getBlockHeader(blockNumber);
    if (blockHeaderDto != null) {
        ObjectRef objectRef = frame.heap.newObject(VariableType.BLOCK_HEADER_TYPE);
        frame.heap.putField(objectRef, "hash", frame.heap.newString(blockHeaderDto.getHash()));
        frame.heap.putField(objectRef, "time", blockHeaderDto.getTime());
        frame.heap.putField(objectRef, "height", blockHeaderDto.getHeight());
        frame.heap.putField(objectRef, "txCount", blockHeaderDto.getTxCount());
        ObjectRef packingAddress = null;
        if (blockHeaderDto.getPackingAddress() != null) {
            packingAddress = frame.heap.newAddress(NativeAddress.toString(blockHeaderDto.getPackingAddress()));
        }
        frame.heap.putField(objectRef, "packingAddress", packingAddress);
        String stateRoot = null;
        if (blockHeaderDto.getStateRoot() != null) {
            stateRoot = Hex.toHexString(blockHeaderDto.getStateRoot());
        }
        frame.heap.putField(objectRef, "stateRoot", frame.heap.newString(stateRoot));
        frame.heap.putStatic(VariableType.BLOCK_HEADER_TYPE.getType(), fieldName, objectRef);
        return objectRef;
    }
    return null;
}
Also used : ObjectRef(io.nuls.contract.vm.ObjectRef) BlockHeaderDto(io.nuls.contract.entity.BlockHeaderDto)

Example 30 with ObjectRef

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

the class NativeBlock method getBlockHeader.

/**
 * native
 *
 * @see Block#getBlockHeader(long)
 */
private static Result getBlockHeader(MethodCode methodCode, MethodArgs methodArgs, Frame frame) {
    long blockNumber = (long) methodArgs.invokeArgs[0];
    ObjectRef objectRef = getBlockHeader(blockNumber, frame);
    Result result = NativeMethod.result(methodCode, objectRef, 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