59
59
import org .truffleruby .core .method .MethodFilter ;
60
60
import org .truffleruby .core .method .RubyMethod ;
61
61
import org .truffleruby .core .method .RubyUnboundMethod ;
62
- import org .truffleruby .core .module .ModuleNodesFactory .ClassExecNodeFactory ;
63
62
import org .truffleruby .core .module .ModuleNodesFactory .ConstSetNodeFactory ;
64
63
import org .truffleruby .core .module .ModuleNodesFactory .ConstSetUncheckedNodeGen ;
65
64
import org .truffleruby .core .module .ModuleNodesFactory .GeneratedReaderNodeFactory ;
@@ -668,7 +667,7 @@ public abstract static class ClassEvalNode extends AlwaysInlinedMethodNode {
668
667
@ Specialization (guards = "isBlockProvided(rubyArgs)" )
669
668
protected Object evalWithBlock (Frame callerFrame , RubyModule self , Object [] rubyArgs , RootCallTarget target ,
670
669
@ Cached BranchProfile errorProfile ,
671
- @ Cached ( allowUncached = true ) ClassExecNode classExecNode ) {
670
+ @ Cached ClassExecBlockNode classExecNode ) {
672
671
final int count = RubyArguments .getPositionalArgumentsCount (rubyArgs , false );
673
672
674
673
if (count > 0 ) {
@@ -677,7 +676,7 @@ protected Object evalWithBlock(Frame callerFrame, RubyModule self, Object[] ruby
677
676
}
678
677
679
678
final Object block = RubyArguments .getBlock (rubyArgs );
680
- return classExecNode .classExec (EmptyArgumentsDescriptor .INSTANCE , self , new Object []{ self },
679
+ return classExecNode .execute (EmptyArgumentsDescriptor .INSTANCE , self , new Object []{ self },
681
680
(RubyProc ) block );
682
681
}
683
682
@@ -763,23 +762,26 @@ private Object classEvalSource(MaterializedFrame callerFrame, RubyModule module,
763
762
@ CoreMethod (names = { "class_exec" , "module_exec" }, rest = true , needsBlock = true )
764
763
public abstract static class ClassExecNode extends CoreMethodArrayArgumentsNode {
765
764
766
- public static ClassExecNode create () {
767
- return ClassExecNodeFactory .create (null );
768
- }
769
-
770
- @ Child private CallBlockNode callBlockNode = CallBlockNode .create ();
771
-
772
765
@ Specialization
773
- protected Object withBlock (VirtualFrame frame , RubyModule self , Object [] args , RubyProc block ) {
774
- return classExec (RubyArguments .getDescriptor (frame ), self , args , block );
766
+ protected Object withBlock (VirtualFrame frame , RubyModule self , Object [] args , RubyProc block ,
767
+ @ Cached ClassExecBlockNode classExecBlockNode ) {
768
+ return classExecBlockNode .execute (RubyArguments .getDescriptor (frame ), self , args , block );
775
769
}
776
770
777
771
@ Specialization
778
772
protected Object noBlock (RubyModule self , Object [] args , Nil block ) {
779
773
throw new RaiseException (getContext (), coreExceptions ().noBlockGiven (this ));
780
774
}
775
+ }
776
+
777
+ @ GenerateUncached
778
+ public abstract static class ClassExecBlockNode extends RubyBaseNode {
779
+
780
+ public abstract Object execute (ArgumentsDescriptor descriptor , RubyModule self , Object [] args , RubyProc block );
781
781
782
- public Object classExec (ArgumentsDescriptor descriptor , RubyModule self , Object [] args , RubyProc block ) {
782
+ @ Specialization
783
+ protected Object classExec (ArgumentsDescriptor descriptor , RubyModule self , Object [] args , RubyProc block ,
784
+ @ Cached CallBlockNode callBlockNode ) {
783
785
final DeclarationContext declarationContext = new DeclarationContext (
784
786
Visibility .PUBLIC ,
785
787
new FixedDefaultDefinee (self ),
@@ -1457,26 +1459,17 @@ protected Object extended(RubyModule module, Object object) {
1457
1459
@ CoreMethod (names = "initialize" , needsBlock = true ) // Ideally should not split if no block given
1458
1460
public abstract static class InitializeNode extends CoreMethodArrayArgumentsNode {
1459
1461
1460
- @ Child private ClassExecNode classExecNode ;
1461
-
1462
1462
public abstract RubyModule executeInitialize (RubyModule module , Object block );
1463
1463
1464
- void classEval (RubyModule module , RubyProc block ) {
1465
- if (classExecNode == null ) {
1466
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1467
- classExecNode = insert (ClassExecNode .create ());
1468
- }
1469
- classExecNode .classExec (EmptyArgumentsDescriptor .INSTANCE , module , new Object []{ module }, block );
1470
- }
1471
-
1472
1464
@ Specialization
1473
1465
protected RubyModule initialize (RubyModule module , Nil block ) {
1474
1466
return module ;
1475
1467
}
1476
1468
1477
1469
@ Specialization
1478
- protected RubyModule initialize (RubyModule module , RubyProc block ) {
1479
- classEval (module , block );
1470
+ protected RubyModule initialize (RubyModule module , RubyProc block ,
1471
+ @ Cached ClassExecBlockNode classExecBlockNode ) {
1472
+ classExecBlockNode .execute (EmptyArgumentsDescriptor .INSTANCE , module , new Object []{ module }, block );
1480
1473
return module ;
1481
1474
}
1482
1475
0 commit comments