Skip to content

Commit

Permalink
Rename readTruffleStringPropertyOfObject(Un)Cached to remove the OfOb…
Browse files Browse the repository at this point in the history
…ject part.
  • Loading branch information
skinny85 committed Mar 25, 2024
1 parent 624482f commit 410adc6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* the difference is we add extra specializations for when strings are used as the index,
* in code like {@code a["b"]} (which, in JavaScript, is equivalent to {@code a.b}).
*
* @see #readTruffleStringPropertyOfObjectCached
* @see #readTruffleStringPropertyOfObjectUncached
* @see #readTruffleStringPropertyCached
* @see #readTruffleStringPropertyUncached
*/
@NodeChild("arrayExpr")
@NodeChild("indexExpr")
Expand All @@ -34,7 +34,8 @@ public abstract class ArrayIndexReadExprNode extends EasyScriptExprNode {
* in code like {@code [1, 2][1]}.
*/
@Specialization(guards = "arrayInteropLibrary.isArrayElementReadable(array, index)", limit = "2")
protected Object readIntIndexOfArray(Object array, int index,
protected Object readIntIndexOfArray(
Object array, int index,
@CachedLibrary("array") InteropLibrary arrayInteropLibrary) {
try {
return arrayInteropLibrary.readArrayElement(array, index);
Expand All @@ -52,12 +53,11 @@ protected Object readIntIndexOfArray(Object array, int index,
* for a maximum of two different names.
* If the given indexed property access sees more than two different names,
* then we switch to the uncached variant,
* {@link #readTruffleStringPropertyOfObjectUncached}.
* {@link #readTruffleStringPropertyUncached}.
*/
@Specialization(guards = "equals(propertyName, cachedPropertyName, equalNode)", limit = "2")
protected Object readTruffleStringPropertyOfObjectCached(
Object target,
@SuppressWarnings("unused") TruffleString propertyName,
protected Object readTruffleStringPropertyCached(
Object target, @SuppressWarnings("unused") TruffleString propertyName,
@Cached @SuppressWarnings("unused") TruffleString.EqualNode equalNode,
@Cached("propertyName") @SuppressWarnings("unused") TruffleString cachedPropertyName,
@Cached @SuppressWarnings("unused") TruffleString.ToJavaStringNode toJavaStringNode,
Expand All @@ -69,11 +69,12 @@ protected Object readTruffleStringPropertyOfObjectCached(
/**
* A specialization for reading a string property of an object,
* in code like {@code [1, 2]['length']}, or {@code "a"['length']}.
* This is the uncached variant of the {@link #readTruffleStringPropertyOfObjectCached}
* This is the uncached variant of the {@link #readTruffleStringPropertyCached}
* specialization, used when this indexed property access sees more than two different property names.
*/
@Specialization(replaces = "readTruffleStringPropertyOfObjectCached")
protected Object readTruffleStringPropertyOfObjectUncached(Object target, TruffleString propertyName,
@Specialization(replaces = "readTruffleStringPropertyCached")
protected Object readTruffleStringPropertyUncached(
Object target, TruffleString propertyName,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached CommonReadPropertyNode commonReadPropertyNode) {
return commonReadPropertyNode.executeReadProperty(target,
Expand All @@ -85,7 +86,8 @@ protected Object readTruffleStringPropertyOfObjectUncached(Object target, Truffl
* in code like {@code "a"[0]}, or {@code [1, 2][undefined]}.
*/
@Fallback
protected Object readNonTruffleStringPropertyOfObject(Object target, Object index,
protected Object readNonTruffleStringPropertyOfObject(
Object target, Object index,
@Cached CommonReadPropertyNode commonReadPropertyNode) {
return commonReadPropertyNode.executeReadProperty(target, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public abstract class ArrayIndexReadExprNode extends EasyScriptExprNode {
* in code like {@code [1, 2][1]}.
*/
@Specialization(guards = "arrayInteropLibrary.isArrayElementReadable(array, index)", limit = "2")
protected Object readIntIndexOfArray(Object array, int index,
protected Object readIntIndexOfArray(
Object array, int index,
@CachedLibrary("array") InteropLibrary arrayInteropLibrary) {
try {
return arrayInteropLibrary.readArrayElement(array, index);
Expand All @@ -43,9 +44,8 @@ protected Object readIntIndexOfArray(Object array, int index,
* in code like {@code [1, 2]['length']}, or {@code "a"['length']}.
*/
@Specialization(guards = "equals(propertyName, cachedPropertyName, equalNode)", limit = "2")
protected Object readTruffleStringPropertyOfObjectCached(
Object target,
@SuppressWarnings("unused") TruffleString propertyName,
protected Object readTruffleStringPropertyCached(
Object target, @SuppressWarnings("unused") TruffleString propertyName,
@Cached @SuppressWarnings("unused") TruffleString.EqualNode equalNode,
@Cached("propertyName") @SuppressWarnings("unused") TruffleString cachedPropertyName,
@Cached @SuppressWarnings("unused") TruffleString.ToJavaStringNode toJavaStringNode,
Expand All @@ -58,8 +58,9 @@ protected Object readTruffleStringPropertyOfObjectCached(
* The uncached variant of the specialization for reading a string property of an object,
* in code like {@code [1, 2]['length']}, or {@code "a"['length']}.
*/
@Specialization(replaces = "readTruffleStringPropertyOfObjectCached")
protected Object readTruffleStringPropertyOfObjectUncached(Object target, TruffleString propertyName,
@Specialization(replaces = "readTruffleStringPropertyCached")
protected Object readTruffleStringPropertyUncached(
Object target, TruffleString propertyName,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached CommonReadPropertyNode commonReadPropertyNode) {
return commonReadPropertyNode.executeReadProperty(target,
Expand All @@ -71,7 +72,8 @@ protected Object readTruffleStringPropertyOfObjectUncached(Object target, Truffl
* in code like {@code "a"[0]}, or {@code [1, 2][undefined]}.
*/
@Fallback
protected Object readNonTruffleStringPropertyOfObject(Object target, Object index,
protected Object readNonTruffleStringPropertyOfObject(
Object target, Object index,
@Cached CommonReadPropertyNode commonReadPropertyNode) {
return commonReadPropertyNode.executeReadProperty(target, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.endoflineblog.truffle.part_13.exceptions.EasyScriptException;
import com.endoflineblog.truffle.part_13.nodes.exprs.EasyScriptExprNode;
import com.endoflineblog.truffle.part_13.nodes.exprs.properties.CommonReadPropertyNode;
import com.endoflineblog.truffle.part_13.nodes.exprs.properties.CommonWritePropertyNode;
import com.endoflineblog.truffle.part_13.runtime.EasyScriptTruffleStrings;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
Expand Down Expand Up @@ -64,7 +63,7 @@ protected Object readIntIndexOfArray(
* in code like {@code [1, 2]['length']}, or {@code "a"['length']}.
*/
@Specialization(guards = "equals(propertyName, cachedPropertyName, equalNode)", limit = "2")
protected Object readTruffleStringPropertyOfObjectCached(
protected Object readTruffleStringPropertyCached(
Object target,
@SuppressWarnings("unused") TruffleString propertyName,
@Cached @SuppressWarnings("unused") TruffleString.EqualNode equalNode,
Expand All @@ -79,8 +78,8 @@ protected Object readTruffleStringPropertyOfObjectCached(
* The uncached variant of the specialization for reading a string property of an object,
* in code like {@code [1, 2]['length']}, or {@code "a"['length']}.
*/
@Specialization(replaces = "readTruffleStringPropertyOfObjectCached")
protected Object readTruffleStringPropertyOfObjectUncached(
@Specialization(replaces = "readTruffleStringPropertyCached")
protected Object readTruffleStringPropertyUncached(
Object target, TruffleString propertyName,
@Cached TruffleString.ToJavaStringNode toJavaStringNode,
@Cached CommonReadPropertyNode commonReadPropertyNode) {
Expand Down

0 comments on commit 410adc6

Please sign in to comment.