Search in sources :

Example 26 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class EspressoInterop method fitsInByte.

@ExportMessage
static boolean fitsInByte(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostByte(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Short) {
        short content = meta.java_lang_Short_value.getShort(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Integer) {
        int content = meta.java_lang_Integer_value.getInt(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return (byte) content == content && !isNegativeZero(content);
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return (byte) content == content && !isNegativeZero(content);
    }
    return false;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 27 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class EspressoInterop method isMemberInvocable.

@ExportMessage
static boolean isMemberInvocable(StaticObject receiver, String member, @Exclusive @Cached LookupVirtualMethodNode lookupMethod) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    ObjectKlass k = getInteropKlass(receiver);
    return lookupMethod.isInvocable(k, member);
}
Also used : ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 28 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class EspressoInterop method fitsInLong.

@ExportMessage
static boolean fitsInLong(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostLong(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) content == content;
    }
    return false;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 29 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class EspressoInterop method writeMember.

@ExportMessage
static void writeMember(StaticObject receiver, String member, Object value, @Cached @Exclusive LookupInstanceFieldNode lookup, @Cached ToEspressoNode toEspresso, @Shared("error") @Cached BranchProfile error) throws UnsupportedTypeException, UnknownIdentifierException, UnsupportedMessageException {
    receiver.checkNotForeign();
    Field f = lookup.execute(getInteropKlass(receiver), member);
    if (f != null) {
        if (f.isFinalFlagSet()) {
            error.enter();
            throw UnsupportedMessageException.create();
        }
        f.set(receiver, toEspresso.execute(value, f.resolveTypeKlass()));
        return;
    }
    error.enter();
    throw UnknownIdentifierException.create(member);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 30 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class EspressoInterop method fitsInInt.

@ExportMessage
static boolean fitsInInt(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostInt(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        return (int) content == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (int) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return (int) content == content && !isNegativeZero(content);
    }
    return false;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4