@@ -1633,23 +1633,17 @@ public int len(VirtualFrame frame, Object obj,
1633
1633
}
1634
1634
}
1635
1635
1636
- public abstract static class MinMaxNode extends PythonBuiltinNode {
1637
- @ NeverDefault
1638
- protected final BinaryComparisonNode createComparison () {
1639
- if (this instanceof MaxNode ) {
1640
- return BinaryComparisonNode .GtNode .create ();
1641
- } else {
1642
- return BinaryComparisonNode .LtNode .create ();
1643
- }
1644
- }
1636
+ @ GenerateInline
1637
+ @ GenerateCached (false )
1638
+ public abstract static class MinMaxNode extends Node {
1639
+
1640
+ abstract Object execute (VirtualFrame frame , Node inliningTarget , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal , String name , BinaryComparisonNode comparisonNode );
1645
1641
1646
1642
@ Specialization (guards = "args.length == 0" )
1647
- @ SuppressWarnings ("truffle-static-method" ) // TODO: inh
1648
- Object minmaxSequenceWithKey (VirtualFrame frame , Object arg1 , @ SuppressWarnings ("unused" ) Object [] args , Object keywordArgIn , Object defaultVal ,
1649
- @ Bind ("this" ) Node inliningTarget ,
1643
+ static Object minmaxSequenceWithKey (VirtualFrame frame , Node inliningTarget , Object arg1 , @ SuppressWarnings ("unused" ) Object [] args , Object keywordArgIn , Object defaultVal , String name ,
1644
+ BinaryComparisonNode compare ,
1650
1645
@ Exclusive @ Cached PyObjectGetIter getIter ,
1651
- @ Cached GetNextNode nextNode ,
1652
- @ Shared @ Cached ("createComparison()" ) BinaryComparisonNode compare ,
1646
+ @ Cached (inline = false ) GetNextNode nextNode ,
1653
1647
@ Exclusive @ Cached CoerceToBooleanNode .YesNode castToBooleanNode ,
1654
1648
@ Exclusive @ Cached CallNode .Lazy keyCall ,
1655
1649
@ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
@@ -1668,7 +1662,7 @@ Object minmaxSequenceWithKey(VirtualFrame frame, Object arg1, @SuppressWarnings(
1668
1662
} catch (PException e ) {
1669
1663
e .expectStopIteration (inliningTarget , errorProfile1 );
1670
1664
if (hasDefaultProfile .profile (inliningTarget , isNoValue (defaultVal ))) {
1671
- throw raiseNode .get (inliningTarget ).raise (PythonErrorType .ValueError , ErrorMessages .ARG_IS_EMPTY_SEQ , getName () );
1665
+ throw raiseNode .get (inliningTarget ).raise (PythonErrorType .ValueError , ErrorMessages .ARG_IS_EMPTY_SEQ , name );
1672
1666
} else {
1673
1667
return defaultVal ;
1674
1668
}
@@ -1708,15 +1702,8 @@ Object minmaxSequenceWithKey(VirtualFrame frame, Object arg1, @SuppressWarnings(
1708
1702
return currentValue ;
1709
1703
}
1710
1704
1711
- private String getName () {
1712
- return this instanceof MaxNode ? "max" : "min" ;
1713
- }
1714
-
1715
1705
@ Specialization (guards = {"args.length != 0" })
1716
- @ SuppressWarnings ("truffle-static-method" ) // TODO: inh
1717
- Object minmaxBinaryWithKey (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1718
- @ Bind ("this" ) Node inliningTarget ,
1719
- @ Shared @ Cached ("createComparison()" ) BinaryComparisonNode compare ,
1706
+ static Object minmaxBinaryWithKey (VirtualFrame frame , Node inliningTarget , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal , String name , BinaryComparisonNode compare ,
1720
1707
@ Exclusive @ Cached CallNode .Lazy keyCall ,
1721
1708
@ Exclusive @ Cached CoerceToBooleanNode .YesNode castToBooleanNode ,
1722
1709
@ Exclusive @ Cached InlinedBranchProfile seenNonBoolean ,
@@ -1730,7 +1717,7 @@ Object minmaxBinaryWithKey(VirtualFrame frame, Object arg1, Object[] args, Objec
1730
1717
Object keywordArg = kwArgsAreNone ? null : keywordArgIn ;
1731
1718
1732
1719
if (!hasDefaultProfile .profile (inliningTarget , isNoValue (defaultVal ))) {
1733
- throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .TypeError , ErrorMessages .CANNOT_SPECIFY_DEFAULT_FOR_S , getName () );
1720
+ throw raiseNode .get (inliningTarget ).raise (PythonBuiltinClassType .TypeError , ErrorMessages .CANNOT_SPECIFY_DEFAULT_FOR_S , name );
1734
1721
}
1735
1722
Object currentValue = arg1 ;
1736
1723
Object currentKey = applyKeyFunction (frame , inliningTarget , keywordArg , keyCall , currentValue );
@@ -1787,16 +1774,29 @@ private static Object applyKeyFunction(VirtualFrame frame, Node inliningTarget,
1787
1774
"max(arg1, arg2, *args, *[, key=func]) -> value\n \n " + "With a single iterable argument, return its biggest item. The\n " +
1788
1775
"default keyword-only argument specifies an object to return if\n " + "the provided iterable is empty.\n " + "With two or more arguments, return the largest argument." )
1789
1776
@ GenerateNodeFactory
1790
- public abstract static class MaxNode extends MinMaxNode {
1777
+ public abstract static class MaxNode extends PythonBuiltinNode {
1791
1778
1779
+ @ Specialization
1780
+ static Object max (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1781
+ @ Bind ("this" ) Node inliningTarget ,
1782
+ @ Cached MinMaxNode minMaxNode ,
1783
+ @ Cached BinaryComparisonNode .GtNode gtNode ) {
1784
+ return minMaxNode .execute (frame , inliningTarget , arg1 , args , keywordArgIn , defaultVal , "max" , gtNode );
1785
+ }
1792
1786
}
1793
1787
1794
1788
// min(iterable, *[, key])
1795
1789
// min(arg1, arg2, *args[, key])
1796
1790
@ Builtin (name = J_MIN , minNumOfPositionalArgs = 1 , takesVarArgs = true , keywordOnlyNames = {"key" , "default" })
1797
1791
@ GenerateNodeFactory
1798
- public abstract static class MinNode extends MinMaxNode {
1799
-
1792
+ public abstract static class MinNode extends PythonBuiltinNode {
1793
+ @ Specialization
1794
+ static Object min (VirtualFrame frame , Object arg1 , Object [] args , Object keywordArgIn , Object defaultVal ,
1795
+ @ Bind ("this" ) Node inliningTarget ,
1796
+ @ Cached MinMaxNode minMaxNode ,
1797
+ @ Cached BinaryComparisonNode .LtNode ltNode ) {
1798
+ return minMaxNode .execute (frame , inliningTarget , arg1 , args , keywordArgIn , defaultVal , "min" , ltNode );
1799
+ }
1800
1800
}
1801
1801
1802
1802
// next(iterator[, default])
0 commit comments