use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.
the class LLVMPolyglotEval method doEval.
@Specialization
protected Object doEval(Object idPointer, Object srcPointer, @Cached("createReadString()") LLVMReadStringNode readId, @Cached("createReadString()") LLVMReadStringNode readSrc, @Cached("createForeignToLLVM()") ForeignToLLVM toLLVM, @Cached BranchProfile exception) {
try {
CallTarget callTarget = getSource.execute(readId.executeWithTarget(idPointer), readSrc.executeWithTarget(srcPointer));
Object foreign = callTarget.call();
return toLLVM.executeWithTarget(foreign);
} catch (IllegalStateException e) {
// language id not found
exception.enter();
throw new LLVMPolyglotException(this, e.getMessage());
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.
the class LLVMPolyglotNewInstance method doNew.
@Specialization
@ExplodeLoop
protected Object doNew(VirtualFrame frame, LLVMManagedPointer value, @Cached("createForeignToLLVM()") ForeignToLLVM toLLVM, @Cached BranchProfile exception) {
Object foreign = asForeign.execute(value);
Object[] evaluatedArgs = new Object[args.length];
for (int i = 0; i < args.length; i++) {
evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
}
try {
Object rawValue;
rawValue = foreignNewInstance.instantiate(foreign, evaluatedArgs);
return toLLVM.executeWithTarget(rawValue);
} catch (UnsupportedMessageException e) {
exception.enter();
throw new LLVMPolyglotException(this, "Polyglot value cannot be instantiated.");
} catch (UnsupportedTypeException e) {
exception.enter();
throw new LLVMPolyglotException(this, "Wrong argument type passed to polyglot_new_instance.");
} catch (ArityException e) {
exception.enter();
throw new LLVMPolyglotException(this, "Wrong number of arguments passed to polyglot_new_instance, expected %d but got %d.", e.getExpectedMinArity(), e.getActualArity());
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.
the class LLVMPolyglotExport method doExport.
@Specialization
@GenerateAOT.Exclude
protected Object doExport(Object name, Object value, @CachedLibrary(limit = "3") InteropLibrary interop, @Cached BranchProfile exception) {
String symbolName = readString.executeWithTarget(name);
Object escaped = escape.executeWithTarget(value);
try {
interop.writeMember(getContext().getEnv().getPolyglotBindings(), symbolName, escaped);
} catch (InteropException ex) {
exception.enter();
throw new LLVMPolyglotException(this, ex.getMessage());
}
return null;
}
use of com.oracle.truffle.llvm.runtime.except.LLVMPolyglotException in project graal by oracle.
the class LLVMTruffleWriteManagedToSymbol method write.
@TruffleBoundary
@Specialization
protected Object write(LLVMPointer address, Object value) {
/*
* The list of symbols should be all global symbols or all function symbols more over, the
* list of symbols should all be pointing to the same value or function code, and they
* should all have the same name.
*/
List<LLVMSymbol> symbols = getContext().removeSymbolReverseMap(address);
if (symbols == null) {
throw new LLVMPolyglotException(this, "First argument to truffle_assign_managed must be a pointer to a symbol.");
}
Object newValue = value;
boolean allGlobals = symbols.get(0).isGlobalVariable();
LLVMContext ctx = LLVMContext.get(this);
/*
* The interop type of the global symbol has to be attached to the new object that's
* replacing the global. This is done by creating a LLVMTypedForeignObject wrapping it
* around the new object with the global's interop type.
*/
if (allGlobals) {
newValue = attachType.execute(value, symbols.get(0).asGlobalVariable().getInteropType(ctx));
}
/*
* Every symbol in the symbol list should point to the same value even if they are stored in
* different locations in the symbol table.
*/
for (LLVMSymbol symbol : symbols) {
assert allGlobals ? symbol.isGlobalVariable() : symbol.isFunction();
ctx.setSymbol(symbol, LLVMPointer.cast(newValue));
}
ctx.registerSymbolReverseMap(symbols, LLVMPointer.cast(value));
return newValue;
}
Aggregations