20
20
21
21
package org .truffleruby .core .cast ;
22
22
23
- import com .oracle .truffle .api .dsl .Bind ;
23
+ import com .oracle .truffle .api .dsl .GenerateCached ;
24
+ import com .oracle .truffle .api .dsl .GenerateInline ;
24
25
import com .oracle .truffle .api .nodes .Node ;
25
26
import org .truffleruby .core .numeric .RubyBignum ;
26
27
import org .truffleruby .core .string .StringUtils ;
35
36
import org .truffleruby .language .objects .LogicalClassNode ;
36
37
37
38
/** This is a port of MRI's rb_cmpint, as taken from RubyComparable and broken out into specialized nodes. */
39
+ @ GenerateInline
40
+ @ GenerateCached (false )
38
41
public abstract class CmpIntNode extends RubyBaseNode {
39
42
40
- public static CmpIntNode create () {
41
- return CmpIntNodeGen .create ();
42
- }
43
-
44
- public abstract int executeCmpInt (Object cmpResult , Object a , Object b );
43
+ public abstract int executeCmpInt (Node node , Object cmpResult , Object a , Object b );
45
44
46
45
@ Specialization
47
- int cmpInt (int value , Object receiver , Object other ) {
46
+ static int cmpInt (int value , Object receiver , Object other ) {
48
47
return value ;
49
48
}
50
49
51
50
@ Specialization
52
- int cmpLong (long value , Object receiver , Object other ) {
51
+ static int cmpLong (long value , Object receiver , Object other ) {
53
52
if (value > 0 ) {
54
53
return 1 ;
55
54
}
@@ -62,30 +61,30 @@ int cmpLong(long value, Object receiver, Object other) {
62
61
}
63
62
64
63
@ Specialization
65
- int cmpBignum (RubyBignum value , Object receiver , Object other ) {
64
+ static int cmpBignum (RubyBignum value , Object receiver , Object other ) {
66
65
return value .value .signum ();
67
66
}
68
67
69
68
@ Specialization
70
- int cmpNil (Nil nil , Object receiver , Object other ) {
71
- throw new RaiseException (getContext (), coreExceptions ().argumentError (formatMessage (receiver , other ), this ));
69
+ static int cmpNil (Node node , Nil nil , Object receiver , Object other ) {
70
+ throw new RaiseException (getContext (node ),
71
+ coreExceptions (node ).argumentError (formatMessage (receiver , other ), node ));
72
72
}
73
73
74
74
@ TruffleBoundary
75
- private String formatMessage (Object receiver , Object other ) {
75
+ private static String formatMessage (Object receiver , Object other ) {
76
76
return StringUtils .format (
77
77
"comparison of %s with %s failed" ,
78
78
LogicalClassNode .getUncached ().execute (receiver ).fields .getName (),
79
79
LogicalClassNode .getUncached ().execute (other ).fields .getName ());
80
80
}
81
81
82
82
@ Specialization (guards = { "!isRubyInteger(value)" , "!isNil(value)" })
83
- static int cmpObject (Object value , Object receiver , Object other ,
84
- @ Cached DispatchNode gtNode ,
85
- @ Cached DispatchNode ltNode ,
83
+ static int cmpObject (Node node , Object value , Object receiver , Object other ,
84
+ @ Cached ( inline = false ) DispatchNode gtNode ,
85
+ @ Cached ( inline = false ) DispatchNode ltNode ,
86
86
@ Cached BooleanCastNode gtCastNode ,
87
- @ Cached BooleanCastNode ltCastNode ,
88
- @ Bind ("this" ) Node node ) {
87
+ @ Cached BooleanCastNode ltCastNode ) {
89
88
90
89
if (gtCastNode .execute (node , gtNode .call (value , ">" , 0 ))) {
91
90
return 1 ;
0 commit comments