Implement toDisplayString on some truffle objects

This commit is contained in:
Pavel Marek 2024-11-15 11:41:55 +01:00
parent 06d1d4c950
commit 62aefe54cc
3 changed files with 23 additions and 1 deletions

View File

@ -772,10 +772,17 @@ public final class EnsoFile extends EnsoObject {
return fromString(context, System.getProperty("user.home"));
}
@ExportMessage
@TruffleBoundary
@Override
public String toDisplayString(boolean allowSideEffects) {
return "(File " + truffleFile.getPath() + ")";
}
@Override
@TruffleBoundary
public String toString() {
return "(File " + truffleFile.getPath() + ")";
return toDisplayString(false);
}
@ExportMessage

View File

@ -1,5 +1,6 @@
package org.enso.interpreter.runtime.data;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
@ -93,4 +94,11 @@ public final class ManagedResource extends EnsoObject {
Type getType(@Bind("$node") Node node) {
return EnsoContext.get(node).getBuiltins().managedResource();
}
@ExportMessage
@TruffleBoundary
@Override
public String toDisplayString(boolean allowSideEffects) {
return resource.toString();
}
}

View File

@ -2,6 +2,7 @@ package org.enso.interpreter.runtime.data;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import com.oracle.truffle.api.nodes.Node;
@ -68,4 +69,10 @@ public final class Ref extends EnsoObject {
Type getType(@Bind("$node") Node node) {
return EnsoContext.get(node).getBuiltins().ref();
}
@ExportMessage
Object toDisplayString(
boolean allowSideEffects, @CachedLibrary(limit = "3") InteropLibrary interop) {
return interop.toDisplayString(value, allowSideEffects);
}
}