59
59
import com .oracle .graal .python .builtins .PythonBuiltins ;
60
60
import com .oracle .graal .python .builtins .modules .CodecsModuleBuiltins .CodecsDecodeNode ;
61
61
import com .oracle .graal .python .builtins .modules .CodecsModuleBuiltins .CodecsEncodeNode ;
62
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CallApplyNodeFactory ;
63
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CodecDecodeNodeFactory ;
64
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CodecInitNodeFactory ;
65
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .EncodeNodeFactory ;
66
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .IncrementalDecodeNodeFactory ;
67
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .IncrementalEncodeNodeFactory ;
68
- import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .StreamDecodeNodeFactory ;
62
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CallApplyNodeGen ;
63
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CodecDecodeNodeGen ;
64
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .CodecInitNodeGen ;
65
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .EncodeNodeGen ;
66
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .IncrementalDecodeNodeGen ;
67
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .IncrementalEncodeNodeGen ;
68
+ import com .oracle .graal .python .builtins .modules .CodecsTruffleModuleBuiltinsFactory .StreamDecodeNodeGen ;
69
69
import com .oracle .graal .python .builtins .objects .PNone ;
70
70
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
71
71
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
94
94
import com .oracle .graal .python .runtime .PythonContext ;
95
95
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
96
96
import com .oracle .graal .python .util .PythonUtils ;
97
+ import com .oracle .graal .python .util .Supplier ;
97
98
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
98
99
import com .oracle .truffle .api .dsl .Cached ;
99
100
import com .oracle .truffle .api .dsl .Cached .Shared ;
100
- import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
101
101
import com .oracle .truffle .api .dsl .ImportStatic ;
102
102
import com .oracle .truffle .api .dsl .NodeFactory ;
103
103
import com .oracle .truffle .api .dsl .Specialization ;
104
104
import com .oracle .truffle .api .frame .VirtualFrame ;
105
+ import java .util .ArrayList ;
105
106
106
107
@ CoreFunctions (defineModule = _CODECS_TRUFFLE )
107
108
public class CodecsTruffleModuleBuiltins extends PythonBuiltins {
@@ -135,7 +136,7 @@ public class CodecsTruffleModuleBuiltins extends PythonBuiltins {
135
136
136
137
@ Override
137
138
protected List <? extends NodeFactory <? extends PythonBuiltinBaseNode >> getNodeFactories () {
138
- return CodecsTruffleModuleBuiltinsFactory . getFactories ();
139
+ return new ArrayList <> ();
139
140
}
140
141
141
142
private static PythonClass initClass (String className , String superClassName , BuiltinDescr [] descrs , PythonModule codecsTruffleModule , PythonModule codecsModule , PythonLanguage language ,
@@ -148,7 +149,7 @@ private static PythonClass initClass(String className, PythonAbstractClass super
148
149
PythonObjectFactory factory ) {
149
150
PythonClass clazz = factory .createPythonClassAndFixupSlots (language , PythonBuiltinClassType .PythonClass , className , new PythonAbstractClass []{superClass });
150
151
for (BuiltinDescr d : descrs ) {
151
- PythonUtils .createMethod (language , clazz , d .nodeFactory . getNodeClass () , d .enclosingType ? clazz : null , 1 , () -> d . nodeFactory . createNode () , factory );
152
+ PythonUtils .createMethod (language , clazz , d .nodeClass , d .enclosingType ? clazz : null , 1 , d . nodeSupplier , factory );
152
153
}
153
154
clazz .setAttribute (__MODULE__ , _CODECS_TRUFFLE );
154
155
clazz .setAttribute (__QUALNAME__ , _CODECS_TRUFFLE );
@@ -157,11 +158,13 @@ private static PythonClass initClass(String className, PythonAbstractClass super
157
158
}
158
159
159
160
private static final class BuiltinDescr {
160
- final NodeFactory <? extends PythonBuiltinBaseNode > nodeFactory ;
161
+ final Supplier <PythonBuiltinBaseNode > nodeSupplier ;
162
+ final Class <?> nodeClass ;
161
163
final boolean enclosingType ;
162
164
163
- public BuiltinDescr (NodeFactory <? extends PythonBuiltinBaseNode > nodeFactory , boolean enclosingType ) {
164
- this .nodeFactory = nodeFactory ;
165
+ public BuiltinDescr (Supplier <PythonBuiltinBaseNode > nodeSupplier , Class <?> nodeClass , boolean enclosingType ) {
166
+ this .nodeSupplier = nodeSupplier ;
167
+ this .nodeClass = nodeClass ;
165
168
this .enclosingType = enclosingType ;
166
169
}
167
170
}
@@ -243,8 +246,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
243
246
// return _codecs.__truffle_decode__(input, self.encoding, errors, True)
244
247
codecsTruffleBuiltins .truffleCodecClass = initClass (TRUFFLE_CODEC , (PythonClass ) codecsModule .getAttribute (CODEC ),
245
248
new BuiltinDescr []{
246
- new BuiltinDescr (EncodeNodeFactory . getInstance () , false ),
247
- new BuiltinDescr (CodecDecodeNodeFactory . getInstance () , true )},
249
+ new BuiltinDescr (() -> EncodeNodeGen . create (), EncodeNode . class , false ),
250
+ new BuiltinDescr (() -> CodecDecodeNodeGen . create (), CodecDecodeNode . class , true )},
248
251
codecsTruffleModule , language , factory );
249
252
250
253
// class TruffleIncrementalEncoder(codecs.IncrementalEncoder):
@@ -255,8 +258,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
255
258
// return _codecs.__truffle_encode__(input, self.encoding, self.errors)[0]
256
259
codecsTruffleBuiltins .truffleIncrementalEncoderClass = initClass (TRUFFLE_INCREMENTAL_ENCODER , INCREMENTAL_ENCODER ,
257
260
new BuiltinDescr []{
258
- new BuiltinDescr (CodecInitNodeFactory . getInstance () , false ),
259
- new BuiltinDescr (IncrementalEncodeNodeFactory . getInstance () , true )},
261
+ new BuiltinDescr (() -> CodecInitNodeGen . create (), CodecInitNode . class , false ),
262
+ new BuiltinDescr (() -> IncrementalEncodeNodeGen . create (), IncrementalEncodeNode . class , true )},
260
263
codecsTruffleModule , codecsModule , language , factory );
261
264
262
265
// class TruffleIncrementalDecoder(codecs.BufferedIncrementalDecoder):
@@ -267,8 +270,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
267
270
// return _codecs.__truffle_decode__(input, self.encoding, errors, final)
268
271
codecsTruffleBuiltins .truffleIncrementalDecoderClass = initClass (TRUFFLE_INCREMENTAL_DECODER , BUFFERED_INCREMENTAL_DECODER ,
269
272
new BuiltinDescr []{
270
- new BuiltinDescr (CodecInitNodeFactory . getInstance () , false ),
271
- new BuiltinDescr (IncrementalDecodeNodeFactory . getInstance () , true )},
273
+ new BuiltinDescr (() -> CodecInitNodeGen . create (), CodecInitNode . class , false ),
274
+ new BuiltinDescr (() -> IncrementalDecodeNodeGen . create (), IncrementalDecodeNode . class , true )},
272
275
codecsTruffleModule , codecsModule , language , factory );
273
276
274
277
// class TruffleStreamWriter(codecs.StreamWriter):
@@ -279,8 +282,8 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
279
282
// return _codecs.__truffle_encode__(input, self.encoding, errors)
280
283
codecsTruffleBuiltins .truffleStreamWriterClass = initClass (TRUFFLE_STREAM_WRITER , STREAM_WRITER ,
281
284
new BuiltinDescr []{
282
- new BuiltinDescr (CodecInitNodeFactory . getInstance () , false ),
283
- new BuiltinDescr (EncodeNodeFactory . getInstance () , true )},
285
+ new BuiltinDescr (() -> CodecInitNodeGen . create (), CodecInitNode . class , false ),
286
+ new BuiltinDescr (() -> EncodeNodeGen . create (), EncodeNode . class , true )},
284
287
codecsTruffleModule , codecsModule , language , factory );
285
288
286
289
// class TruffleStreamReader(codecs.StreamReader):
@@ -291,22 +294,21 @@ private static void initCodecClasses(PythonModule codecsTruffleModule, PythonMod
291
294
// return _codecs.__truffle_decode__(input, self.encoding, errors)
292
295
codecsTruffleBuiltins .truffleStreamReaderClass = initClass (TRUFFLE_STREAM_READER , STREAM_READER ,
293
296
new BuiltinDescr []{
294
- new BuiltinDescr (CodecInitNodeFactory . getInstance () , false ),
295
- new BuiltinDescr (StreamDecodeNodeFactory . getInstance () , true )},
297
+ new BuiltinDescr (() -> CodecInitNodeGen . create (), CodecInitNode . class , false ),
298
+ new BuiltinDescr (() -> StreamDecodeNodeGen . create (), StreamDecodeNode . class , true )},
296
299
codecsTruffleModule , codecsModule , language , factory );
297
300
298
301
// serves as factory function for CodecInfo-s incrementalencoder/decode and streamwriter/reader
299
302
// class apply_encoding:
300
303
// def __call__(self, *args, **kwargs):
301
304
// return self.fn(self.encoding, *args, **kwargs)
302
305
codecsTruffleBuiltins .applyEncodingClass = initClass (APPLY_ENCODING , context .getCore ().lookupType (PythonBuiltinClassType .PythonObject ),
303
- new BuiltinDescr []{new BuiltinDescr (CallApplyNodeFactory . getInstance () , false )},
306
+ new BuiltinDescr []{new BuiltinDescr (() -> CallApplyNodeGen . create (), CallApplyNode . class , false )},
304
307
codecsTruffleModule , language , factory );
305
308
}
306
309
// @formatter:on
307
310
308
311
@ Builtin (name = __INIT__ , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true )
309
- @ GenerateNodeFactory
310
312
protected abstract static class CodecInitNode extends PythonVarargsBuiltinNode {
311
313
@ Specialization
312
314
Object init (VirtualFrame frame , PythonObject self , Object [] args , PKeyword [] kw ,
@@ -338,7 +340,6 @@ protected SetAttributeNode createSetAttr() {
338
340
}
339
341
340
342
@ Builtin (name = __CALL__ , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true )
341
- @ GenerateNodeFactory
342
343
protected abstract static class CallApplyNode extends PythonVarargsBuiltinNode {
343
344
@ Specialization
344
345
Object call (VirtualFrame frame , PythonObject self , Object [] args , PKeyword [] kw ,
@@ -352,7 +353,6 @@ Object call(VirtualFrame frame, PythonObject self, Object[] args, PKeyword[] kw,
352
353
}
353
354
354
355
@ Builtin (name = ENCODE , minNumOfPositionalArgs = 2 , maxNumOfPositionalArgs = 3 )
355
- @ GenerateNodeFactory
356
356
protected abstract static class EncodeNode extends PythonTernaryBuiltinNode {
357
357
@ Specialization
358
358
Object encode (VirtualFrame frame , PythonObject self , Object input , Object errors ,
@@ -363,7 +363,6 @@ Object encode(VirtualFrame frame, PythonObject self, Object input, Object errors
363
363
}
364
364
365
365
@ Builtin (name = DECODE , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 3 )
366
- @ GenerateNodeFactory
367
366
protected abstract static class CodecDecodeNode extends PythonTernaryBuiltinNode {
368
367
@ Specialization
369
368
Object decode (VirtualFrame frame , PythonObject self , Object input , Object errors ,
@@ -374,7 +373,6 @@ Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors
374
373
}
375
374
376
375
@ Builtin (name = ENCODE , minNumOfPositionalArgs = 2 , maxNumOfPositionalArgs = 3 )
377
- @ GenerateNodeFactory
378
376
protected abstract static class IncrementalEncodeNode extends PythonTernaryBuiltinNode {
379
377
@ Specialization
380
378
Object encode (VirtualFrame frame , PythonObject self , Object input , @ SuppressWarnings ("unused" ) Object ffinal ,
@@ -387,7 +385,6 @@ Object encode(VirtualFrame frame, PythonObject self, Object input, @SuppressWarn
387
385
}
388
386
389
387
@ Builtin (name = BUFFER_DECODE , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 4 )
390
- @ GenerateNodeFactory
391
388
protected abstract static class IncrementalDecodeNode extends PythonQuaternaryBuiltinNode {
392
389
@ Specialization
393
390
Object decode (VirtualFrame frame , PythonObject self , Object input , Object errors , Object ffinal ,
@@ -398,7 +395,6 @@ Object decode(VirtualFrame frame, PythonObject self, Object input, Object errors
398
395
}
399
396
400
397
@ Builtin (name = DECODE , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 4 )
401
- @ GenerateNodeFactory
402
398
protected abstract static class StreamDecodeNode extends PythonQuaternaryBuiltinNode {
403
399
@ Specialization
404
400
Object decode (VirtualFrame frame , PythonObject self , Object input , Object errors , Object ffinal ,
0 commit comments