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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations