use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoInterop method asInstant.
@ExportMessage
@TruffleBoundary
static Instant asInstant(StaticObject receiver, @CachedLibrary("receiver") InteropLibrary receiverLibrary, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (receiverLibrary.isInstant(receiver)) {
StaticObject instant;
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
instant = (StaticObject) meta.java_time_ZonedDateTime_toInstant.invokeDirect(receiver);
} else if (instanceOf(receiver, meta.java_util_Date)) {
int index = meta.java_util_Date_toInstant.getVTableIndex();
Method virtualToInstant = receiver.getKlass().vtableLookup(index);
instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
} else {
instant = receiver;
}
assert instanceOf(instant, meta.java_time_Instant);
long seconds = (long) meta.java_time_Instant_seconds.get(instant);
int nanos = (int) meta.java_time_Instant_nanos.get(instant);
return Instant.ofEpochSecond(seconds, nanos);
}
error.enter();
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.espresso.meta.Meta 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;
}
use of com.oracle.truffle.espresso.meta.Meta 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;
}
use of com.oracle.truffle.espresso.meta.Meta 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;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoInterop method isTime.
@ExportMessage
static boolean isTime(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Meta meta = receiver.getKlass().getMeta();
return instanceOf(receiver, meta.java_time_LocalTime) || instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_time_ZonedDateTime) || instanceOf(receiver, meta.java_util_Date);
}
Aggregations