- Clone JRuby 9k master
- Download http://lafo.ssw.uni-linz.ac.at/graalvm/openjdk-8-graalvm-b132-macosx-x86_64-0.7.tar.gz and untar into JRuby directory
- or http://lafo.ssw.uni-linz.ac.at/graalvm/openjdk-8-graalvm-b132-linux-x86_64-0.7.tar.gz
$ function jt { ruby tool/jt.rb $@; }
$ jt build
$ jt run --graal test/truffle/can-we-fold-yet.rb
$ jt run --graal test/truffle/can-we-fold-yet.rb test/truffle/can-we-fold-yet.rb
Can Truffle constant fold yet?
> 14
Yes! Truffle can constant fold this to 14
> 14 + 2
Yes! Truffle can constant fold this to 16
> eval([1, 2, 3].inspect).sort[1] * 2
Yes! Truffle can constant fold this to 4
> eval(rand < 0.5 ? '14 - 2' : '10 + 2')
Yes! Truffle can constant fold this to 12
> eval('rand')
No :( Truffle can't constant fold that
It's because strings are mutable. A dynamic value 14 is the same as a constant value 14, but
'foo' + 'bar'
generates a new value each time, so it's not clear how to make that constant.