graalvm / simplelanguage

A simple example language built using the Truffle API.

Home Page:http://openjdk.java.net/projects/graal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for in-IDE builds, runs, and tests

maenu opened this issue · comments

commented

I'm trying to build my own language on Graal, therefore I checked out this repo and built it. I can get the examples to run on the Maven built Jars, e.g. sl HelloWorld.sl, but not from within Eclipse.

To run SLMain I use the same JVM arguments as in the POM for tests:

-XX:-UseJVMCIClassLoader
-Xbootclasspath/a:../graalvm/jre/lib/truffle/truffle-api.jar:../graalvm/jre/lib/truffle/locator.jar:../graalvm/jre/lib/truffle/truffle-nfi.jar:../graalvm/Contents/Home/jre/lib/truffle/truffle-api.jar:../graalvm/Contents/Home/jre/lib/truffle/locator.jar:../graalvm/Contents/Home/jre/lib/truffle/truffle-nfi.jar

When I run SLMain with HelloWorld.sl I get:

== running on org.graalvm.polyglot.Engine@34a245ab
Exception in thread "main" java.lang.IllegalStateException: A language with id 'sl' is not installed. Installed languages are: [R, js, python, llvm, ruby].
	at com.oracle.truffle.api.vm.PolyglotEngineImpl.requirePublicLanguage(PolyglotEngineImpl.java:556)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.requirePublicLanguage(PolyglotContextImpl.java:781)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.eval(PolyglotContextImpl.java:757)
	at org.graalvm.polyglot.Context.eval(Context.java:162)
	at com.oracle.truffle.sl.launcher.SLMain.executeSource(SLMain.java:99)
	at com.oracle.truffle.sl.launcher.SLMain.main(SLMain.java:85)

When I run the tests, not a single one passes, I get errors like:

java.lang.AssertionError: Error in eval
	at com.oracle.truffle.tck.DebuggerTester.expectSuspended(DebuggerTester.java:246)
	at com.oracle.truffle.sl.test.SLDebugTest.expectSuspended(SLDebugTest.java:111)
	at com.oracle.truffle.sl.test.SLDebugTest.testMetaObjects(SLDebugTest.java:530)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.IllegalStateException: A language with id 'sl' is not installed. Installed languages are: [R, js, meat, python, llvm, ruby, tck, truffletestinvoker].
	at com.oracle.truffle.api.vm.PolyglotEngineImpl.requirePublicLanguage(PolyglotEngineImpl.java:556)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.requirePublicLanguage(PolyglotContextImpl.java:781)
	at com.oracle.truffle.api.vm.PolyglotContextImpl.eval(PolyglotContextImpl.java:757)
	at org.graalvm.polyglot.Context.eval(Context.java:162)
	at com.oracle.truffle.tck.DebuggerTester$ExecutingLoop.run(DebuggerTester.java:544)
	at java.lang.Thread.run(Thread.java:748)

So, how can I run examples and tests from within Eclipse for a Truffle language project?

Did I miss something in the documentation that would tell me how to set this up, or is a Maven build always required? If that is the case, then what is magic happening in the build?
I assumed that the Maven build merely applies an annotation processor to generate the missing classes, but it would not require witch craft to do this for the Eclipse build.
I do not want to debug my languages by building with Maven, starting a JVM with remote debugging enabled, and then connect the remote debugger. Building with Maven is fine for CI, but I want to use the features of my IDE, requiring a Maven build for every execution harms the user experience a lot.

commented

Update: After I checked out simplelanguage again with a new Eclipse and workspace, without the second language I added, the tests run within Eclipse. Different from the previous setup, I added the VM args from the POM as the default arguments for the JVM (GraalVM) in the installed JRE properties. SLMain still does not work though.
BTW, Eclipse import in Oxygen is broken: Importing the existing Maven project (the parent) does not add the language folder as a subproject. I guess the issue is that the parent is checked out as a project named 'simplelanguage', which conflicts with the artifact name of the language submodule. To fix this I had to rename the parent project to simplelanguage-parent and reimport the submodules.

I'm trying to run SLMain from Intellij, I get the following error:

Exception in thread "main" java.lang.UnsupportedOperationException
at org.graalvm.polyglot.Engine$PolyglotInvalid.getSourceSectionImpl(Engine.java:579)
at org.graalvm.polyglot.Source.getImpl(Source.java:112)
at org.graalvm.polyglot.Source$Builder.build(Source.java:564)
at SLMain.main(SLMain.java:81)

I used the same flags as in the pom.xml file and set the JDK to the local graalvm.

I'm able to run tests fine but I need to run SLMain for debugging.

@maenu Do you mind sharing what maven dependency you use to install Python? I am running into similar exception "Caused by: java.lang.IllegalArgumentException: A language with id 'python' is not installed. Installed languages are: [js]." I suspect i didn't pull in python dependency in my gradle file. But looking in the artifacts i didn't see anything on the python here: https://mvnrepository.com/artifact/org.graalvm
my current dependency in gradle file is " compile 'org.graalvm.sdk:graal-sdk:19.+'
compile 'org.graalvm.js:js:19.+'" and it is working for JS. Can anyone let me know how to install Python through gradle?

commented

@yvonnecc I did not install Python, and I would assume the setup has changed in the two years since opening the issue. Maybe somebody else has pointers for you? I would search for Graal/Truffle/Python to find resources around Python on Graal.