Java Code Examples for com.oracle.truffle.api.interop.UnknownIdentifierException#create()

The following examples show how to use com.oracle.truffle.api.interop.UnknownIdentifierException#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (frame == null) {
        return HashemPooch.SINGLETON;
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object value;
        Object info = slot.getInfo();
        if (args != null && info != null) {
            value = args[(Integer) info];
        } else {
            value = frame.getValue(slot);
        }
        return value;
    }
}
 
Example 2
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object info = slot.getInfo();
        if (args != null && info != null) {
            args[(Integer) info] = value;
        } else {
            frame.setObject(slot, value);
        }
    }
}
 
Example 3
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
@SuppressWarnings("deprecation") // isAccessible deprecated in Java 11
public Object invokeMember(final String member, final Object... arguments) throws UnknownIdentifierException, UnsupportedTypeException {
    final Method method = getMethods().get(member);
    if (method != null) {
        try {
            if (!method.isAccessible()) {
                method.setAccessible(true);
            }
            return wrap(method.invoke(wrappedObject, arguments));
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw UnsupportedTypeException.create(arguments);
        }
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example 4
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(final String member) throws UnknownIdentifierException {
    if (WRAPPED_MEMBER.equals(member)) {
        return WrapToSqueakNode.getUncached().executeWrap(wrappedObject);
    }
    final Field field = getFields().get(member);
    if (field != null) {
        try {
            return wrap(field.get(wrappedObject));
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw UnknownIdentifierException.create(member);
        }
    }
    final Method method = getMethods().get(member);
    if (method != null) {
        return new JavaMethodWrapper(wrappedObject, method);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example 5
Source File: AbstractSqueakObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
public Object readMember(final String member,
                @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode,
                @Shared("classNode") @Cached final SqueakObjectClassNode classNode,
                @Exclusive @Cached("createBinaryProfile()") final ConditionProfile alternativeProfile) throws UnknownIdentifierException {
    final ClassObject classObject = classNode.executeLookup(this);
    final String selectorString = toSelector(member);
    final Object methodObject = lookupNode.executeLookup(classObject, selectorString);
    if (alternativeProfile.profile(methodObject instanceof CompiledMethodObject)) {
        return new BoundMethod((CompiledMethodObject) methodObject, this);
    } else {
        final Object methodObjectAlternative = lookupNode.executeLookup(classObject, toAlternativeSelector(selectorString));
        if (methodObjectAlternative instanceof CompiledMethodObject) {
            return new BoundMethod((CompiledMethodObject) methodObjectAlternative, this);
        } else {
            throw UnknownIdentifierException.create(member);
        }
    }
}
 
Example 6
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (POINTER.equals(memberName)) {
        return getPointer();
    }
    if (COPY_FROM.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.FROM_POINTER);
    }
    if (COPY_TO.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.TO_POINTER);
    }
    if (FREE.equals(memberName)) {
        return new DeviceArrayFreeFunction();
    }
    if (IS_MEMORY_FREED.equals(memberName)) {
        return isMemoryFreed();
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example 7
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String member,
                @Shared("member") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(member, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(member);
    }
    if (POINTER.equals(memberProfile.profile(member))) {
        return getPointer();
    }
    if (IS_MEMORY_FREED.equals(memberProfile.profile(member))) {
        return arrayFreed;
    }
    if (FREE.equals(memberProfile.profile(member))) {
        return new MultiDimDeviceArrayFreeFunction();
    }
    CompilerDirectives.transferToInterpreter();
    throw new GrCUDAInternalException("trying to read unknown member '" + member + "'");
}
 
Example 8
Source File: Device.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (ID.equals(memberName)) {
        return deviceId;
    }
    if (PROPERTIES.equals(memberName)) {
        return properties;
    }
    if (IS_CURRENT.equals(memberName)) {
        return new IsCurrentFunction(deviceId, runtime);
    }
    if (SET_CURRENT.equals(memberName)) {
        return new SetCurrentFunction(deviceId, runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example 9
Source File: GPUDeviceProperties.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        throw UnknownIdentifierException.create(member);
    }
    Object value = properties.get(member);
    if (value == null) {
        DeviceProperty prop = PROPERTY_SET.getProperty(member);
        value = prop.getValue(deviceId, runtime);
        if (prop.isStaticProperty()) {
            properties.put(member, value);
        }
    }
    return value;
}
 
Example 10
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public void writeMember(final String member, final Object value) throws UnknownIdentifierException, UnsupportedMessageException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    final FrameSlot slot = slots.get(member);
    if (slot != null) {
        FrameAccess.setStackSlot(frame, slot, value);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example 11
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(final String member) throws UnknownIdentifierException {
    if (frame == null) {
        return NilObject.SINGLETON;
    }
    if (SENDER.equals(member)) {
        return FrameAccess.getSender(frame);
    }
    if (PC.equals(member)) {
        return FrameAccess.getInstructionPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (STACKP.equals(member)) {
        return FrameAccess.getStackPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (METHOD.equals(member)) {
        return FrameAccess.getMethod(frame);
    }
    if (CLOSURE_OR_NIL.equals(member)) {
        return NilObject.nullToNil(FrameAccess.getClosure(frame));
    }
    if (RECEIVER.equals(member)) {
        return FrameAccess.getReceiver(frame);
    }
    final FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        return Objects.requireNonNull(frame.getValue(slot));
    }
}
 
Example 12
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (MAP.equals(memberProfile.profile(memberName))) {
        return new MapDeviceArrayFunction(runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example 13
Source File: Namespace.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(String member) throws UnknownIdentifierException {
    Object entry = map.get(member);
    if (entry == null) {
        throw UnknownIdentifierException.create(member);
    }
    return entry;
}
 
Example 14
Source File: HashemObjectType.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
/**
 * The generic case is used if the number of shapes accessed overflows the limit of the
 * polymorphic inline cache.
 */
@TruffleBoundary
@Specialization(replaces = {"readCached"}, guards = "receiver.getShape().isValid()")
static Object readUncached(DynamicObject receiver, String name) throws UnknownIdentifierException {
    Object result = receiver.get(name);
    if (result == null) {
        /* Property does not exist. */
        throw UnknownIdentifierException.create(name);
    }
    return result;
}
 
Example 15
Source File: HashemObjectType.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
static Location lookupLocation(Shape shape, String name) throws UnknownIdentifierException {
    /* Initialization of cached values always happens in a slow path. */
    CompilerAsserts.neverPartOfCompilation();

    Property property = shape.getProperty(name);
    if (property == null) {
        /* Property does not exist. */
        throw UnknownIdentifierException.create(name);
    }

    return property.getLocation();
}
 
Example 16
Source File: HashemObjectType.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
static boolean removeMember(DynamicObject receiver, String member) throws UnknownIdentifierException {
    if (receiver.containsKey(member)) {
        return receiver.delete(member);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example 17
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Fallback
static MapFunctionBase readMemberOther(MapFunction receiver, String member) throws UnknownIdentifierException {
    throw UnknownIdentifierException.create(member);
}
 
Example 18
Source File: Kernel.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Fallback
public static Object readMemberOther(Kernel receiver, String member) throws UnknownIdentifierException {
    throw UnknownIdentifierException.create(member);
}
 
Example 19
Source File: HashemToMemberNode.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@TruffleBoundary
private static UnknownIdentifierException error(Object value) {
    return UnknownIdentifierException.create(value.toString());
}