mutao.net

いわゆる雑記。

GraalVM②

  • Graalは言語間で呼び出しができるらしいのでお試しテスト

JavaScript -> Java

$ js
> const array = new(Java.type("int[]"))(2)
> array[1] = 1
1
  • 記法全然わからないけどうまくいったみたい

Ruby いれてみた

gu install ruby
Downloading: Component catalog from www.graalvm.org
Processing Component: TruffleRuby
Additional Components are required:
    LLVM.org toolchain (org.graalvm.llvm-toolchain, version 20.0.0), required by: TruffleRuby (org.graalvm.ruby)
Processing Component: LLVM.org toolchain
Downloading: Component ruby: TruffleRuby  from github.com
Downloading: Component org.graalvm.llvm-toolchain: LLVM.org toolchain  from github.com
Installing new component: TruffleRuby (org.graalvm.ruby, version 20.0.0)
Installing new component: LLVM.org toolchain (org.graalvm.llvm-toolchain, version 20.0.0)

IMPORTANT NOTE:
---------------
The Ruby openssl C extension needs to be recompiled on your system to work with the installed libssl.
First, make sure TruffleRuby's dependencies are installed, which are described at:
  https://github.com/oracle/truffleruby/blob/master/README.md#dependencies
Then run the following command:
        /usr/local/graalvm-ce/languages/ruby/lib/truffle/post_install_hook.sh


IMPORTANT NOTE:
---------------
Set of GraalVM components that provide language implementations have changed. The Polyglot native image and polyglot native C library may be out of sync:
- new languages may not be accessible
- removed languages may cause the native binary to fail on missing resources or libraries.
To rebuild and refresh the native binaries, use the following command:
        /usr/local/graalvm-ce/bin/gu rebuild-images
$ ruby -v
truffleruby 20.0.0, like ruby 2.6.5, GraalVM CE Native [x86_64-linux]
array = Polyglot.eval('js', '[1,2,3,4]');
puts array[2];
  • 実行
$ ruby --polyglot --jvm test.rb
3

Polyglot って何?

  • GrralVm上のTruffleRubyでは Polyglot.eval() メソッドに言語のidと実行するコードを渡して実行する
  • 実行時には --polyglot --jvm のようにオプションをつける