25
25
*/
26
26
package com .oracle .graal .python .builtins .objects .function ;
27
27
28
- import com .oracle .graal .python .builtins .objects .cell .PCell ;
29
28
import com .oracle .graal .python .builtins .objects .frame .PFrame ;
30
29
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
31
- import com .oracle .graal .python .runtime . PythonOptions ;
30
+ import com .oracle .graal .python .nodes . argument . CreateArgumentsNode ;
32
31
import com .oracle .graal .python .runtime .exception .PException ;
33
32
import com .oracle .truffle .api .exception .AbstractTruffleException ;
34
33
import com .oracle .truffle .api .frame .Frame ;
35
- import com .oracle .truffle .api .frame .MaterializedFrame ;
36
34
37
- //@formatter:off
38
35
/**
39
36
* The layout of an argument array for a Python frame.
40
- *
41
- * +-------------------+
42
- * INDEX_GENERATOR_FRAME -> | MaterializedFrame |
43
- * +-------------------+
44
- * SPECIAL_ARGUMENT -> | Object |
45
- * +-------------------+
46
- * INDEX_GLOBALS_ARGUMENT -> | PythonObject |
47
- * +-------------------+
48
- * INDEX_CLOSURE -> | PCell[] |
49
- * +-------------------+
50
- * INDEX_CALLER_FRAME_INFO -> | PFrame.Reference |
51
- * +-------------------+
52
- * INDEX_CURRENT_FRAME_INFO -> | PFrame.Reference |
53
- * +-------------------+
54
- * INDEX_CURRENT_EXCEPTION -> | PException |
55
- * +-------------------+
56
- * USER_ARGUMENTS -> | arg_0 |
57
- * | arg_1 |
58
- * | ... |
59
- * | arg_(nArgs-1) |
60
- * +-------------------+
37
+ * <ul>
38
+ * <li>{@code SPECIAL_ARGUMENT (Object)}</li>
39
+ * <li>{@code INDEX_GLOBALS_ARGUMENT (PythonObject)}</li>
40
+ * <li>{@code INDEX_FUNCTION_OBJECT (PFunction)}</li>
41
+ * <li>{@code INDEX_CALLER_FRAME_INFO (PFrame.Reference)}</li>
42
+ * <li>{@code INDEX_CURRENT_FRAME_INFO (PFrame.Reference)}</li>
43
+ * <li>{@code INDEX_CURRENT_EXCEPTION (PException)}</li>
44
+ * <li>{@code USER_ARGUMENTS (Object...)}; Further defined by a particular call convention:
45
+ * <ul>
46
+ * <li>Function calls: non-variadic arguments as individual items in order of {@code co_varnames},
47
+ * then varargs as {@code Object[]} iff the function takes them, then variadic keywords as
48
+ * {@code PKeyword[]} iff the function takes them. Implemented by {@link CreateArgumentsNode}</li>
49
+ * <li>Generator resumes (non-DSL): generator frame ({@code MaterializedFrame}), then the send value
50
+ * or null</li>
51
+ * <li>Generator resumes (DSL): doesn't use PArguments to call the continuation root</li>
52
+ * </ul>
53
+ * </li>
54
+ * </ul>
61
55
*/
62
- //@formatter:on
63
56
public final class PArguments {
64
- private static final int INDEX_GENERATOR_FRAME = 0 ;
65
- private static final int INDEX_SPECIAL_ARGUMENT = 1 ;
66
- private static final int INDEX_GLOBALS_ARGUMENT = 2 ;
67
- private static final int INDEX_CLOSURE = 3 ;
68
- private static final int INDEX_CALLER_FRAME_INFO = 4 ;
69
- private static final int INDEX_CURRENT_FRAME_INFO = 5 ;
70
- private static final int INDEX_CURRENT_EXCEPTION = 6 ;
71
- public static final int USER_ARGUMENTS_OFFSET = 7 ;
57
+ private static final int INDEX_SPECIAL_ARGUMENT = 0 ;
58
+ private static final int INDEX_GLOBALS_ARGUMENT = 1 ;
59
+ private static final int INDEX_FUNCTION_OBJECT = 2 ;
60
+ private static final int INDEX_CALLER_FRAME_INFO = 3 ;
61
+ private static final int INDEX_CURRENT_FRAME_INFO = 4 ;
62
+ private static final int INDEX_CURRENT_EXCEPTION = 5 ;
63
+ public static final int USER_ARGUMENTS_OFFSET = 6 ;
72
64
73
65
public static boolean isPythonFrame (Frame frame ) {
74
66
return frame != null && isPythonFrame (frame .getArguments ());
@@ -105,8 +97,6 @@ public static void setSpecialArgument(Object[] arguments, Object value) {
105
97
/**
106
98
* The special argument is used for various purposes, none of which can occur at the same time:
107
99
* <ul>
108
- * <li>The value sent to a generator via <code>send</code></li>
109
- * <li>An exception thrown through a generator via <code>throw</code></li>
110
100
* <li>The custom locals in a module or class scope when called through <code>exec</code> or
111
101
* <code>__build_class__</code></li>
112
102
* </ul>
@@ -199,16 +189,12 @@ public static void setExceptionUnchecked(Object[] arguments, Object exc) {
199
189
arguments [INDEX_CURRENT_EXCEPTION ] = exc ;
200
190
}
201
191
202
- public static void setClosure (Object [] arguments , PCell [] closure ) {
203
- arguments [INDEX_CLOSURE ] = closure ;
204
- }
205
-
206
- public static PCell [] getClosure (Object [] arguments ) {
207
- return (PCell []) arguments [INDEX_CLOSURE ];
192
+ public static PFunction getFunctionObject (Object [] arguments ) {
193
+ return (PFunction ) arguments [INDEX_FUNCTION_OBJECT ];
208
194
}
209
195
210
- public static PCell [] getClosure ( Frame frame ) {
211
- return getClosure ( frame . getArguments ()) ;
196
+ public static void setFunctionObject ( Object [] arguments , PFunction function ) {
197
+ arguments [ INDEX_FUNCTION_OBJECT ] = function ;
212
198
}
213
199
214
200
public static void setArgument (Object [] arguments , int index , Object value ) {
@@ -223,43 +209,6 @@ public static Object getArgument(Frame frame, int index) {
223
209
return getArgument (frame .getArguments (), index );
224
210
}
225
211
226
- public static MaterializedFrame getGeneratorFrame (Object [] arguments ) {
227
- assert !PythonOptions .ENABLE_BYTECODE_DSL_INTERPRETER ;
228
- return (MaterializedFrame ) arguments [INDEX_GENERATOR_FRAME ];
229
- }
230
-
231
- public static MaterializedFrame getGeneratorFrame (Frame frame ) {
232
- return getGeneratorFrame (frame .getArguments ());
233
- }
234
-
235
- public static MaterializedFrame getGeneratorFrameSafe (Frame frame ) {
236
- return getGeneratorFrameSafe (frame .getArguments ());
237
- }
238
-
239
- public static MaterializedFrame getGeneratorFrameSafe (Object [] arguments ) {
240
- if (arguments [INDEX_GENERATOR_FRAME ] instanceof MaterializedFrame ) {
241
- return getGeneratorFrame (arguments );
242
- } else {
243
- return null ;
244
- }
245
- }
246
-
247
- public static void setGeneratorFrame (Object [] arguments , MaterializedFrame generatorFrame ) {
248
- arguments [INDEX_GENERATOR_FRAME ] = generatorFrame ;
249
- }
250
-
251
- /**
252
- * This should be used only in GeneratorFunctionRootNode, later the slot is overwritten with
253
- * generator frame
254
- */
255
- public static PFunction getGeneratorFunction (Object [] arguments ) {
256
- return (PFunction ) arguments [INDEX_GENERATOR_FRAME ];
257
- }
258
-
259
- public static void setGeneratorFunction (Object [] arguments , PFunction generatorFunction ) {
260
- arguments [INDEX_GENERATOR_FRAME ] = generatorFunction ;
261
- }
262
-
263
212
/**
264
213
* Synchronizes the arguments array of a Truffle frame with a {@link PFrame}. Copies only those
265
214
* arguments that are necessary to be synchronized between the two.
@@ -271,7 +220,7 @@ public static void synchronizeArgs(Frame frameToMaterialize, PFrame escapedFrame
271
220
// copy only some carefully picked internal arguments
272
221
setSpecialArgument (copiedArgs , getSpecialArgument (arguments ));
273
222
setGlobals (copiedArgs , getGlobals (arguments ));
274
- setClosure (copiedArgs , getClosure (arguments ));
223
+ setFunctionObject (copiedArgs , getFunctionObject (arguments ));
275
224
276
225
escapedFrame .setArguments (copiedArgs );
277
226
}
0 commit comments