9
9
*/
10
10
package org .jruby .truffle .nodes .rubinius ;
11
11
12
- import com .oracle .truffle .api .CompilerDirectives ;
12
+ import com .oracle .truffle .api .CompilerDirectives . TruffleBoundary ;
13
13
import com .oracle .truffle .api .dsl .Specialization ;
14
14
import com .oracle .truffle .api .source .SourceSection ;
15
+
15
16
import org .jruby .Ruby ;
16
17
import org .jruby .RubyFixnum ;
17
18
import org .jruby .RubyNumeric ;
20
21
import org .jruby .truffle .nodes .core .BignumNodes ;
21
22
import org .jruby .truffle .runtime .RubyContext ;
22
23
import org .jruby .truffle .runtime .core .RubyBasicObject ;
23
- import org .jruby .truffle .runtime .core .RubyBignum ;
24
24
25
25
import java .math .BigInteger ;
26
26
@@ -66,13 +66,13 @@ public RandomizerRandIntPrimitiveNode(RubyContext context, SourceSection sourceS
66
66
}
67
67
68
68
@ 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 );
71
71
}
72
72
73
73
@ 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 );
76
76
}
77
77
}
78
78
@@ -83,36 +83,29 @@ public RandomizerGenSeedPrimitiveNode(RubyContext context, SourceSection sourceS
83
83
super (context , sourceSection );
84
84
}
85
85
86
- @ CompilerDirectives . TruffleBoundary
86
+ @ TruffleBoundary
87
87
@ Specialization
88
88
public RubyBasicObject randomizerGenSeed (RubyBasicObject random ) {
89
- BigInteger integer = RandomPrimitiveHelper .randomSeed (getContext ().getRuntime (). getCurrentContext (). getRuntime () );
89
+ BigInteger integer = RandomPrimitiveHelper .randomSeed (getContext ().getRuntime ());
90
90
return BignumNodes .createRubyBignum (getContext ().getCoreLibrary ().getBignumClass (), integer );
91
91
}
92
92
}
93
93
94
94
static class RandomPrimitiveHelper {
95
95
96
- @ CompilerDirectives . TruffleBoundary
96
+ @ TruffleBoundary
97
97
public static BigInteger randomSeed (Ruby context ) {
98
98
return RubyRandom .randomSeed (context ).getBigIntegerValue ();
99
99
}
100
100
101
- @ CompilerDirectives . TruffleBoundary
101
+ @ TruffleBoundary
102
102
public static long randomInt (Ruby context , long limit ) {
103
103
RubyFixnum fixnum = context .newFixnum (limit );
104
104
return generateRandomInt (context , fixnum );
105
105
}
106
106
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
-
113
107
public static long generateRandomInt (Ruby context , RubyFixnum limit ) {
114
- IRubyObject params [] = new IRubyObject [1 ];
115
- params [0 ] = limit ;
108
+ IRubyObject params [] = new IRubyObject [] { limit };
116
109
RubyNumeric num = (RubyNumeric ) RubyRandom .randCommon19 (context .getCurrentContext (), null , params );
117
110
return num .getLongValue ();
118
111
}
0 commit comments