9
9
*/
10
10
package org .truffleruby .language .control ;
11
11
12
- import com .oracle .truffle .api .profiles .CountingConditionProfile ;
12
+ import com .oracle .truffle .api .dsl .Cached ;
13
+ import com .oracle .truffle .api .dsl .Specialization ;
14
+ import com .oracle .truffle .api .profiles .InlinedCountingConditionProfile ;
13
15
import org .truffleruby .core .cast .BooleanCastNode ;
14
- import org .truffleruby .core .cast .BooleanCastNodeGen ;
15
16
import org .truffleruby .language .RubyContextSourceNode ;
16
17
import org .truffleruby .language .RubyNode ;
17
18
18
19
import com .oracle .truffle .api .frame .VirtualFrame ;
19
20
20
- public class UnlessNode extends RubyContextSourceNode {
21
+ public abstract class UnlessNode extends RubyContextSourceNode {
21
22
22
- @ Child private BooleanCastNode condition ;
23
+ @ Child private RubyNode condition ;
23
24
@ Child private RubyNode thenBody ;
24
25
25
- private final CountingConditionProfile conditionProfile = CountingConditionProfile .create ();
26
-
27
26
public UnlessNode (RubyNode condition , RubyNode thenBody ) {
28
- this .condition = BooleanCastNodeGen .create (condition );
29
- this .thenBody = thenBody ;
30
- }
31
-
32
- public UnlessNode (BooleanCastNode condition , RubyNode thenBody ) {
33
27
this .condition = condition ;
34
28
this .thenBody = thenBody ;
35
29
}
36
30
37
- @ Override
38
- public Object execute (VirtualFrame frame ) {
39
- if (!conditionProfile .profile (condition .execute (frame ))) {
31
+ @ Specialization
32
+ protected Object doUnless (VirtualFrame frame ,
33
+ @ Cached InlinedCountingConditionProfile conditionProfile ,
34
+ @ Cached BooleanCastNode booleanCastNode ) {
35
+ if (!conditionProfile .profile (this , booleanCastNode .execute (condition .execute (frame )))) {
40
36
return thenBody .execute (frame );
41
37
} else {
42
38
return nil ;
@@ -55,16 +51,13 @@ public RubyNode subsumeFollowing(RubyNode following) {
55
51
56
52
@ Override
57
53
public RubyNode simplifyAsTailExpression () {
58
- return new UnlessNode (condition , thenBody .simplifyAsTailExpression ()).copySourceSection (this );
54
+ return UnlessNodeGen . create (condition , thenBody .simplifyAsTailExpression ()).copySourceSection (this );
59
55
}
60
56
61
- private RubyNode getConditionBeforeCasting () {
62
- return condition .getValueNode ();
63
- }
64
57
65
58
public RubyNode cloneUninitialized () {
66
- var copy = new UnlessNode (
67
- getConditionBeforeCasting () .cloneUninitialized (),
59
+ var copy = UnlessNodeGen . create (
60
+ condition .cloneUninitialized (),
68
61
thenBody .cloneUninitialized ());
69
62
return copy .copyFlags (this );
70
63
}
0 commit comments