191191import com .oracle .graal .python .lib .PyObjectDir ;
192192import com .oracle .graal .python .lib .PyObjectFormat ;
193193import com .oracle .graal .python .lib .PyObjectGetAIter ;
194- import com .oracle .graal .python .lib .PyObjectGetAttr ;
195194import com .oracle .graal .python .lib .PyObjectGetAttrO ;
196195import com .oracle .graal .python .lib .PyObjectGetIter ;
196+ import com .oracle .graal .python .lib .PyObjectGetMethod ;
197197import com .oracle .graal .python .lib .PyObjectHashNode ;
198198import com .oracle .graal .python .lib .PyObjectIsInstanceNode ;
199199import com .oracle .graal .python .lib .PyObjectIsSubclassNode ;
232232import com .oracle .graal .python .nodes .bytecode_dsl .PBytecodeDSLRootNode ;
233233import com .oracle .graal .python .nodes .call .CallDispatchers ;
234234import com .oracle .graal .python .nodes .call .CallNode ;
235+ import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
235236import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
236237import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
237238import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
283284import com .oracle .truffle .api .CallTarget ;
284285import com .oracle .truffle .api .CompilerAsserts ;
285286import com .oracle .truffle .api .CompilerDirectives ;
286- import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
287287import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
288288import com .oracle .truffle .api .HostCompilerDirectives .InliningCutoff ;
289289import com .oracle .truffle .api .RootCallTarget ;
@@ -1575,14 +1575,13 @@ static Object ord(@SuppressWarnings("unused") Object obj,
15751575 @ GenerateNodeFactory
15761576 public abstract static class PrintNode extends PythonBuiltinNode {
15771577 @ Child private ReadAttributeFromModuleNode readStdout ;
1578- @ CompilationFinal private PythonModule cachedSys ;
15791578
15801579 @ Specialization
15811580 @ SuppressWarnings ("unused" )
15821581 PNone printNoKeywords (VirtualFrame frame , Object [] values , PNone sep , PNone end , PNone file , PNone flush ,
15831582 @ Bind Node inliningTarget ,
1584- @ Shared ("getWriteMethod" ) @ Cached PyObjectGetAttr getWriteMethod ,
1585- @ Shared ("callWrite" ) @ Cached CallNode callWrite ,
1583+ @ Shared ("getWriteMethod" ) @ Cached PyObjectGetMethod getWriteMethod ,
1584+ @ Shared ("callWrite" ) @ Cached CallBinaryMethodNode callWrite ,
15861585 @ Shared ("callFlush" ) @ Cached PyObjectCallMethodObjArgs callFlush ,
15871586 @ Shared ("strNode" ) @ Cached PyObjectStrAsObjectNode strNode ) {
15881587 Object stdout = getStdout ();
@@ -1596,23 +1595,22 @@ PNone printNoKeywords(VirtualFrame frame, Object[] values, PNone sep, PNone end,
15961595 @ Specialization (guards = {"!isNone(file)" , "!isNoValue(file)" })
15971596 static PNone printAllGiven (VirtualFrame frame , Object [] values , TruffleString sep , TruffleString end , Object file , boolean flush ,
15981597 @ Bind Node inliningTarget ,
1599- @ Shared ("getWriteMethod" ) @ Cached PyObjectGetAttr getWriteMethod ,
1600- @ Shared ("callWrite" ) @ Cached CallNode callWrite ,
1598+ @ Shared ("getWriteMethod" ) @ Cached PyObjectGetMethod getWriteMethod ,
1599+ @ Shared ("callWrite" ) @ Cached CallBinaryMethodNode callWrite ,
16011600 @ Shared ("callFlush" ) @ Cached PyObjectCallMethodObjArgs callFlush ,
16021601 @ Shared ("strNode" ) @ Cached PyObjectStrAsObjectNode strNode ) {
16031602 int lastValue = values .length - 1 ;
1604- // Note: the separate lookup is necessary due to different __getattr__ treatment than
1605- // method lookup
1603+ // Resolve write once, before converting the values to strings.
16061604 Object writeMethod = getWriteMethod .execute (frame , inliningTarget , file , T_WRITE );
16071605 for (int i = 0 ; i < lastValue ; i ++) {
1608- callWrite .execute (frame , writeMethod , strNode .execute (frame , inliningTarget , values [i ]));
1609- callWrite .execute (frame , writeMethod , sep );
1606+ callWrite .executeObject (frame , writeMethod , file , strNode .execute (frame , inliningTarget , values [i ]));
1607+ callWrite .executeObject (frame , writeMethod , file , sep );
16101608 }
16111609 LoopNode .reportLoopCount (inliningTarget , values .length == 0 ? 0 : values .length - 1 );
16121610 if (lastValue >= 0 ) {
1613- callWrite .execute (frame , writeMethod , strNode .execute (frame , inliningTarget , values [lastValue ]));
1611+ callWrite .executeObject (frame , writeMethod , file , strNode .execute (frame , inliningTarget , values [lastValue ]));
16141612 }
1615- callWrite .execute (frame , writeMethod , end );
1613+ callWrite .executeObject (frame , writeMethod , file , end );
16161614 if (flush ) {
16171615 callFlush .execute (frame , inliningTarget , file , T_FLUSH );
16181616 }
@@ -1626,8 +1624,8 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
16261624 @ Cached CastToTruffleStringNode castSep ,
16271625 @ Cached CastToTruffleStringNode castEnd ,
16281626 @ Cached PyObjectIsTrueNode castFlush ,
1629- @ Exclusive @ Cached PyObjectGetAttr getWriteMethod ,
1630- @ Exclusive @ Cached CallNode callWrite ,
1627+ @ Exclusive @ Cached PyObjectGetMethod getWriteMethod ,
1628+ @ Exclusive @ Cached CallBinaryMethodNode callWrite ,
16311629 @ Exclusive @ Cached PyObjectCallMethodObjArgs callFlush ,
16321630 @ Exclusive @ Cached PyObjectStrAsObjectNode strNode ,
16331631 @ Cached PRaiseNode raiseNode ) {
@@ -1665,20 +1663,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
16651663 }
16661664
16671665 private Object getStdout () {
1668- PythonModule sys ;
1669- if (getLanguage ().isSingleContext ()) {
1670- if (cachedSys == null ) {
1671- CompilerDirectives .transferToInterpreterAndInvalidate ();
1672- cachedSys = getContext ().lookupBuiltinModule (T_SYS );
1673- }
1674- sys = cachedSys ;
1675- } else {
1676- if (cachedSys != null ) {
1677- CompilerDirectives .transferToInterpreterAndInvalidate ();
1678- cachedSys = null ;
1679- }
1680- sys = getContext ().lookupBuiltinModule (T_SYS );
1681- }
1666+ PythonModule sys = getContext ().getSysModule ();
16821667 if (readStdout == null ) {
16831668 CompilerDirectives .transferToInterpreterAndInvalidate ();
16841669 readStdout = insert (ReadAttributeFromModuleNode .create ());
0 commit comments