121
121
import org .truffleruby .language .methods .DeclarationContext ;
122
122
import org .truffleruby .language .methods .GetMethodObjectNode ;
123
123
import org .truffleruby .language .methods .InternalMethod ;
124
+ import org .truffleruby .language .methods .SharedMethodInfo ;
124
125
import org .truffleruby .language .objects .AllocationTracing ;
125
126
import org .truffleruby .language .objects .CheckIVarNameNode ;
126
127
import org .truffleruby .language .objects .IsANode ;
139
140
import com .oracle .truffle .api .CompilerDirectives ;
140
141
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
141
142
import com .oracle .truffle .api .RootCallTarget ;
142
- import com .oracle .truffle .api .Truffle ;
143
143
import com .oracle .truffle .api .dsl .Cached ;
144
144
import com .oracle .truffle .api .dsl .CreateCast ;
145
145
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
@@ -731,18 +731,6 @@ public abstract static class EvalNode extends PrimitiveArrayArgumentsNode {
731
731
732
732
@ Child private CreateEvalSourceNode createEvalSourceNode = new CreateEvalSourceNode ();
733
733
734
- protected static class RootNodeWrapper {
735
- private final RubyRootNode rootNode ;
736
-
737
- public RootNodeWrapper (RubyRootNode rootNode ) {
738
- this .rootNode = rootNode ;
739
- }
740
-
741
- public RubyRootNode getRootNode () {
742
- return rootNode ;
743
- }
744
- }
745
-
746
734
public abstract Object execute (VirtualFrame frame , Object target , Object source , RubyBinding binding ,
747
735
Object file , int line );
748
736
@@ -756,7 +744,7 @@ public abstract Object execute(VirtualFrame frame, Object target, Object source,
756
744
"equalNode.execute(libSource.getRope(source), cachedSource)" ,
757
745
"equalNode.execute(libFile.getRope(file), cachedFile)" ,
758
746
"line == cachedLine" ,
759
- "!assignsNewUserVariables(getDescriptor(cachedRootNode ))" ,
747
+ "!assignsNewUserVariables(getDescriptor(cachedCallTarget ))" ,
760
748
"bindingDescriptor == getBindingDescriptor(binding)" },
761
749
limit = "getCacheLimit()" )
762
750
protected Object evalBindingNoAddsVarsCached (
@@ -767,12 +755,11 @@ protected Object evalBindingNoAddsVarsCached(
767
755
@ Cached ("libFile.getRope(file)" ) Rope cachedFile ,
768
756
@ Cached ("line" ) int cachedLine ,
769
757
@ Cached ("getBindingDescriptor(binding)" ) FrameDescriptor bindingDescriptor ,
770
- @ Cached ("compileSource(cachedSource, getBindingFrame(binding), cachedFile, cachedLine)" ) RootNodeWrapper cachedRootNode ,
771
- @ Cached ("createCallTarget(cachedRootNode)" ) RootCallTarget cachedCallTarget ,
758
+ @ Cached ("compileSource(cachedSource, getBindingFrame(binding), cachedFile, cachedLine)" ) RootCallTarget cachedCallTarget ,
772
759
@ Cached ("create(cachedCallTarget)" ) DirectCallNode callNode ,
773
760
@ Cached RopeNodes .EqualNode equalNode ) {
774
761
final MaterializedFrame parentFrame = binding .getFrame ();
775
- return eval (target , cachedRootNode , cachedCallTarget , callNode , parentFrame );
762
+ return eval (target , cachedCallTarget , callNode , parentFrame );
776
763
}
777
764
778
765
@ Specialization (
@@ -782,8 +769,8 @@ protected Object evalBindingNoAddsVarsCached(
782
769
"equalNode.execute(libSource.getRope(source), cachedSource)" ,
783
770
"equalNode.execute(libFile.getRope(file), cachedFile)" ,
784
771
"line == cachedLine" ,
785
- "assignsNewUserVariables(getDescriptor(cachedRootNode ))" ,
786
- "!assignsNewUserVariables(getDescriptor(rootNodeToEval ))" ,
772
+ "assignsNewUserVariables(getDescriptor(firstCallTarget ))" ,
773
+ "!assignsNewUserVariables(getDescriptor(cachedCallTarget ))" ,
787
774
"bindingDescriptor == getBindingDescriptor(binding)" },
788
775
limit = "getCacheLimit()" )
789
776
protected Object evalBindingAddsVarsCached (
@@ -794,14 +781,13 @@ protected Object evalBindingAddsVarsCached(
794
781
@ Cached ("libFile.getRope(file)" ) Rope cachedFile ,
795
782
@ Cached ("line" ) int cachedLine ,
796
783
@ Cached ("getBindingDescriptor(binding)" ) FrameDescriptor bindingDescriptor ,
797
- @ Cached ("compileSource(cachedSource, getBindingFrame(binding), cachedFile, cachedLine)" ) RootNodeWrapper cachedRootNode ,
798
- @ Cached ("getDescriptor(cachedRootNode).copy()" ) FrameDescriptor newBindingDescriptor ,
799
- @ Cached ("compileSource(cachedSource, getBindingFrame(binding), newBindingDescriptor, cachedFile, cachedLine)" ) RootNodeWrapper rootNodeToEval ,
800
- @ Cached ("createCallTarget(rootNodeToEval)" ) RootCallTarget cachedCallTarget ,
784
+ @ Cached ("compileSource(cachedSource, getBindingFrame(binding), cachedFile, cachedLine)" ) RootCallTarget firstCallTarget ,
785
+ @ Cached ("getDescriptor(firstCallTarget).copy()" ) FrameDescriptor newBindingDescriptor ,
786
+ @ Cached ("compileSource(cachedSource, getBindingFrame(binding), newBindingDescriptor, cachedFile, cachedLine)" ) RootCallTarget cachedCallTarget ,
801
787
@ Cached ("create(cachedCallTarget)" ) DirectCallNode callNode ,
802
788
@ Cached RopeNodes .EqualNode equalNode ) {
803
789
final MaterializedFrame parentFrame = BindingNodes .newFrame (binding , newBindingDescriptor );
804
- return eval (target , rootNodeToEval , cachedCallTarget , callNode , parentFrame );
790
+ return eval (target , cachedCallTarget , callNode , parentFrame );
805
791
}
806
792
807
793
@ Specialization (guards = { "libSource.isRubyString(source)" , "libFile.isRubyString(file)" })
@@ -818,14 +804,15 @@ protected Object evalBindingUncached(Object target, Object source, RubyBinding b
818
804
return deferredCall .call (callNode );
819
805
}
820
806
821
- private Object eval (Object target , RootNodeWrapper rootNode , RootCallTarget callTarget , DirectCallNode callNode ,
807
+ private Object eval (Object target , RootCallTarget callTarget , DirectCallNode callNode ,
822
808
MaterializedFrame parentFrame ) {
809
+ final SharedMethodInfo sharedMethodInfo = RubyRootNode .of (callTarget ).getSharedMethodInfo ();
823
810
final InternalMethod method = new InternalMethod (
824
811
getContext (),
825
- rootNode . getRootNode (). getSharedMethodInfo () ,
812
+ sharedMethodInfo ,
826
813
RubyArguments .getMethod (parentFrame ).getLexicalScope (),
827
814
RubyArguments .getDeclarationContext (parentFrame ),
828
- rootNode . getRootNode (). getSharedMethodInfo () .getMethodNameForNotBlock (),
815
+ sharedMethodInfo .getMethodNameForNotBlock (),
829
816
RubyArguments .getMethod (parentFrame ).getDeclaringModule (),
830
817
Visibility .PUBLIC ,
831
818
callTarget );
@@ -845,19 +832,19 @@ private CodeLoader.DeferredCall doEvalX(Object target, Rope source, RubyBinding
845
832
final MaterializedFrame frame = BindingNodes .newFrame (binding .getFrame ());
846
833
final DeclarationContext declarationContext = RubyArguments .getDeclarationContext (frame );
847
834
final FrameDescriptor descriptor = frame .getFrameDescriptor ();
848
- RubyRootNode rootNode = buildRootNode (source , frame , file , line , false );
835
+ RootCallTarget callTarget = parse (source , frame , file , line , false );
849
836
if (assignsNewUserVariables (descriptor )) {
850
837
binding .setFrame (frame );
851
838
}
852
839
return getContext ().getCodeLoader ().prepareExecute (
840
+ callTarget ,
853
841
ParserContext .EVAL ,
854
842
declarationContext ,
855
- rootNode ,
856
843
frame ,
857
844
target );
858
845
}
859
846
860
- protected RubyRootNode buildRootNode (Rope sourceText , MaterializedFrame parentFrame , Rope file , int line ,
847
+ protected RootCallTarget parse (Rope sourceText , MaterializedFrame parentFrame , Rope file , int line ,
861
848
boolean ownScopeForAssignments ) {
862
849
//intern() to improve footprint
863
850
final String sourceFile = RopeOperations .decodeRope (file ).intern ();
@@ -867,25 +854,21 @@ protected RubyRootNode buildRootNode(Rope sourceText, MaterializedFrame parentFr
867
854
.parse (source , ParserContext .EVAL , parentFrame , null , ownScopeForAssignments , this );
868
855
}
869
856
870
- protected RootNodeWrapper compileSource (Rope sourceText , MaterializedFrame parentFrame , Rope file , int line ) {
871
- return new RootNodeWrapper ( buildRootNode ( sourceText , parentFrame , file , line , true ) );
857
+ protected RootCallTarget compileSource (Rope sourceText , MaterializedFrame parentFrame , Rope file , int line ) {
858
+ return parse ( sourceText , parentFrame , file , line , true );
872
859
}
873
860
874
- protected RootNodeWrapper compileSource (Rope sourceText , MaterializedFrame parentFrame ,
861
+ protected RootCallTarget compileSource (Rope sourceText , MaterializedFrame parentFrame ,
875
862
FrameDescriptor additionalVariables , Rope file , int line ) {
876
863
return compileSource (sourceText , BindingNodes .newFrame (parentFrame , additionalVariables ), file , line );
877
864
}
878
865
879
- protected RootCallTarget createCallTarget (RootNodeWrapper rootNode ) {
880
- return Truffle .getRuntime ().createCallTarget (rootNode .rootNode );
881
- }
882
-
883
866
protected FrameDescriptor getBindingDescriptor (RubyBinding binding ) {
884
867
return BindingNodes .getFrameDescriptor (binding );
885
868
}
886
869
887
- protected FrameDescriptor getDescriptor (RootNodeWrapper rootNode ) {
888
- return rootNode . getRootNode ( ).getFrameDescriptor ();
870
+ protected FrameDescriptor getDescriptor (RootCallTarget callTarget ) {
871
+ return RubyRootNode . of ( callTarget ).getFrameDescriptor ();
889
872
}
890
873
891
874
protected MaterializedFrame getBindingFrame (RubyBinding binding ) {
0 commit comments