Search in sources :

Example 71 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoInterop method asTimeZone.

@ExportMessage
@TruffleBoundary
static ZoneId asTimeZone(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (isTimeZone(receiver)) {
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_ZoneId)) {
            int index = meta.java_time_ZoneId_getId.getVTableIndex();
            StaticObject zoneIdEspresso = (StaticObject) receiver.getKlass().vtableLookup(index).invokeDirect(receiver);
            String zoneId = Meta.toHostStringStatic(zoneIdEspresso);
            return ZoneId.of(zoneId, ZoneId.SHORT_IDS);
        } else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            StaticObject zoneId = (StaticObject) meta.java_time_ZonedDateTime_getZone.invokeDirect(receiver);
            return asTimeZone(zoneId, error);
        } else if (instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_util_Date)) {
            return ZoneId.of("UTC");
        }
    }
    error.enter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 72 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoInterop method isDuration.

@ExportMessage
static boolean isDuration(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Meta meta = receiver.getKlass().getMeta();
    return instanceOf(receiver, meta.java_time_Duration);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 73 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoInterop method isTimeZone.

@ExportMessage
static boolean isTimeZone(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Meta meta = receiver.getKlass().getMeta();
    return instanceOf(receiver, meta.java_time_ZoneId) || instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_time_ZonedDateTime) || instanceOf(receiver, meta.java_util_Date);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 74 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoInterop method asTime.

@ExportMessage
@TruffleBoundary
static LocalTime asTime(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (isTime(receiver)) {
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_LocalTime)) {
            byte hour = (byte) meta.java_time_LocalTime_hour.get(receiver);
            byte minute = (byte) meta.java_time_LocalTime_minute.get(receiver);
            byte second = (byte) meta.java_time_LocalTime_second.get(receiver);
            int nano = (int) meta.java_time_LocalTime_nano.get(receiver);
            return LocalTime.of(hour, minute, second, nano);
        } else if (instanceOf(receiver, meta.java_time_LocalDateTime)) {
            StaticObject localTime = (StaticObject) meta.java_time_LocalDateTime_toLocalTime.invokeDirect(receiver);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(receiver);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_time_Instant)) {
            // return ((Instant) obj).atZone(UTC).toLocalTime();
            StaticObject zoneIdUTC = (StaticObject) meta.java_time_ZoneId_of.invokeDirect(null, meta.toGuestString("UTC"));
            assert instanceOf(zoneIdUTC, meta.java_time_ZoneId);
            StaticObject zonedDateTime = (StaticObject) meta.java_time_Instant_atZone.invokeDirect(receiver, zoneIdUTC);
            assert instanceOf(zonedDateTime, meta.java_time_ZonedDateTime);
            StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(zonedDateTime);
            assert instanceOf(localTime, meta.java_time_LocalTime);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_util_Date)) {
            // return ((Date) obj).toInstant().atZone(UTC).toLocalTime();
            int index = meta.java_util_Date_toInstant.getVTableIndex();
            Method virtualToInstant = receiver.getKlass().vtableLookup(index);
            StaticObject instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
            return asTime(instant, error);
        }
    }
    error.enter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 75 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoInterop method readNumberValue.

private static Number readNumberValue(StaticObject receiver) throws UnsupportedMessageException {
    assert receiver.isEspressoObject();
    Klass klass = receiver.getKlass();
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Byte) {
        return (Byte) meta.java_lang_Byte_value.get(receiver);
    }
    if (klass == meta.java_lang_Short) {
        return (Short) meta.java_lang_Short_value.get(receiver);
    }
    if (klass == meta.java_lang_Integer) {
        return (Integer) meta.java_lang_Integer_value.get(receiver);
    }
    if (klass == meta.java_lang_Long) {
        return (Long) meta.java_lang_Long_value.get(receiver);
    }
    if (klass == meta.java_lang_Float) {
        return (Float) meta.java_lang_Float_value.get(receiver);
    }
    if (klass == meta.java_lang_Double) {
        return (Double) meta.java_lang_Double_value.get(receiver);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) InteropUtils.isAtMostFloat(com.oracle.truffle.espresso.runtime.InteropUtils.isAtMostFloat) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) InteropUtils.isAtMostByte(com.oracle.truffle.espresso.runtime.InteropUtils.isAtMostByte) InteropUtils.isAtMostLong(com.oracle.truffle.espresso.runtime.InteropUtils.isAtMostLong) InteropUtils.isAtMostShort(com.oracle.truffle.espresso.runtime.InteropUtils.isAtMostShort)

Aggregations

Meta (com.oracle.truffle.espresso.meta.Meta)82 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)29 Method (com.oracle.truffle.espresso.impl.Method)27 ExportMessage (com.oracle.truffle.api.library.ExportMessage)24 Klass (com.oracle.truffle.espresso.impl.Klass)21 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)21 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)21 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)20 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)17 ArityException (com.oracle.truffle.api.interop.ArityException)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)9 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)8 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)6 NativeType (com.oracle.truffle.espresso.ffi.NativeType)4 Field (com.oracle.truffle.espresso.impl.Field)4 ArrayList (java.util.ArrayList)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)3