42
42
43
43
import static com .oracle .graal .python .nodes .BuiltinNames .J_READLINE ;
44
44
import static com .oracle .graal .python .nodes .BuiltinNames .T_READLINE ;
45
- import static com .oracle .graal .python .nodes .HiddenAttr .DATA ;
46
45
import static com .oracle .graal .python .util .PythonUtils .toTruffleStringUncached ;
47
46
48
47
import java .io .BufferedReader ;
62
61
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
63
62
import com .oracle .graal .python .builtins .objects .str .PString ;
64
63
import com .oracle .graal .python .nodes .ErrorMessages ;
65
- import com .oracle .graal .python .nodes .HiddenAttr ;
66
64
import com .oracle .graal .python .nodes .PRaiseNode ;
67
65
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
68
66
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
@@ -100,17 +98,15 @@ private static final class LocalData {
100
98
@ Override
101
99
public void postInitialize (Python3Core core ) {
102
100
super .postInitialize (core );
103
- HiddenAttr . WriteNode . executeUncached ( core .lookupBuiltinModule (T_READLINE ), DATA , new LocalData ());
101
+ core .lookupBuiltinModule (T_READLINE ). setModuleState ( new LocalData ());
104
102
}
105
103
106
104
@ Builtin (name = "get_completer" , minNumOfPositionalArgs = 1 , declaresExplicitSelf = true )
107
105
@ GenerateNodeFactory
108
106
abstract static class GetCompleterNode extends PythonUnaryBuiltinNode {
109
107
@ Specialization
110
- static Object getCompleter (PythonModule self ,
111
- @ Bind ("this" ) Node inliningTarget ,
112
- @ Cached HiddenAttr .ReadNode readNode ) {
113
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
108
+ static Object getCompleter (PythonModule self ) {
109
+ LocalData data = self .getModuleState (LocalData .class );
114
110
if (data .completer != null ) {
115
111
return data .completer ;
116
112
} else {
@@ -123,10 +119,8 @@ static Object getCompleter(PythonModule self,
123
119
@ GenerateNodeFactory
124
120
abstract static class SetCompleterNode extends PythonBinaryBuiltinNode {
125
121
@ Specialization
126
- PNone setCompleter (PythonModule self , Object callable ,
127
- @ Bind ("this" ) Node inliningTarget ,
128
- @ Cached HiddenAttr .ReadNode readNode ) {
129
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
122
+ PNone setCompleter (PythonModule self , Object callable ) {
123
+ LocalData data = self .getModuleState (LocalData .class );
130
124
data .completer = callable ;
131
125
return PNone .NONE ;
132
126
}
@@ -140,7 +134,7 @@ abstract static class ParseAndBindNode extends PythonBinaryBuiltinNode {
140
134
PNone setCompleter (PythonModule self , TruffleString tspec ) {
141
135
String spec = tspec .toJavaStringUncached ();
142
136
if (spec .startsWith ("tab:" )) {
143
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
137
+ LocalData data = self . getModuleState (LocalData . class );
144
138
data .bindings .put ("tab" , spec .split (":" )[1 ].trim ());
145
139
return PNone .NONE ;
146
140
} else {
@@ -165,7 +159,7 @@ abstract static class GetHistoryLengthNode extends PythonUnaryBuiltinNode {
165
159
@ Specialization
166
160
@ TruffleBoundary
167
161
int setCompleter (PythonModule self ) {
168
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
162
+ LocalData data = self . getModuleState (LocalData . class );
169
163
return data .history .size ();
170
164
}
171
165
}
@@ -176,7 +170,7 @@ abstract static class SetHistoryLengthNode extends PythonBinaryBuiltinNode {
176
170
@ Specialization
177
171
@ TruffleBoundary
178
172
TruffleString setCompleter (PythonModule self , int index ) {
179
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
173
+ LocalData data = self . getModuleState (LocalData . class );
180
174
try {
181
175
return data .history .get (index );
182
176
} catch (IndexOutOfBoundsException e ) {
@@ -198,7 +192,7 @@ TruffleString setCompleter(PythonModule self, int index, PString string,
198
192
@ Specialization
199
193
@ TruffleBoundary
200
194
TruffleString setCompleter (PythonModule self , int index , TruffleString string ) {
201
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
195
+ LocalData data = self . getModuleState (LocalData . class );
202
196
try {
203
197
return data .history .set (index , string );
204
198
} catch (IndexOutOfBoundsException e ) {
@@ -213,7 +207,7 @@ abstract static class DeleteItemNode extends PythonBinaryBuiltinNode {
213
207
@ Specialization
214
208
@ TruffleBoundary
215
209
TruffleString setCompleter (PythonModule self , int index ) {
216
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
210
+ LocalData data = self . getModuleState (LocalData . class );
217
211
try {
218
212
return data .history .remove (index );
219
213
} catch (IndexOutOfBoundsException e ) {
@@ -235,7 +229,7 @@ static PNone addHistory(PythonModule self, PString item,
235
229
@ Specialization
236
230
@ TruffleBoundary
237
231
static PNone addHistory (PythonModule self , TruffleString item ) {
238
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
232
+ LocalData data = self . getModuleState (LocalData . class );
239
233
data .history .add (item );
240
234
return PNone .NONE ;
241
235
}
@@ -255,7 +249,7 @@ PNone setCompleter(PythonModule self, PString path,
255
249
@ TruffleBoundary
256
250
@ SuppressWarnings ("try" )
257
251
PNone setCompleter (PythonModule self , TruffleString path ) {
258
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
252
+ LocalData data = self . getModuleState (LocalData . class );
259
253
try (GilNode .UncachedRelease gil = GilNode .uncachedRelease ()) {
260
254
BufferedReader reader = getContext ().getEnv ().getPublicTruffleFile (path .toJavaStringUncached ()).newBufferedReader ();
261
255
String line ;
@@ -283,7 +277,7 @@ PNone setCompleter(PythonModule self, PString path,
283
277
@ Specialization
284
278
@ TruffleBoundary
285
279
PNone setCompleter (PythonModule self , TruffleString path ) {
286
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
280
+ LocalData data = self . getModuleState (LocalData . class );
287
281
try {
288
282
BufferedWriter writer = getContext ().getEnv ().getPublicTruffleFile (path .toJavaStringUncached ()).newBufferedWriter (StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
289
283
for (TruffleString l : data .history ) {
@@ -304,7 +298,7 @@ abstract static class ClearNode extends PythonUnaryBuiltinNode {
304
298
@ Specialization
305
299
@ TruffleBoundary
306
300
static PNone setCompleter (PythonModule self ) {
307
- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
301
+ LocalData data = self . getModuleState (LocalData . class );
308
302
data .history .clear ();
309
303
return PNone .NONE ;
310
304
}
@@ -314,7 +308,7 @@ static PNone setCompleter(PythonModule self) {
314
308
@ GenerateNodeFactory
315
309
abstract static class InsertTextNode extends PythonUnaryBuiltinNode {
316
310
@ Specialization
317
- PNone setCompleter (@ SuppressWarnings ("unused" ) Object text ) {
311
+ static PNone setCompleter (@ SuppressWarnings ("unused" ) Object text ) {
318
312
return PNone .NONE ;
319
313
}
320
314
}
@@ -323,7 +317,7 @@ PNone setCompleter(@SuppressWarnings("unused") Object text) {
323
317
@ GenerateNodeFactory
324
318
abstract static class RedisplayNode extends PythonBuiltinNode {
325
319
@ Specialization
326
- PNone setCompleter () {
320
+ static PNone setCompleter () {
327
321
return PNone .NONE ;
328
322
}
329
323
}
@@ -332,10 +326,8 @@ PNone setCompleter() {
332
326
@ GenerateNodeFactory
333
327
abstract static class GetAutoHistoryNode extends PythonUnaryBuiltinNode {
334
328
@ Specialization
335
- boolean setCompleter (PythonModule self ,
336
- @ Bind ("this" ) Node inliningTarget ,
337
- @ Cached HiddenAttr .ReadNode readNode ) {
338
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
329
+ static boolean setCompleter (PythonModule self ) {
330
+ LocalData data = self .getModuleState (LocalData .class );
339
331
return data .autoHistory ;
340
332
}
341
333
}
@@ -344,10 +336,8 @@ boolean setCompleter(PythonModule self,
344
336
@ GenerateNodeFactory
345
337
abstract static class SetAutoHistoryNode extends PythonBinaryBuiltinNode {
346
338
@ Specialization
347
- PNone setCompleter (PythonModule self , boolean enabled ,
348
- @ Bind ("this" ) Node inliningTarget ,
349
- @ Cached HiddenAttr .ReadNode readNode ) {
350
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
339
+ static PNone setCompleter (PythonModule self , boolean enabled ) {
340
+ LocalData data = self .getModuleState (LocalData .class );
351
341
data .autoHistory = enabled ;
352
342
return PNone .NONE ;
353
343
}
@@ -357,10 +347,8 @@ PNone setCompleter(PythonModule self, boolean enabled,
357
347
@ GenerateNodeFactory
358
348
abstract static class SetCompleterDelimsNode extends PythonBinaryBuiltinNode {
359
349
@ Specialization
360
- PNone setCompleterDelims (PythonModule self , TruffleString completerDelims ,
361
- @ Bind ("this" ) Node inliningTarget ,
362
- @ Cached HiddenAttr .ReadNode readNode ) {
363
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
350
+ static PNone setCompleterDelims (PythonModule self , TruffleString completerDelims ) {
351
+ LocalData data = self .getModuleState (LocalData .class );
364
352
data .completerDelims = completerDelims ;
365
353
return PNone .NONE ;
366
354
}
@@ -370,10 +358,8 @@ PNone setCompleterDelims(PythonModule self, TruffleString completerDelims,
370
358
@ GenerateNodeFactory
371
359
abstract static class GetCompleterDelimsNode extends PythonBuiltinNode {
372
360
@ Specialization
373
- Object getCompleterDelims (PythonModule self ,
374
- @ Bind ("this" ) Node inliningTarget ,
375
- @ Cached HiddenAttr .ReadNode readNode ) {
376
- LocalData data = (LocalData ) readNode .execute (inliningTarget , self , DATA , null );
361
+ static Object getCompleterDelims (PythonModule self ) {
362
+ LocalData data = self .getModuleState (LocalData .class );
377
363
return (data .completerDelims != null ) ? data .completerDelims : PNone .NONE ;
378
364
}
379
365
}
0 commit comments