-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure Enso FrameDescriptors have non-null default value (#6977)
- Loading branch information
1 parent
e6652b8
commit 9f39fb3
Showing
8 changed files
with
180 additions
and
36 deletions.
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
engine/runtime-with-polyglot/src/test/java/org/enso/interpreter/test/InsightForEnsoTest.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import org.enso.polyglot.RuntimeOptions; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Language; | ||
import org.graalvm.polyglot.Source; | ||
import org.junit.After; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class InsightForEnsoTest { | ||
private Context ctx; | ||
private AutoCloseable insightHandle; | ||
private final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
|
||
@Before | ||
public void initContext() throws Exception { | ||
this.ctx = Context.newBuilder() | ||
.allowExperimentalOptions(true) | ||
.option( | ||
RuntimeOptions.LANGUAGE_HOME_OVERRIDE, | ||
Paths.get("../../distribution/component").toFile().getAbsolutePath() | ||
) | ||
.logHandler(OutputStream.nullOutputStream()) | ||
.allowExperimentalOptions(true) | ||
.allowIO(true) | ||
.out(out) | ||
.allowAllAccess(true) | ||
.build(); | ||
|
||
var engine = ctx.getEngine(); | ||
Map<String, Language> langs = engine.getLanguages(); | ||
assertNotNull("Enso found: " + langs, langs.get("enso")); | ||
|
||
@SuppressWarnings("unchecked") | ||
var fn = (Function<Source,AutoCloseable>) engine.getInstruments().get("insight").lookup(Function.class); | ||
assertNotNull(fn); | ||
|
||
var insightScript = Source.newBuilder("js", """ | ||
insight.on('enter', (ctx, frame) => { | ||
print(`${ctx.name} at ${ctx.source.name}:${ctx.line}:`); | ||
let dump = ""; | ||
for (let p in frame) { | ||
dump += ` ${p}=${frame[p]}`; | ||
} | ||
print(dump); | ||
}, { | ||
roots : true | ||
}); | ||
""", "trace.js").build(); | ||
this.insightHandle = fn.apply(insightScript); | ||
} | ||
|
||
@After | ||
public void disposeContext() throws Exception { | ||
this.insightHandle.close(); | ||
this.ctx.close(); | ||
} | ||
|
||
@Test | ||
public void computeFactorial() throws Exception { | ||
var code = Source.newBuilder("enso", """ | ||
fac n = | ||
acc n v = if n <= 1 then v else | ||
@Tail_Call acc n-1 n*v | ||
acc n 1 | ||
""", "factorial.enso").build(); | ||
|
||
var m = ctx.eval(code); | ||
var fac = m.invokeMember("eval_expression", "fac"); | ||
var res = fac.execute(5); | ||
assertEquals(120, res.asInt()); | ||
|
||
var msgs = out.toString(); | ||
assertNotEquals("Step one: " + msgs, -1, msgs.indexOf("n=5 v=1 acc=function")); | ||
assertNotEquals("Step two: " + msgs, -1, msgs.indexOf("n=4 v=5 acc=function")); | ||
assertNotEquals("3rd step: " + msgs, -1, msgs.indexOf("n=3 v=20 acc=function")); | ||
assertNotEquals("4th step: " + msgs, -1, msgs.indexOf("n=2 v=60 acc=function")); | ||
|
||
assertNotEquals( | ||
"Uninitialized variables are seen as JavaScript null: " + msgs, | ||
-1, msgs.indexOf("n=null v=null acc=function") | ||
); | ||
} | ||
} |
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
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
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