Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Array Visualisation #1588

Merged
merged 5 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -27,8 +27,12 @@ class Module(private val value: Value) {
* @param name the name of the method
* @return the runtime representation of the method
*/
def getMethod(constructor: Value, name: String): Function =
new Function(value.invokeMember(GET_METHOD, constructor, name))
def getMethod(constructor: Value, name: String): Option[Function] = {
val newVal = value.invokeMember(GET_METHOD, constructor, name);
if (newVal.isNull) { None } else {
Some(new Function(newVal))
}
}

/** Evaluates an arbitrary expression as if it were placed in a function
* body inside this module.
Expand Down
19 changes: 13 additions & 6 deletions engine/runner/src/main/scala/org/enso/runner/Main.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.enso.runner

import java.io.File
import java.util.UUID

import akka.http.scaladsl.model.{IllegalUriException, Uri}
import cats.implicits._
import org.apache.commons.cli.{Option => CliOption, _}
Expand All @@ -12,8 +9,11 @@ import org.enso.loggingservice.LogLevel
import org.enso.pkg.{Contact, PackageManager, SemVerEnsoVersion}
import org.enso.polyglot.{LanguageInfo, Module, PolyglotContext}
import org.enso.version.VersionDescription
import org.graalvm.polyglot.{PolyglotException, Value}
import org.graalvm.polyglot.PolyglotException

import java.io.File
import java.util.UUID
import scala.Console.err
import scala.jdk.CollectionConverters._
import scala.util.Try

Expand Down Expand Up @@ -382,11 +382,18 @@ object Main {
mainModule: Module,
rootPkgPath: Option[File],
mainMethodName: String = "main"
): Value = {
): Unit = {
val mainCons = mainModule.getAssociatedConstructor
val mainFun = mainModule.getMethod(mainCons, mainMethodName)
try {
mainFun.execute(mainCons.newInstance())
mainFun match {
case Some(main) => main.execute(mainCons.newInstance())
case None =>
err.println(
"Your module does not contain a `main` function. It could not " +
iamrecursion marked this conversation as resolved.
Show resolved Hide resolved
"be run."
)
}
} catch {
case e: PolyglotException =>
printPolyglotException(e, rootPkgPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.File;
import java.io.IOException;

import java.util.Map;
import org.enso.compiler.core.IR;
import org.enso.compiler.phase.StubIrBuilder;
import org.enso.interpreter.Language;
Expand Down Expand Up @@ -405,7 +406,11 @@ static Object doInvoke(
ModuleScope scope = module.compileScope(context);
switch (member) {
case MethodNames.Module.GET_METHOD:
return getMethod(scope, arguments);
var result = getMethod(scope, arguments);
if (result == null) {
iamrecursion marked this conversation as resolved.
Show resolved Hide resolved
return context.getBuiltins().nothing().newInstance();
}
return result;
case MethodNames.Module.GET_CONSTRUCTOR:
return getConstructor(scope, arguments);
case MethodNames.Module.REPARSE:
Expand Down