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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations