use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method removeHashEntry.
@ExportMessage
@TruffleBoundary
void removeHashEntry(Object key, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException, UnknownKeyException {
if (proxy instanceof ProxyHashMap) {
if (!isHashValueExisting(key, library, cache)) {
throw UnknownKeyException.create(key);
}
Value keyValue = context.asValue(library, key);
guestToHostCall(library, cache.removeHashEntry, context, proxy, keyValue);
} else {
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method invokeMember.
@ExportMessage
@TruffleBoundary
Object invokeMember(String member, Object[] arguments, @CachedLibrary("this") InteropLibrary library, @Shared("executables") @CachedLibrary(limit = "LIMIT") InteropLibrary executables, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException, UnsupportedTypeException, ArityException, UnknownIdentifierException {
if (proxy instanceof ProxyObject) {
if (!isMemberExisting(member, library, cache)) {
throw UnknownIdentifierException.create(member);
}
Object memberObject;
try {
memberObject = readMember(member, library, cache);
} catch (UnsupportedOperationException e) {
throw UnsupportedMessageException.create();
}
memberObject = context.toGuestValue(library, memberObject);
if (executables.isExecutable(memberObject)) {
return executables.execute(memberObject, arguments);
} else {
throw UnsupportedMessageException.create();
}
} else {
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method writeMember.
@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
if (proxy instanceof ProxyObject) {
Value castValue = context.asValue(library, value);
guestToHostCall(library, cache.putMember, context, proxy, member, castValue);
} else {
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method execute.
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
if (proxy instanceof ProxyExecutable) {
Value[] convertedArguments = context.language.access.toValues(context.internalContext, arguments);
Object result = guestToHostCall(library, cache.execute, context, proxy, convertedArguments);
return context.toGuestValue(library, result);
}
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method getMembers.
@ExportMessage
@TruffleBoundary
Object getMembers(@SuppressWarnings("unused") boolean includeInternal, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
if (proxy instanceof ProxyObject) {
Object result = guestToHostCall(library, cache.memberKeys, context, proxy);
if (result == null) {
result = EMPTY;
}
Object guestValue = context.toGuestValue(library, result);
InteropLibrary interop = InteropLibrary.getFactory().getUncached();
if (!interop.hasArrayElements(guestValue)) {
if (guestValue instanceof HostObject) {
HostObject hostObject = (HostObject) guestValue;
if (hostObject.obj.getClass().isArray() && !hostObject.getHostClassCache().isArrayAccess()) {
throw illegalProxy(context, "getMemberKeys() returned a Java array %s, but allowArrayAccess in HostAccess is false.", context.asValue(library, guestValue).toString());
} else if (hostObject.obj instanceof List && !hostObject.getHostClassCache().isListAccess()) {
throw illegalProxy(context, "getMemberKeys() returned a Java List %s, but allowListAccess in HostAccess is false.", context.asValue(library, guestValue).toString());
}
}
throw illegalProxy(context, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.", context.asValue(library, guestValue).toString());
}
// Todo: Use interop to determine an array element type when the GR-5737 is resolved.
for (int i = 0; i < interop.getArraySize(guestValue); i++) {
try {
Object element = interop.readArrayElement(guestValue, i);
if (!interop.isString(element)) {
throw illegalProxy(context, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.", context.asValue(library, guestValue).toString());
}
} catch (UnsupportedOperationException e) {
CompilerDirectives.shouldNotReachHere(e);
} catch (InvalidArrayIndexException e) {
continue;
}
}
return guestValue;
} else {
throw UnsupportedMessageException.create();
}
}
Aggregations