Skip to content

Commit

Permalink
Fallback to old parser when the .so file of the new one cannot be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Nov 9, 2022
1 parent 54857c1 commit 2a61405
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 14 additions & 2 deletions engine/runtime/src/main/java/org/enso/compiler/EnsoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ public final class EnsoCompiler implements AutoCloseable {
private final Parser parser;

public EnsoCompiler() {
this.parser = Parser.create();
Parser p;
try {
p = Parser.create();
} catch (LinkageError err) {
p = null;
}
this.parser = p;
}

@Override
public void close() throws Exception {
this.parser.close();
if (parser != null) {
parser.close();
}
}

boolean isReady() {
return parser != null;
}

IR.Module compile(Source src) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Compiler(
private val serializationManager: SerializationManager =
new SerializationManager(this)
private val logger: TruffleLogger = context.getLogger(getClass)
private val ensoCompiler: EnsoCompiler = new EnsoCompiler();
private lazy val ensoCompiler: EnsoCompiler = new EnsoCompiler();

/** Run the initialization sequence. */
def initialize(): Unit = {
Expand Down Expand Up @@ -445,14 +445,11 @@ class Compiler(
val tree = parse(src)
generateIR(tree)
}
def newParser() = {
val expr = if (!"scala".equals(System.getenv("ENSO_PARSER")) && ensoCompiler.isReady()) {
val tree = ensoCompiler.parse(src)
ensoCompiler.generateIR(tree)
}
val expr = if ("scala".equals(System.getenv("ENSO_PARSER"))) {
oldParser()
} else {
newParser()
oldParser()
}

val exprWithModuleExports =
Expand Down

0 comments on commit 2a61405

Please sign in to comment.