Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ private void initialize() throws IOException {
if (insightFile.getFileName().toString().endsWith(".py")) {
language = "python";
}
if (insightFile.getFileName().toString().endsWith(".enso")) {
language = "enso";
}
var insightSrc =
Source.newBuilder("epb", insightFile.toFile())
.content(language + ":0#" + insightCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public InlineContext create() {
moduleScope.getModule().asCompilerModule(),
scala.Option.apply(false),
ensoCtx.getCompilerConfig(),
scala.Option.apply(pkgRepository));
scala.Option.apply(pkgRepository),
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public interface CompilerContext {
* @param diagnostic an IR node representing diagnostic information
* @param isOutputRedirected true if the output is not system's out. If true, no ANSI color escape
* characters will be inside the returned string.
* @param source a special source for the module
* @return exception with a message to display or to throw
*/
RuntimeException formatDiagnostic(
Module module, Diagnostic diagnostic, boolean isOutputRedirected);
Module module, Diagnostic diagnostic, boolean isOutputRedirected, Object source);

// threads
boolean isCreateThreadAllowed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ class Compiler(
)
.diagnostics
val module = inlineContext.getModule()
val hasErrors = reportDiagnostics(errors, module)
val hasErrors = reportDiagnostics(errors, module, inlineContext.src)
hasErrors match {
case error :: _ if inlineContext.compilerConfig.isStrictErrors =>
throw error
Expand All @@ -1016,7 +1016,7 @@ class Compiler(
List((module, errors))
}

val hasErrors = reportDiagnostics(diagnostics)
val hasErrors = reportDiagnostics(diagnostics, null)
if (hasErrors.nonEmpty && config.isStrictErrors) {
val count =
diagnostics.map(_._2.collect { case e: Error => e }.length).sum
Expand Down Expand Up @@ -1108,11 +1108,12 @@ class Compiler(
* @return whether any errors were encountered.
*/
private def reportDiagnostics(
diagnostics: List[(Module, List[Diagnostic])]
diagnostics: List[(Module, List[Diagnostic])],
src: Object
): List[RuntimeException] = {
diagnostics.flatMap { diags =>
if (diags._2.nonEmpty) {
reportDiagnostics(diags._2, diags._1)
reportDiagnostics(diags._2, diags._1, src)
} else {
List()
}
Expand All @@ -1128,13 +1129,19 @@ class Compiler(
*/
private def reportDiagnostics(
diagnostics: List[Diagnostic],
compilerModule: CompilerContext.Module
compilerModule: CompilerContext.Module,
src: Object
): List[RuntimeException] = {
val isOutputRedirected = config.outputRedirect.isDefined
val exceptions = diagnostics
.flatMap { diag =>
val formattedDiag =
context.formatDiagnostic(compilerModule, diag, isOutputRedirected)
context.formatDiagnostic(
compilerModule,
diag,
isOutputRedirected,
src
)
printDiagnostic(formattedDiag.getMessage)
if (diag.isInstanceOf[Error] || config.treatWarningsAsErrors) {
Some(formattedDiag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.enso.compiler.pass.PassConfiguration
*
* @param moduleContext the module in which the expression is being executed
* @param compilerConfig the compiler configuration
* @param src inline context may need reference to special source
* @param localScope the local scope in which the expression is being executed
* @param isInTailPosition whether or not the inline expression occurs in tail
* position ([[None]] indicates no information)
Expand All @@ -20,6 +21,7 @@ import org.enso.compiler.pass.PassConfiguration
case class InlineContext(
private val moduleContext: ModuleContext,
compilerConfig: CompilerConfig,
src: Object = null,
localScope: Option[LocalScope] = None,
isInTailPosition: Option[Boolean] = None,
freshNameSupply: Option[FreshNameSupply] = None,
Expand Down Expand Up @@ -52,14 +54,16 @@ object InlineContext {
module: CompilerContext.Module,
isInTailPosition: Option[Boolean],
compilerConfig: CompilerConfig,
pkgRepo: Option[PackageRepository]
pkgRepo: Option[PackageRepository],
src: Object
): InlineContext = {
InlineContext(
localScope = Option(localScope),
moduleContext = ModuleContext(module, compilerConfig),
isInTailPosition = isInTailPosition,
compilerConfig = compilerConfig,
pkgRepo = pkgRepo
pkgRepo = pkgRepo,
src = src
)
}

Expand All @@ -77,7 +81,8 @@ object InlineContext {
freshNameSupply = moduleContext.freshNameSupply,
passConfiguration = moduleContext.passConfiguration,
compilerConfig = moduleContext.compilerConfig,
pkgRepo = moduleContext.pkgRepo
pkgRepo = moduleContext.pkgRepo,
src = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Module findTopScopeModule(String name) {

@Override
public RuntimeException formatDiagnostic(
Module module, Diagnostic diagnostic, boolean isOutputRedirected) {
Module module, Diagnostic diagnostic, boolean isOutputRedirected, Object src) {
return new DiagnosticException((MockModule) module, diagnostic, isOutputRedirected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import java.util.ArrayList;
import org.enso.interpreter.runtime.callable.UnresolvedConstructor;
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
Expand Down Expand Up @@ -53,6 +57,7 @@ public static Object[][] allPossibleEnsoInterpreterValues() throws Exception {
}
data.add(new Object[] {UnresolvedSymbol.build("unknown_name", null), "Function"});
data.add(new Object[] {UnresolvedConstructor.build(null, "Unknown_Name"), "Function"});
data.add(new Object[] {new PolyArray(), "Array"});
ctxRule.context().leave();
return data.toArray(new Object[0][]);
}
Expand Down Expand Up @@ -99,4 +104,27 @@ class ForeignObject implements TruffleObject {}
assertTrue("It is meta object: " + symbolTypeValue, symbolTypeValue.isMetaObject());
assertEquals(expectedTypeName, symbolTypeValue.getMetaSimpleName());
}

@ExportLibrary(InteropLibrary.class)
static final class PolyArray implements TruffleObject {
@ExportMessage
boolean hasArrayElements() {
return true;
}

@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
throw InvalidArrayIndexException.create(index);
}

@ExportMessage
long getArraySize() {
return 0L;
}

@ExportMessage
boolean isArrayElementReadable(long index) {
return false;
}
}
}
Loading
Loading