62
62
import static com .oracle .graal .python .nodes .BuiltinNames .__BUILTINS__ ;
63
63
import static com .oracle .graal .python .nodes .BuiltinNames .__DEBUG__ ;
64
64
import static com .oracle .graal .python .nodes .BuiltinNames .__GRAALPYTHON__ ;
65
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__ABS__ ;
65
66
import static com .oracle .graal .python .nodes .SpecialMethodNames .__INSTANCECHECK__ ;
66
67
import static com .oracle .graal .python .nodes .SpecialMethodNames .__NEXT__ ;
67
68
import static com .oracle .graal .python .nodes .SpecialMethodNames .__SUBCLASSCHECK__ ;
120
121
import com .oracle .graal .python .nodes .SpecialMethodNames ;
121
122
import com .oracle .graal .python .nodes .argument .ReadArgumentNode ;
122
123
import com .oracle .graal .python .nodes .attributes .DeleteAttributeNode ;
123
- import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
124
124
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
125
125
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetFixedAttributeNode ;
126
126
import com .oracle .graal .python .nodes .attributes .HasInheritedAttributeNode ;
@@ -241,14 +241,15 @@ public double absDouble(double arg) {
241
241
return Math .abs (arg );
242
242
}
243
243
244
- @ Specialization
244
+ @ Specialization ( limit = "2" )
245
245
public Object absObject (VirtualFrame frame , Object object ,
246
- @ Cached ("create(__ABS__)" ) LookupAndCallUnaryNode callAbsNode ) {
247
- Object result = callAbsNode .executeObject (frame , object );
248
- if (result == NO_VALUE ) {
246
+ @ CachedLibrary ("object" ) PythonObjectLibrary lib ,
247
+ @ CachedLibrary (limit = "2" ) PythonObjectLibrary methodLib ) {
248
+ Object method = lib .lookupAttributeOnType (object , __ABS__ );
249
+ if (method == NO_VALUE ) {
249
250
throw raise (TypeError , ErrorMessages .BAD_OPERAND_FOR , "" , "abs()" , object );
250
251
}
251
- return result ;
252
+ return methodLib . callUnboundMethod ( method , frame , object ) ;
252
253
}
253
254
}
254
255
@@ -311,14 +312,13 @@ String doPI(PInt x) {
311
312
312
313
@ Specialization (replaces = {"doL" , "doD" , "doPI" })
313
314
String doO (VirtualFrame frame , Object x ,
314
- @ Cached ConditionProfile hasFrame ,
315
315
@ Cached ConditionProfile isMinLong ,
316
316
@ Cached IsSubtypeNode isSubtype ,
317
317
@ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) PythonObjectLibrary lib ,
318
318
@ Cached BranchProfile isInt ,
319
319
@ Cached BranchProfile isLong ,
320
320
@ Cached BranchProfile isPInt ) {
321
- Object index = lib .asIndexWithFrame (x , hasFrame , frame );
321
+ Object index = lib .asIndexWithFrame (x , frame );
322
322
if (isSubtype .execute (lib .getLazyPythonClass (index ), PythonBuiltinClassType .PInt )) {
323
323
if (index instanceof Boolean || index instanceof Integer ) {
324
324
isInt .enter ();
@@ -467,9 +467,8 @@ public char charFromObject(Object arg) {
467
467
public abstract static class HashNode extends PythonUnaryBuiltinNode {
468
468
@ Specialization (limit = "getCallSiteInlineCacheMaxDepth()" )
469
469
long hash (VirtualFrame frame , Object object ,
470
- @ Cached ("createBinaryProfile()" ) ConditionProfile profile ,
471
470
@ CachedLibrary ("object" ) PythonObjectLibrary lib ) {
472
- return lib .hashWithFrame (object , profile , frame );
471
+ return lib .hashWithFrame (object , frame );
473
472
}
474
473
}
475
474
@@ -1314,9 +1313,8 @@ public Object iter(Object callable, Object sentinel) {
1314
1313
public abstract static class LenNode extends PythonUnaryBuiltinNode {
1315
1314
@ Specialization (limit = "getCallSiteInlineCacheMaxDepth()" )
1316
1315
public int len (VirtualFrame frame , Object obj ,
1317
- @ Cached ("createBinaryProfile()" ) ConditionProfile hasFrame ,
1318
1316
@ CachedLibrary ("obj" ) PythonObjectLibrary lib ) {
1319
- return lib .lengthWithFrame (obj , hasFrame , frame );
1317
+ return lib .lengthWithFrame (obj , frame );
1320
1318
}
1321
1319
}
1322
1320
@@ -1572,39 +1570,35 @@ public abstract static class PrintNode extends PythonBuiltinNode {
1572
1570
private static final String DEFAULT_END = "\n " ;
1573
1571
private static final String DEFAULT_SEPARATOR = " " ;
1574
1572
@ Child private ReadAttributeFromObjectNode readStdout ;
1575
- @ Child private GetAttributeNode getWrite = GetAttributeNode .create ("write" , null );
1576
- @ Child private CallNode callWrite = CallNode .create ();
1577
- @ Child private LookupAndCallUnaryNode callFlushNode ;
1578
1573
@ CompilationFinal private Assumption singleContextAssumption ;
1579
1574
@ CompilationFinal private PythonModule cachedSys ;
1580
1575
1581
1576
@ Specialization
1582
1577
PNone printNoKeywords (VirtualFrame frame , Object [] values , @ SuppressWarnings ("unused" ) PNone sep , @ SuppressWarnings ("unused" ) PNone end , @ SuppressWarnings ("unused" ) PNone file ,
1583
1578
@ SuppressWarnings ("unused" ) PNone flush ,
1584
- @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
1579
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1580
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary valueLib ) {
1585
1581
Object stdout = getStdout ();
1586
- return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , lib );
1582
+ return printAllGiven (frame , values , DEFAULT_SEPARATOR , DEFAULT_END , stdout , false , lib , valueLib );
1587
1583
}
1588
1584
1589
1585
@ Specialization (guards = {"!isNone(file)" , "!isNoValue(file)" })
1590
1586
PNone printAllGiven (VirtualFrame frame , Object [] values , String sep , String end , Object file , boolean flush ,
1591
- @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
1587
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ,
1588
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary valueLib ) {
1592
1589
int lastValue = values .length - 1 ;
1593
- Object write = getWrite . executeObject ( frame , file );
1590
+ Object writeMethod = lib . lookupAttributeStrict ( file , frame , "write" );
1594
1591
for (int i = 0 ; i < lastValue ; i ++) {
1595
- callWrite . execute ( frame , write , lib .asPString (values [i ]));
1596
- callWrite . execute ( frame , write , sep );
1592
+ lib . callObject ( writeMethod , frame , valueLib .asPString (values [i ]));
1593
+ lib . callObject ( writeMethod , frame , sep );
1597
1594
}
1598
1595
if (lastValue >= 0 ) {
1599
- callWrite . execute ( frame , write , lib .asPString (values [lastValue ]));
1596
+ lib . callObject ( writeMethod , frame , valueLib .asPString (values [lastValue ]));
1600
1597
}
1601
- callWrite . execute ( frame , write , end );
1598
+ lib . callObject ( writeMethod , frame , end );
1602
1599
if (flush ) {
1603
- if (callFlushNode == null ) {
1604
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1605
- callFlushNode = insert (LookupAndCallUnaryNode .create ("flush" ));
1606
- }
1607
- callFlushNode .executeObject (frame , file );
1600
+ Object flushMethod = lib .lookupAttributeStrict (file , frame , "flush" );
1601
+ lib .callObject (flushMethod , frame );
1608
1602
}
1609
1603
return PNone .NONE ;
1610
1604
}
@@ -1615,7 +1609,8 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1615
1609
@ Cached CastToJavaStringNode castEnd ,
1616
1610
@ Cached ("createIfTrueNode()" ) CoerceToBooleanNode castFlush ,
1617
1611
@ Cached PRaiseNode raiseNode ,
1618
- @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
1612
+ @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
1613
+ @ CachedLibrary (limit = "3" ) PythonObjectLibrary valueLib ) {
1619
1614
String sep ;
1620
1615
try {
1621
1616
sep = sepIn instanceof PNone ? DEFAULT_SEPARATOR : castSep .execute (sepIn );
@@ -1642,7 +1637,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
1642
1637
} else {
1643
1638
flush = castFlush .executeBoolean (frame , flushIn );
1644
1639
}
1645
- return printAllGiven (frame , values , sep , end , file , flush , lib );
1640
+ return printAllGiven (frame , values , sep , end , file , flush , lib , valueLib );
1646
1641
}
1647
1642
1648
1643
private Object getStdout () {
0 commit comments