2929import com .oracle .truffle .api .SourceSection ;
3030import com .oracle .truffle .api .frame .FrameDescriptor ;
3131import com .oracle .truffle .api .frame .FrameSlot ;
32- import com .oracle .truffle .api .frame .MaterializedFrame ;
3332import com .oracle .truffle .api .frame .VirtualFrame ;
34- import com .oracle .truffle .api .nodes .ExplodeLoop ;
3533import com .oracle .truffle .api .nodes .RootNode ;
3634
3735
@@ -40,8 +38,19 @@ public class Method extends RootNode {
4038 @ Child private ExpressionNode expressionOrSequence ;
4139
4240 private final FrameSlot selfSlot ;
43- @ CompilationFinal private final FrameSlot [] argumentSlots ;
44- @ CompilationFinal private final FrameSlot [] temporarySlots ;
41+ // @CompilationFinal private final FrameSlot[] argumentSlots;
42+ // @CompilationFinal private final FrameSlot[] temporarySlots;
43+
44+ @ CompilationFinal private final FrameSlot argumentSlot1 ;
45+ @ CompilationFinal private final FrameSlot argumentSlot2 ;
46+ @ CompilationFinal private final FrameSlot argumentSlot3 ;
47+ @ CompilationFinal private final FrameSlot argumentSlot4 ;
48+
49+ @ CompilationFinal private final FrameSlot temporarySlot1 ;
50+ @ CompilationFinal private final FrameSlot temporarySlot2 ;
51+ @ CompilationFinal private final FrameSlot temporarySlot3 ;
52+ @ CompilationFinal private final FrameSlot temporarySlot4 ;
53+
4554 private final FrameSlot nonLocalReturnMarker ;
4655 private final Universe universe ;
4756
@@ -56,16 +65,35 @@ public Method(final ExpressionNode expressions,
5665 final FrameDescriptor frameDescriptor ) {
5766 this .expressionOrSequence = adoptChild (expressions );
5867 this .selfSlot = selfSlot ;
59- this .argumentSlots = argumentSlots ;
60- this .temporarySlots = temporarySlots ;
68+
69+ if (argumentSlots .length > 4 ) {
70+ throw new RuntimeException ("We did not expect that many arguments!" );
71+ }
72+
73+ if (temporarySlots .length > 4 ) {
74+ throw new RuntimeException ("We did not expect that many temporaries!" );
75+ }
76+
77+ // --- init arguments ---
78+ if (argumentSlots .length == 4 ) { this .argumentSlot4 = argumentSlots [3 ]; } else { this .argumentSlot4 = null ; }
79+ if (argumentSlots .length >= 3 ) { this .argumentSlot3 = argumentSlots [2 ]; } else { this .argumentSlot3 = null ; }
80+ if (argumentSlots .length >= 2 ) { this .argumentSlot2 = argumentSlots [1 ]; } else { this .argumentSlot2 = null ; }
81+ if (argumentSlots .length >= 1 ) { this .argumentSlot1 = argumentSlots [0 ]; } else { this .argumentSlot1 = null ; }
82+
83+ // --- init temps ---
84+ if (temporarySlots .length == 4 ) { this .temporarySlot4 = temporarySlots [3 ]; } else { this .temporarySlot4 = null ; }
85+ if (temporarySlots .length >= 3 ) { this .temporarySlot3 = temporarySlots [2 ]; } else { this .temporarySlot3 = null ; }
86+ if (temporarySlots .length >= 2 ) { this .temporarySlot2 = temporarySlots [1 ]; } else { this .temporarySlot2 = null ; }
87+ if (temporarySlots .length >= 1 ) { this .temporarySlot1 = temporarySlots [0 ]; } else { this .temporarySlot1 = null ; }
88+
6189 this .nonLocalReturnMarker = nonLocalReturnMarker ;
6290 this .universe = universe ;
6391 this .frameDescriptor = frameDescriptor ;
6492 }
6593
6694 @ Override
6795 public Object execute (final VirtualFrame frame ) {
68- final FrameOnStackMarker marker = initializeFrame (this , frame . materialize () );
96+ final FrameOnStackMarker marker = initializeFrame (this , frame );
6997 return messageSendExecution (marker , frame , expressionOrSequence );
7098 }
7199
@@ -96,22 +124,55 @@ public static SObject messageSendExecution(final FrameOnStackMarker marker,
96124 return result ;
97125 }
98126
99- @ ExplodeLoop
127+ // static int maxArgs = 0;
128+ // static int maxTemps = 0;
129+ //
130+ // if (maxArgs < method.argumentSlots.length) { maxArgs = method.argumentSlots.length; System.out.println("MAX ARGS: " + maxArgs); }
131+ // if (maxTemps < method.temporarySlots.length) { maxTemps = method.temporarySlots.length; System.out.println("MAX TMPS: " + maxTemps);}
132+
133+
134+ // @ExplodeLoop
100135 public static FrameOnStackMarker initializeFrame (final Method method ,
101- final MaterializedFrame frame ) {
136+ final VirtualFrame frame ) {
102137 frame .setObject (method .selfSlot , frame .getArguments (Arguments .class ).self );
103138
104139 final FrameOnStackMarker marker = new FrameOnStackMarker ();
105140 frame .setObject (method .nonLocalReturnMarker , marker );
106141
107142 Object [] args = frame .getArguments (Arguments .class ).arguments ;
108- for (int i = 0 ; i < method .argumentSlots .length ; i ++) {
109- frame .setObject (method .argumentSlots [i ], args [i ]);
143+ // for (int i = 0; i < method.argumentSlots.length; i++) {
144+ // frame.setObject(method.argumentSlots[i], args[i]);
145+ // }
146+ if (args .length > 0 ) {
147+ frame .setObject (method .argumentSlot1 , args [0 ]);
148+ if (args .length > 1 ) {
149+ frame .setObject (method .argumentSlot2 , args [1 ]);
150+ if (args .length > 2 ) {
151+ frame .setObject (method .argumentSlot3 , args [2 ]);
152+ if (args .length > 3 ) {
153+ frame .setObject (method .argumentSlot4 , args [3 ]);
154+ }
155+ }
156+ }
110157 }
111158
112- for (int i = 0 ; i < method .temporarySlots .length ; i ++) {
113- frame .setObject (method .temporarySlots [i ], method .universe .nilObject );
159+ // for (int i = 0; i < method.temporarySlots.length; i++) {
160+ // frame.setObject(method.temporarySlots[i], method.universe.nilObject);
161+ // }
162+
163+ if (method .temporarySlot1 != null ) {
164+ frame .setObject (method .temporarySlot1 , method .universe .nilObject );
165+ if (method .temporarySlot2 != null ) {
166+ frame .setObject (method .temporarySlot2 , method .universe .nilObject );
167+ if (method .temporarySlot3 != null ) {
168+ frame .setObject (method .temporarySlot3 , method .universe .nilObject );
169+ if (method .temporarySlot4 != null ) {
170+ frame .setObject (method .temporarySlot4 , method .universe .nilObject );
171+ }
172+ }
173+ }
114174 }
175+
115176 return marker ;
116177 }
117178
0 commit comments