Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
}
}
}
$ 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)
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