99 */
1010package org .jruby .truffle .nodes .rubinius ;
1111
12- import com .oracle .truffle .api .CompilerDirectives ;
12+ import com .oracle .truffle .api .CompilerDirectives . TruffleBoundary ;
1313import com .oracle .truffle .api .dsl .Specialization ;
1414import com .oracle .truffle .api .source .SourceSection ;
15+
1516import org .jruby .Ruby ;
1617import org .jruby .RubyFixnum ;
1718import org .jruby .RubyNumeric ;
2021import org .jruby .truffle .nodes .core .BignumNodes ;
2122import org .jruby .truffle .runtime .RubyContext ;
2223import org .jruby .truffle .runtime .core .RubyBasicObject ;
23- import org .jruby .truffle .runtime .core .RubyBignum ;
2424
2525import java .math .BigInteger ;
2626
@@ -66,13 +66,13 @@ public RandomizerRandIntPrimitiveNode(RubyContext context, SourceSection sourceS
6666 }
6767
6868 @ Specialization
69- public long randomizerRandInt (RubyBasicObject random , Integer limit ) {
70- return RandomPrimitiveHelper . randomInt ( getContext (). getRuntime (). getCurrentContext (). getRuntime (), limit );
69+ public long randomizerRandInt (RubyBasicObject random , int limit ) {
70+ return randomizerRandLong ( random , ( long ) limit );
7171 }
7272
7373 @ Specialization
74- public long randomizerRandInt (RubyBasicObject random , Long limit ) {
75- return RandomPrimitiveHelper .randomInt (getContext ().getRuntime (). getCurrentContext (). getRuntime () , limit );
74+ public long randomizerRandLong (RubyBasicObject random , long limit ) {
75+ return RandomPrimitiveHelper .randomInt (getContext ().getRuntime (), limit );
7676 }
7777 }
7878
@@ -83,36 +83,29 @@ public RandomizerGenSeedPrimitiveNode(RubyContext context, SourceSection sourceS
8383 super (context , sourceSection );
8484 }
8585
86- @ CompilerDirectives . TruffleBoundary
86+ @ TruffleBoundary
8787 @ Specialization
8888 public RubyBasicObject randomizerGenSeed (RubyBasicObject random ) {
89- BigInteger integer = RandomPrimitiveHelper .randomSeed (getContext ().getRuntime (). getCurrentContext (). getRuntime () );
89+ BigInteger integer = RandomPrimitiveHelper .randomSeed (getContext ().getRuntime ());
9090 return BignumNodes .createRubyBignum (getContext ().getCoreLibrary ().getBignumClass (), integer );
9191 }
9292 }
9393
9494 static class RandomPrimitiveHelper {
9595
96- @ CompilerDirectives . TruffleBoundary
96+ @ TruffleBoundary
9797 public static BigInteger randomSeed (Ruby context ) {
9898 return RubyRandom .randomSeed (context ).getBigIntegerValue ();
9999 }
100100
101- @ CompilerDirectives . TruffleBoundary
101+ @ TruffleBoundary
102102 public static long randomInt (Ruby context , long limit ) {
103103 RubyFixnum fixnum = context .newFixnum (limit );
104104 return generateRandomInt (context , fixnum );
105105 }
106106
107- @ CompilerDirectives .TruffleBoundary
108- public static long randomInt (Ruby context , int limit ) {
109- RubyFixnum fixnum = context .newFixnum (limit );
110- return generateRandomInt (context , fixnum );
111- }
112-
113107 public static long generateRandomInt (Ruby context , RubyFixnum limit ) {
114- IRubyObject params [] = new IRubyObject [1 ];
115- params [0 ] = limit ;
108+ IRubyObject params [] = new IRubyObject [] { limit };
116109 RubyNumeric num = (RubyNumeric ) RubyRandom .randCommon19 (context .getCurrentContext (), null , params );
117110 return num .getLongValue ();
118111 }
0 commit comments