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 IfNode extends RubyContextSourceNode {
21
+ public abstract class IfNode 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 IfNode (RubyNode condition , RubyNode thenBody ) {
28
- this (BooleanCastNodeGen .create (condition ), thenBody );
29
- }
30
-
31
- private IfNode (BooleanCastNode condition , RubyNode thenBody ) {
32
27
this .condition = condition ;
33
28
this .thenBody = thenBody ;
34
29
}
35
30
36
- @ Override
37
- public Object execute (VirtualFrame frame ) {
38
- if (conditionProfile .profile (condition .execute (frame ))) {
31
+ @ Specialization
32
+ protected Object doIf (VirtualFrame frame ,
33
+ @ Cached BooleanCastNode booleanCastNode ,
34
+ @ Cached InlinedCountingConditionProfile conditionProfile ) {
35
+ final var conditionAsBoolean = booleanCastNode .execute (condition .execute (frame ));
36
+ if (conditionProfile .profile (this , conditionAsBoolean )) {
39
37
return thenBody .execute (frame );
40
38
} else {
41
39
return nil ;
42
40
}
43
41
}
44
42
43
+
45
44
@ Override
46
45
public boolean canSubsumeFollowing () {
47
46
return !thenBody .isContinuable ();
@@ -54,17 +53,14 @@ public RubyNode subsumeFollowing(RubyNode following) {
54
53
55
54
@ Override
56
55
public RubyNode simplifyAsTailExpression () {
57
- return new IfNode (condition , thenBody .simplifyAsTailExpression ()).copySourceSection (this );
56
+ return IfNodeGen . create (condition , thenBody .simplifyAsTailExpression ()).copySourceSection (this );
58
57
}
59
58
60
- private RubyNode getConditionBeforeCasting () {
61
- return condition .getValueNode ();
62
- }
63
59
64
60
@ Override
65
61
public RubyNode cloneUninitialized () {
66
- var copy = new IfNode (
67
- getConditionBeforeCasting () .cloneUninitialized (),
62
+ var copy = IfNodeGen . create (
63
+ condition .cloneUninitialized (),
68
64
thenBody .cloneUninitialized ());
69
65
return copy .copyFlags (this );
70
66
}
0 commit comments