Skip to content

Commit

Permalink
minor Truffle DSL/interop usage fixes (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasstadler authored Mar 3, 2020
1 parent 7547747 commit 1d0ca13
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ boolean isMemberInvocable(String memberName) {
@ExportMessage
Object invokeMember(String memberName,
Object[] arguments,
@CachedLibrary(limit = "1") InteropLibrary interopRead,
@CachedLibrary("this") InteropLibrary interopRead,
@CachedLibrary(limit = "1") InteropLibrary interopExecute)
throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ boolean isMemberInvocable(String memberName) {
@ExportMessage
Object invokeMember(String memberName,
Object[] arguments,
@CachedLibrary(limit = "1") InteropLibrary interopRead,
@CachedLibrary("this") InteropLibrary interopRead,
@CachedLibrary(limit = "1") InteropLibrary interopExecute)
throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;

Expand Down Expand Up @@ -101,18 +100,6 @@ public String toString() {

// Implementation of Truffle API

@ExportMessage
@SuppressWarnings("static-method")
boolean hasMembers() {
return false;
}

@ExportMessage
@SuppressWarnings("static-method")
Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
return null;
}

@ExportMessage
@SuppressWarnings("static-method")
boolean hasArrayElements() {
Expand All @@ -129,18 +116,6 @@ boolean isArrayElementReadable(long index) {
return index >= 0 && index < devices.length;
}

@SuppressWarnings("static-method")
@ExportMessage
boolean isArrayElementModifiable(@SuppressWarnings("unused") long index) {
return false;
}

@SuppressWarnings("static-method")
@ExportMessage
boolean isArrayElementInsertable(@SuppressWarnings("unused") long index) {
return false;
}

@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
if ((index < 0) || (index >= devices.length)) {
Expand All @@ -149,11 +124,4 @@ Object readArrayElement(long index) throws InvalidArrayIndexException {
}
return devices[(int) index];
}

@SuppressWarnings("static-method")
@ExportMessage
void writeArrayElement(@SuppressWarnings("unused") long index, @SuppressWarnings("unused") Object value) throws UnsupportedMessageException {
CompilerDirectives.transferToInterpreter();
throw UnsupportedMessageException.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import java.util.Optional;

import com.nvidia.grcuda.gpu.CUDARuntime.CUDADeviceAttribute;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
import com.oracle.truffle.api.interop.TruffleObject;
Expand Down Expand Up @@ -72,15 +72,16 @@ Object getMembers(boolean includeInternal) {
}

@ExportMessage
@TruffleBoundary
@SuppressWarnings("static-method")
boolean isMemberReadable(String member) {
return PROPERTY_SET.contains(member);
}

@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
if (!isMemberReadable(member)) {
CompilerDirectives.transferToInterpreter();
throw UnknownIdentifierException.create(member);
}
Object value = properties.get(member);
Expand Down Expand Up @@ -146,14 +147,15 @@ public long getArraySize() {
}

@ExportMessage
@TruffleBoundary
public boolean isArrayElementReadable(long index) {
return index >= 0 && index < propertyMap.size();
}

@ExportMessage
@TruffleBoundary
public Object readArrayElement(long index) throws InvalidArrayIndexException {
if ((index < 0) || (index >= propertyMap.size())) {
CompilerDirectives.transferToInterpreter();
throw InvalidArrayIndexException.create(index);
}
return names[(int) index];
Expand Down

0 comments on commit 1d0ca13

Please sign in to comment.