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

The following examples show how to use com.oracle.truffle.api.interop.UnsupportedMessageException#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: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments) throws UnsupportedMessageException, UnsupportedTypeException, ArityException {
    if (value instanceof MapArgObjectMember) {
        MapArgObjectMember member = (MapArgObjectMember) value;
        if (MAP.equals(member.name)) {
            checkArity(arguments, 1);
            return new MapArgObject(member.parent).map(arguments[0]);
        } else if (SHRED.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).shred();
        } else if (DESCRIBE.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).describe();
        } else if (BIND.equals(member.name)) {
            checkArity(arguments, 3);
            return member.parent.bind(arguments[0], arguments[1], arguments[2]);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw UnsupportedMessageException.create();
}
 
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 5 votes vote down vote up
@ExportMessage
protected double asDouble(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException {
    if (isNumber()) {
        return lib.asDouble(wrappedObject);
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 4
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected String asString() throws UnsupportedMessageException {
    try {
        return (String) wrappedObject;
    } catch (final ClassCastException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 5
Source File: LargeIntegerObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public float asFloat() throws UnsupportedMessageException {
    if (fitsInFloat()) {
        return integer.floatValue();
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 6
Source File: LargeIntegerObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public long asLong() throws UnsupportedMessageException {
    try {
        return longValueExact();
    } catch (final ArithmeticException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 7
Source File: LargeIntegerObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public int asInt() throws UnsupportedMessageException {
    try {
        return intValueExact();
    } catch (final ArithmeticException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 8
Source File: LargeIntegerObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public short asShort() throws UnsupportedMessageException {
    try {
        return shortValueExact();
    } catch (final ArithmeticException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 9
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected short asShort(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException {
    if (isNumber()) {
        return lib.asShort(wrappedObject);
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 10
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public long getArraySize(@Shared("sizeNode") @Cached final ArraySizeNode sizeNode) throws UnsupportedMessageException {
    try {
        return sizeNode.execute(wrappedObject);
    } catch (final UnsupportedSpecializationException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 11
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected byte asByte(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException {
    if (isNumber()) {
        return lib.asByte(wrappedObject);
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 12
Source File: JavaMethodWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
protected Object execute(final Object[] arguments) throws UnsupportedMessageException {
    try {
        return JavaObjectWrapper.wrap(method.invoke(receiver, arguments));
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw UnsupportedMessageException.create();
    }
}
 
Example 13
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 14
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected int asInt(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException {
    if (isNumber()) {
        return lib.asInt(wrappedObject);
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 15
Source File: JavaMethodWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
protected Object readMember(final String member) throws UnsupportedMessageException {
    if (NAME_MEMBER.equals(member)) {
        return method.getName();
    } else if (RECEIVER_MEMBER.equals(member)) {
        return receiver;
    } else if (PARAMETER_COUNT.equals(member)) {
        return method.getParameterCount();
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 16
Source File: HashemBigNumber.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
long asLong() throws UnsupportedMessageException {
    if (fitsInLong()) {
        return value.longValue();
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 17
Source File: HashemBigNumber.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
double asDouble() throws UnsupportedMessageException {
    if (fitsInDouble()) {
        return value.doubleValue();
    } else {
        throw UnsupportedMessageException.create();
    }
}
 
Example 18
Source File: JavaMethodWrapper.java    From trufflesqueak with MIT License 4 votes vote down vote up
@SuppressWarnings({"static-method", "unused"})
@ExportMessage
protected void writeMember(final String member, final Object value) throws UnsupportedMessageException {
    throw UnsupportedMessageException.create();
}
 
Example 19
Source File: AbstractSqueakObject.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(replaces = "invokeMember")
protected static final Object invokeMemberWithDNU(final AbstractSqueakObject receiver, final String member, final Object[] arguments,
                @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode,
                @Shared("classNode") @Cached final SqueakObjectClassNode classNode,
                @Exclusive @Cached final WrapToSqueakNode wrapNode,
                @Exclusive @Cached final DispatchUneagerlyNode dispatchNode,
                @Exclusive @Cached final AbstractPointersObjectWriteNode writeNode,
                @Exclusive @Cached("createBinaryProfile()") final ConditionProfile hasMethodProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) throws UnsupportedMessageException, ArityException {
    final int actualArity = arguments.length;
    final String selector = toSelector(member, actualArity);
    final ClassObject classObject = classNode.executeLookup(receiver);
    final Object methodObject = lookupNode.executeLookup(classObject, selector);
    if (hasMethodProfile.profile(methodObject instanceof CompiledMethodObject)) {
        final CompiledMethodObject method = (CompiledMethodObject) methodObject;
        final int expectedArity = method.getNumArgs();
        if (actualArity == expectedArity) {
            return dispatchNode.executeDispatch(method, ArrayUtils.copyWithFirst(wrapNode.executeObjects(arguments), receiver), NilObject.SINGLETON);
        } else {
            throw ArityException.create(1 + expectedArity, 1 + actualArity);
        }
    } else {
        final CompiledMethodObject doesNotUnderstandMethodObject = (CompiledMethodObject) lookupNode.executeLookup(classObject, "doesNotUnderstand:");
        final NativeObject symbol = (NativeObject) image.asByteString(selector).send("asSymbol");
        final PointersObject message = image.newMessage(writeNode, symbol, classObject, arguments);
        try {
            return dispatchNode.executeDispatch(doesNotUnderstandMethodObject, new Object[]{receiver, message}, NilObject.SINGLETON);
        } catch (final ProcessSwitch ps) {
            CompilerDirectives.transferToInterpreter();
            /*
             * A ProcessSwitch exception is thrown in case Squeak/Smalltalk wants to open
             * the debugger. This needs to be avoided in headless mode.
             */
            if (image.isHeadless()) {
                throw UnsupportedMessageException.create();
            } else {
                throw ps;
            }
        }
    }
}
 
Example 20
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(guards = "!receiver.isClass()")
@SuppressWarnings("unused")
protected static final Object doUnsupported(final JavaObjectWrapper receiver, final Object[] args) throws UnsupportedMessageException {
    throw UnsupportedMessageException.create();
}