Skip to content

Commit

Permalink
StaticObject.rawForeignObject() now requires EspressoLanguage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ansalond committed May 17, 2021
1 parent 1f99944 commit 389079b
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Object readMember(String member,
if (field != null) {
Object result = field.get(this.tryInitializeAndGetStatics());
if (result instanceof StaticObject && ((StaticObject) result).isForeignObject()) {
return ((StaticObject) result).rawForeignObject();
return ((StaticObject) result).rawForeignObject(getEspressoLanguage());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected Object getForeignField(StaticObject receiver, InteropLibrary interopLi
assert !field.isStatic();
Object value;
try {
value = interopLibrary.readMember(receiver.rawForeignObject(), fieldName);
value = interopLibrary.readMember(receiver.rawForeignObject(context.getLanguage()), fieldName);
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
error.enter();
Meta meta = context.getMeta();
Expand Down Expand Up @@ -117,7 +117,7 @@ int doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asInt(receiver.rawForeignObject());
return interopLibrary.asInt(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -126,9 +126,9 @@ int doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
int doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
int doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -171,7 +171,7 @@ boolean doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asBoolean(receiver.rawForeignObject());
return interopLibrary.asBoolean(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -180,9 +180,9 @@ boolean doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
boolean doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
boolean doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -225,7 +225,7 @@ char doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
String foreignString = interopLibrary.asString(receiver.rawForeignObject());
String foreignString = interopLibrary.asString(receiver.rawForeignObject(context.getLanguage()));
if (foreignString.length() != 1) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -240,9 +240,9 @@ char doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
char doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
char doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -285,7 +285,7 @@ short doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asShort(receiver.rawForeignObject());
return interopLibrary.asShort(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -294,9 +294,9 @@ short doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
short doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
short doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -339,7 +339,7 @@ byte doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asByte(receiver.rawForeignObject());
return interopLibrary.asByte(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -348,9 +348,9 @@ byte doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
byte doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
byte doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -393,7 +393,7 @@ long doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asLong(receiver.rawForeignObject());
return interopLibrary.asLong(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -402,9 +402,9 @@ long doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
long doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
long doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -447,7 +447,7 @@ float doForeignValue(StaticObject receiver,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asFloat(receiver.rawForeignObject());
return interopLibrary.asFloat(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -456,9 +456,9 @@ float doForeignValue(StaticObject receiver,
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
float doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
float doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -501,7 +501,7 @@ public int getField(VirtualFrame frame, long[] primitives, Object[] refs, Byteco
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
try {
return interopLibrary.asDouble(receiver.rawForeignObject());
return interopLibrary.asDouble(receiver.rawForeignObject(context.getLanguage()));
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
Expand All @@ -510,9 +510,9 @@ public int getField(VirtualFrame frame, long[] primitives, Object[] refs, Byteco
}

@Specialization(guards = {"receiver.isForeignObject()", "!isValueField(context)"}, limit = "CACHED_LIBRARY_LIMIT")
double doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
double doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down Expand Up @@ -553,9 +553,9 @@ StaticObject doEspresso(StaticObject receiver) {
}

@Specialization(guards = "receiver.isForeignObject()", limit = "CACHED_LIBRARY_LIMIT")
StaticObject doForeign(StaticObject receiver, @CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
StaticObject doForeign(StaticObject receiver, @CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached ToEspressoNode toEspressoNode,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@Cached BranchProfile error) {
Object value = getForeignField(receiver, interopLibrary, context, error);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void setForeignField(StaticObject receiver, Object fieldValue,
assert receiver.isForeignObject();
assert !(fieldValue instanceof StaticObject) || !((StaticObject) fieldValue).isForeignObject();
try {
interopLibrary.writeMember(receiver.rawForeignObject(), fieldName, fieldValue);
interopLibrary.writeMember(receiver.rawForeignObject(context.getLanguage()), fieldName, fieldValue);
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
error.enter();
Meta meta = context.getMeta();
Expand Down Expand Up @@ -115,8 +115,8 @@ void doEspresso(StaticObject receiver, int value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, int fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -144,8 +144,8 @@ void doEspresso(StaticObject receiver, boolean value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, boolean fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -173,8 +173,8 @@ void doEspresso(StaticObject receiver, char value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, char fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -202,8 +202,8 @@ void doEspresso(StaticObject receiver, short value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, short fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -231,8 +231,8 @@ void doEspresso(StaticObject receiver, byte value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, byte fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -260,8 +260,8 @@ void doEspresso(StaticObject receiver, long value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, long fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -289,8 +289,8 @@ void doEspresso(StaticObject receiver, float value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, float fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -318,8 +318,8 @@ void doEspresso(StaticObject receiver, double value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, double fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue, interopLibrary, context, error);
}
Expand Down Expand Up @@ -347,9 +347,9 @@ void doEspresso(StaticObject receiver, StaticObject value) {

@Specialization(guards = {"receiver.isForeignObject()"}, limit = "CACHED_LIBRARY_LIMIT")
void doForeign(StaticObject receiver, StaticObject fieldValue,
@CachedLibrary("receiver.rawForeignObject()") InteropLibrary interopLibrary,
@CachedContext(EspressoLanguage.class) EspressoContext context,
@CachedLibrary("receiver.rawForeignObject(context.getLanguage())") InteropLibrary interopLibrary,
@Cached BranchProfile error) {
setForeignField(receiver, fieldValue.isForeignObject() ? fieldValue.rawForeignObject() : fieldValue, interopLibrary, context, error);
setForeignField(receiver, fieldValue.isForeignObject() ? fieldValue.rawForeignObject(context.getLanguage()) : fieldValue, interopLibrary, context, error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final Object execute(Method method, Object receiver, Object[] arguments)
* Espresso and unwrapped when going out)
*/
if (result instanceof StaticObject && ((StaticObject) result).isForeignObject()) {
return ((StaticObject) result).rawForeignObject();
return ((StaticObject) result).rawForeignObject(method.getEspressoLanguage());
}
return result;
}
Expand Down
Loading

0 comments on commit 389079b

Please sign in to comment.