11
11
12
12
import com .oracle .truffle .api .HostCompilerDirectives .InliningCutoff ;
13
13
import com .oracle .truffle .api .dsl .NeverDefault ;
14
- import com .oracle .truffle .api .dsl .TypeSystemReference ;
15
- import org .truffleruby .core .CoreLibrary ;
16
- import org .truffleruby .core .encoding .RubyEncoding ;
17
14
import org .truffleruby .core .klass .RubyClass ;
18
- import org .truffleruby .core .numeric .RubyBignum ;
19
- import org .truffleruby .core .range .RubyIntOrLongRange ;
20
- import org .truffleruby .core .regexp .RubyRegexp ;
21
- import org .truffleruby .core .symbol .RubySymbol ;
22
- import org .truffleruby .core .string .ImmutableRubyString ;
23
- import org .truffleruby .language .Nil ;
24
- import org .truffleruby .language .NoImplicitCastsToLong ;
25
15
import org .truffleruby .language .RubyBaseNode ;
26
16
import org .truffleruby .language .RubyDynamicObject ;
27
17
30
20
import com .oracle .truffle .api .dsl .Specialization ;
31
21
32
22
@ GenerateUncached
33
- @ TypeSystemReference (NoImplicitCastsToLong .class )
34
23
public abstract class MetaClassNode extends RubyBaseNode {
35
24
36
25
@ NeverDefault
@@ -42,94 +31,34 @@ public static MetaClassNode getUncached() {
42
31
return MetaClassNodeGen .getUncached ();
43
32
}
44
33
45
- public final RubyClass execute (Object value ) {
46
- return execute (value , coreLibrary ());
47
- }
48
-
49
- protected abstract RubyClass execute (Object value , CoreLibrary coreLibrary );
50
-
51
- // Cover all primitives, nil and symbols
52
-
53
- @ Specialization (guards = "value" )
54
- protected RubyClass metaClassTrue (boolean value , CoreLibrary coreLibrary ) {
55
- return coreLibrary .trueClass ;
56
- }
57
-
58
- @ Specialization (guards = "!value" )
59
- protected RubyClass metaClassFalse (boolean value , CoreLibrary coreLibrary ) {
60
- return coreLibrary .falseClass ;
61
- }
62
-
63
- @ Specialization
64
- protected RubyClass metaClassInt (int value , CoreLibrary coreLibrary ) {
65
- return coreLibrary .integerClass ;
66
- }
67
-
68
- @ Specialization
69
- protected RubyClass metaClassLong (long value , CoreLibrary coreLibrary ) {
70
- return coreLibrary .integerClass ;
71
- }
72
-
73
- @ Specialization
74
- protected RubyClass metaClassBignum (RubyBignum value , CoreLibrary coreLibrary ) {
75
- return coreLibrary .integerClass ;
76
- }
77
-
78
- @ Specialization
79
- protected RubyClass metaClassDouble (double value , CoreLibrary coreLibrary ) {
80
- return coreLibrary .floatClass ;
81
- }
82
-
83
- @ Specialization
84
- protected RubyClass metaClassNil (Nil value , CoreLibrary coreLibrary ) {
85
- return coreLibrary .nilClass ;
86
- }
87
-
88
- @ Specialization
89
- protected RubyClass metaClassSymbol (RubySymbol value , CoreLibrary coreLibrary ) {
90
- return coreLibrary .symbolClass ;
91
- }
92
-
93
- @ Specialization
94
- protected RubyClass metaClassEncoding (RubyEncoding value , CoreLibrary coreLibrary ) {
95
- return coreLibrary .encodingClass ;
96
- }
97
-
98
- @ Specialization
99
- protected RubyClass metaClassImmutableString (ImmutableRubyString value , CoreLibrary coreLibrary ) {
100
- return coreLibrary .stringClass ;
101
- }
102
-
103
- @ Specialization
104
- protected RubyClass metaClassRegexp (RubyRegexp value , CoreLibrary coreLibrary ) {
105
- return coreLibrary .regexpClass ;
106
- }
34
+ public abstract RubyClass execute (Object value );
107
35
108
- @ Specialization
109
- protected RubyClass metaClassIntRange (RubyIntOrLongRange value , CoreLibrary coreLibrary ) {
110
- return coreLibrary .rangeClass ;
36
+ @ Specialization (guards = "isPrimitiveOrImmutable(value)" )
37
+ protected RubyClass metaClassImmutable (Object value ,
38
+ @ Cached ImmutableClassNode immutableClassNode ) {
39
+ return immutableClassNode .execute (this , value );
111
40
}
112
41
113
42
// Cover all RubyDynamicObject cases with cached and uncached
114
43
115
44
@ Specialization (
116
45
guards = { "object == cachedObject" , "metaClass.isSingleton" },
117
46
limit = "getIdentityCacheContextLimit()" )
118
- protected RubyClass singletonClassCached (RubyDynamicObject object , CoreLibrary coreLibrary ,
47
+ protected RubyClass singletonClassCached (RubyDynamicObject object ,
119
48
@ Cached ("object" ) RubyDynamicObject cachedObject ,
120
49
@ Cached ("object.getMetaClass()" ) RubyClass metaClass ) {
121
50
return metaClass ;
122
51
}
123
52
124
53
@ Specialization (replaces = "singletonClassCached" )
125
- protected RubyClass metaClassObject (RubyDynamicObject object , CoreLibrary coreLibrary ) {
54
+ protected RubyClass metaClassObject (RubyDynamicObject object ) {
126
55
return object .getMetaClass ();
127
56
}
128
57
129
58
// Foreign object
130
59
@ InliningCutoff
131
60
@ Specialization (guards = "isForeignObject(object)" )
132
- protected RubyClass metaClassForeign (Object object , CoreLibrary coreLibrary ,
61
+ protected RubyClass metaClassForeign (Object object ,
133
62
@ Cached ForeignClassNode foreignClassNode ) {
134
63
return foreignClassNode .execute (object );
135
64
}
0 commit comments