use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMTruffleHandleToManaged method doIntrinsic.
@Specialization
protected LLVMTruffleObject doIntrinsic(Object rawHandle, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("createToNativeWithTarget()") LLVMToNativeNode forceAddressNode) {
LLVMAddress handle = forceAddressNode.executeWithTarget(rawHandle);
TruffleObject object = context.get().getManagedObjectForHandle(handle);
return new LLVMTruffleObject(object);
}
use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMTruffleReadNBytes method doIntrinsic.
@Specialization
protected Object doIntrinsic(LLVMAddress value, int n, @Cached("getLLVMMemory()") LLVMMemory memory, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
int count = n < 0 ? 0 : n;
byte[] bytes = new byte[count];
long ptr = value.getVal();
for (int i = 0; i < count; i++) {
bytes[i] = memory.getI8(ptr);
ptr += Byte.BYTES;
}
TruffleObject ret = (TruffleObject) ctxRef.get().getEnv().asGuestValue(bytes);
return new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(ret));
}
use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMTruffleReadNString method interop.
@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM) {
long offset = objectWithOffset.getOffset();
TruffleObject object = objectWithOffset.getObject();
char[] chars = new char[n];
for (int i = 0; i < n; i++) {
Object rawValue;
try {
rawValue = ForeignAccess.sendRead(foreignRead, object, offset + i);
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
byte byteValue = (byte) toLLVM.executeWithTarget(rawValue);
chars[i] = (char) Byte.toUnsignedInt(byteValue);
}
return new String(chars);
}
use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMPolyglotExport method doExport.
@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
String symbolName = readString.executeWithTarget(name);
LLVMContext ctx = ctxRef.get();
Object escaped = escape.executeWithTarget(value);
try {
ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
} catch (InteropException ex) {
throw ex.raise();
}
return null;
}
use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMTruffleExecute method doExecute.
@ExplodeLoop
private Object doExecute(VirtualFrame frame, TruffleObject value, LLVMContext context, LLVMGetStackNode getStack) {
Object[] evaluatedArgs = new Object[args.length];
for (int i = 0; i < args.length; i++) {
evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
}
try {
LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
Object rawValue;
try (StackPointer save = stack.newFrame()) {
rawValue = ForeignAccess.sendExecute(foreignExecute, value, evaluatedArgs);
}
return toLLVM.executeWithTarget(rawValue);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
}
Aggregations