4242
4343import static com .oracle .graal .python .nodes .BuiltinNames .J_READLINE ;
4444import static com .oracle .graal .python .nodes .BuiltinNames .T_READLINE ;
45- import static com .oracle .graal .python .nodes .HiddenAttr .DATA ;
4645import static com .oracle .graal .python .util .PythonUtils .toTruffleStringUncached ;
4746
4847import java .io .BufferedReader ;
6261import com .oracle .graal .python .builtins .objects .module .PythonModule ;
6362import com .oracle .graal .python .builtins .objects .str .PString ;
6463import com .oracle .graal .python .nodes .ErrorMessages ;
65- import com .oracle .graal .python .nodes .HiddenAttr ;
6664import com .oracle .graal .python .nodes .PRaiseNode ;
6765import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
6866import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
@@ -100,17 +98,15 @@ private static final class LocalData {
10098 @ Override
10199 public void postInitialize (Python3Core core ) {
102100 super .postInitialize (core );
103- HiddenAttr . WriteNode . executeUncached ( core .lookupBuiltinModule (T_READLINE ), DATA , new LocalData ());
101+ core .lookupBuiltinModule (T_READLINE ). setModuleState ( new LocalData ());
104102 }
105103
106104 @ Builtin (name = "get_completer" , minNumOfPositionalArgs = 1 , declaresExplicitSelf = true )
107105 @ GenerateNodeFactory
108106 abstract static class GetCompleterNode extends PythonUnaryBuiltinNode {
109107 @ 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 );
114110 if (data .completer != null ) {
115111 return data .completer ;
116112 } else {
@@ -123,10 +119,8 @@ static Object getCompleter(PythonModule self,
123119 @ GenerateNodeFactory
124120 abstract static class SetCompleterNode extends PythonBinaryBuiltinNode {
125121 @ 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 );
130124 data .completer = callable ;
131125 return PNone .NONE ;
132126 }
@@ -140,7 +134,7 @@ abstract static class ParseAndBindNode extends PythonBinaryBuiltinNode {
140134 PNone setCompleter (PythonModule self , TruffleString tspec ) {
141135 String spec = tspec .toJavaStringUncached ();
142136 if (spec .startsWith ("tab:" )) {
143- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
137+ LocalData data = self . getModuleState (LocalData . class );
144138 data .bindings .put ("tab" , spec .split (":" )[1 ].trim ());
145139 return PNone .NONE ;
146140 } else {
@@ -165,7 +159,7 @@ abstract static class GetHistoryLengthNode extends PythonUnaryBuiltinNode {
165159 @ Specialization
166160 @ TruffleBoundary
167161 int setCompleter (PythonModule self ) {
168- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
162+ LocalData data = self . getModuleState (LocalData . class );
169163 return data .history .size ();
170164 }
171165 }
@@ -176,7 +170,7 @@ abstract static class SetHistoryLengthNode extends PythonBinaryBuiltinNode {
176170 @ Specialization
177171 @ TruffleBoundary
178172 TruffleString setCompleter (PythonModule self , int index ) {
179- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
173+ LocalData data = self . getModuleState (LocalData . class );
180174 try {
181175 return data .history .get (index );
182176 } catch (IndexOutOfBoundsException e ) {
@@ -198,7 +192,7 @@ TruffleString setCompleter(PythonModule self, int index, PString string,
198192 @ Specialization
199193 @ TruffleBoundary
200194 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 );
202196 try {
203197 return data .history .set (index , string );
204198 } catch (IndexOutOfBoundsException e ) {
@@ -213,7 +207,7 @@ abstract static class DeleteItemNode extends PythonBinaryBuiltinNode {
213207 @ Specialization
214208 @ TruffleBoundary
215209 TruffleString setCompleter (PythonModule self , int index ) {
216- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
210+ LocalData data = self . getModuleState (LocalData . class );
217211 try {
218212 return data .history .remove (index );
219213 } catch (IndexOutOfBoundsException e ) {
@@ -235,7 +229,7 @@ static PNone addHistory(PythonModule self, PString item,
235229 @ Specialization
236230 @ TruffleBoundary
237231 static PNone addHistory (PythonModule self , TruffleString item ) {
238- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
232+ LocalData data = self . getModuleState (LocalData . class );
239233 data .history .add (item );
240234 return PNone .NONE ;
241235 }
@@ -255,7 +249,7 @@ PNone setCompleter(PythonModule self, PString path,
255249 @ TruffleBoundary
256250 @ SuppressWarnings ("try" )
257251 PNone setCompleter (PythonModule self , TruffleString path ) {
258- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
252+ LocalData data = self . getModuleState (LocalData . class );
259253 try (GilNode .UncachedRelease gil = GilNode .uncachedRelease ()) {
260254 BufferedReader reader = getContext ().getEnv ().getPublicTruffleFile (path .toJavaStringUncached ()).newBufferedReader ();
261255 String line ;
@@ -283,7 +277,7 @@ PNone setCompleter(PythonModule self, PString path,
283277 @ Specialization
284278 @ TruffleBoundary
285279 PNone setCompleter (PythonModule self , TruffleString path ) {
286- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
280+ LocalData data = self . getModuleState (LocalData . class );
287281 try {
288282 BufferedWriter writer = getContext ().getEnv ().getPublicTruffleFile (path .toJavaStringUncached ()).newBufferedWriter (StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
289283 for (TruffleString l : data .history ) {
@@ -304,7 +298,7 @@ abstract static class ClearNode extends PythonUnaryBuiltinNode {
304298 @ Specialization
305299 @ TruffleBoundary
306300 static PNone setCompleter (PythonModule self ) {
307- LocalData data = (LocalData ) HiddenAttr . ReadNode . executeUncached ( self , DATA , null );
301+ LocalData data = self . getModuleState (LocalData . class );
308302 data .history .clear ();
309303 return PNone .NONE ;
310304 }
@@ -314,7 +308,7 @@ static PNone setCompleter(PythonModule self) {
314308 @ GenerateNodeFactory
315309 abstract static class InsertTextNode extends PythonUnaryBuiltinNode {
316310 @ Specialization
317- PNone setCompleter (@ SuppressWarnings ("unused" ) Object text ) {
311+ static PNone setCompleter (@ SuppressWarnings ("unused" ) Object text ) {
318312 return PNone .NONE ;
319313 }
320314 }
@@ -323,7 +317,7 @@ PNone setCompleter(@SuppressWarnings("unused") Object text) {
323317 @ GenerateNodeFactory
324318 abstract static class RedisplayNode extends PythonBuiltinNode {
325319 @ Specialization
326- PNone setCompleter () {
320+ static PNone setCompleter () {
327321 return PNone .NONE ;
328322 }
329323 }
@@ -332,10 +326,8 @@ PNone setCompleter() {
332326 @ GenerateNodeFactory
333327 abstract static class GetAutoHistoryNode extends PythonUnaryBuiltinNode {
334328 @ 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 );
339331 return data .autoHistory ;
340332 }
341333 }
@@ -344,10 +336,8 @@ boolean setCompleter(PythonModule self,
344336 @ GenerateNodeFactory
345337 abstract static class SetAutoHistoryNode extends PythonBinaryBuiltinNode {
346338 @ 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 );
351341 data .autoHistory = enabled ;
352342 return PNone .NONE ;
353343 }
@@ -357,10 +347,8 @@ PNone setCompleter(PythonModule self, boolean enabled,
357347 @ GenerateNodeFactory
358348 abstract static class SetCompleterDelimsNode extends PythonBinaryBuiltinNode {
359349 @ 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 );
364352 data .completerDelims = completerDelims ;
365353 return PNone .NONE ;
366354 }
@@ -370,10 +358,8 @@ PNone setCompleterDelims(PythonModule self, TruffleString completerDelims,
370358 @ GenerateNodeFactory
371359 abstract static class GetCompleterDelimsNode extends PythonBuiltinNode {
372360 @ 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 );
377363 return (data .completerDelims != null ) ? data .completerDelims : PNone .NONE ;
378364 }
379365 }
0 commit comments