Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quick-fix for Error.to_text CCE (#3357)
This is just a quick fix addressing an issue which was making debugging problematic. The proper solution to the broader issue described at #1538 (comment) still needs to be done.
- Loading branch information
Showing
3 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 17 additions & 2 deletions
19
...ime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ErrorToTextNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
package org.enso.interpreter.node.expression.builtin.error; | ||
|
||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.AcceptsError; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.runtime.callable.atom.Atom; | ||
import org.enso.interpreter.runtime.data.text.Text; | ||
import org.enso.interpreter.runtime.error.DataflowError; | ||
|
||
@BuiltinMethod(type = "Error", name = "to_text", description = "Convert an error to text.") | ||
public class ErrorToTextNode extends Node { | ||
public abstract class ErrorToTextNode extends Node { | ||
private static final int DISPATCH_CACHE = 3; | ||
private @Child InteropLibrary displays = | ||
InteropLibrary.getFactory().createDispatched(DISPATCH_CACHE); | ||
private @Child InteropLibrary strings = | ||
InteropLibrary.getFactory().createDispatched(DISPATCH_CACHE); | ||
|
||
public Text execute(DataflowError _this) { | ||
static ErrorToTextNode build() { | ||
return ErrorToTextNodeGen.create(); | ||
} | ||
|
||
public abstract Text execute(@AcceptsError Object _this); | ||
|
||
@Specialization | ||
public Text doDataflowError(DataflowError _this) { | ||
try { | ||
return Text.create(strings.asString(displays.toDisplayString(_this))); | ||
} catch (UnsupportedMessageException ignored) { | ||
throw new IllegalStateException("Unreachable"); | ||
} | ||
} | ||
|
||
@Specialization | ||
public Text doAtom(Atom _this) { | ||
return Text.create("Error"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters