Created
October 24, 2019 01:47
-
-
Save frsyuki/5ebe1e8b3f829a1f72f6cb7dcde225c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.File; | |
import java.io.IOException; | |
import org.graalvm.polyglot.Context; | |
import org.graalvm.polyglot.Source; | |
import org.graalvm.polyglot.Value; | |
public class GraalPolyglot { | |
public static void main(String[] args) throws IOException { | |
Source source = Source.newBuilder("ruby", new File(args[0])).build(); | |
try (Context context = Context.newBuilder().allowAllAccess(true).build()) { | |
context.eval(source); | |
} | |
} | |
} |
This file contains hidden or 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
$ java GraalPolyglot test.rb | |
1 | |
Exception in thread "main" org.graalvm.polyglot.PolyglotException: org.truffleruby.language.control.RaiseException: <no message> (EngineException) | |
Translated to internal error (RuntimeError) | |
at com.oracle.truffle.api.TruffleStackTrace.materializeHostException(TruffleStackTrace.java:103) | |
at com.oracle.truffle.api.TruffleStackTrace.materializeHostFrames(TruffleStackTrace.java:162) | |
at com.oracle.truffle.api.LanguageAccessor$LanguageImpl.materializeHostFrames(LanguageAccessor.java:119) | |
at com.oracle.truffle.polyglot.PolyglotExceptionImpl.<init>(PolyglotExceptionImpl.java:175) | |
at com.oracle.truffle.polyglot.PolyglotExceptionImpl.<init>(PolyglotExceptionImpl.java:98) | |
at com.oracle.truffle.polyglot.PolyglotImpl.wrapGuestException(PolyglotImpl.java:366) | |
at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:817) | |
at org.graalvm.polyglot.Context.eval(Context.java:344) | |
at GraalPolyglot.main(GraalPolyglot.java:12) | |
at <ruby> <top (required)>(Unknown) | |
at <ruby> parsing-request(Unknown) | |
Original Internal Error: | |
org.truffleruby.language.control.RaiseException: <no message> (EngineException) | |
Translated to internal error (RuntimeError) | |
Caused by: Attached Guest Language Frames (2) | |
$ java -version | |
openjdk version "1.8.0_232" | |
OpenJDK Runtime Environment (build 1.8.0_232-20191009173705.graal.jdk8u-src-tar-gz-b07) | |
OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode) |
This file contains hidden or 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
Java.import 'org.graalvm.polyglot.Context' | |
context = Context.newBuilder().allowAllAccess(true).build | |
begin | |
#v = 'Ruby String' | |
#context.getBindings("js").putMember("v", v.to_java) | |
#js = <<~JS | |
#print('v=' + v) | |
#JS | |
#context.eval("js", js) | |
context.eval("js", 'print(1)') | |
ensure | |
context.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment