Skip to content

Commit ebded0c

Browse files
committed
[GR-30482] Migrate remaining numeric conversions to nodes
PullRequest: graalpython/1788
2 parents 99c6832 + 621c9c5 commit ebded0c

File tree

62 files changed

+1508
-1313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1508
-1313
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/objects/PythonObjectLibraryTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@
4040
*/
4141
package com.oracle.graal.python.test.objects;
4242

43-
import static org.junit.Assert.assertEquals;
4443
import static org.junit.Assert.assertNotNull;
4544
import static org.junit.Assert.assertNotSame;
4645
import static org.junit.Assert.assertSame;
4746
import static org.junit.Assert.fail;
4847

49-
import java.math.BigInteger;
5048
import java.util.concurrent.Callable;
5149

52-
import com.oracle.graal.python.builtins.objects.ints.PInt;
5350
import org.graalvm.polyglot.Context;
5451
import org.graalvm.polyglot.Value;
5552
import org.graalvm.polyglot.proxy.ProxyExecutable;
@@ -100,17 +97,6 @@ public void testLookupAttribute() {
10097
lookupAttr(() -> "abc", noSuchMethod, true);
10198
}
10299

103-
@Test
104-
public void testPIntAsJavaLong() {
105-
execInContext(() -> {
106-
PInt p = PythonObjectFactory.getUncached().createInt(BigInteger.valueOf(123));
107-
PythonObjectLibrary lib = PythonObjectLibrary.getFactory().getUncached();
108-
assertEquals(123, lib.asJavaLong(p));
109-
assertEquals(123, lib.asJavaLong(p, null));
110-
return null;
111-
});
112-
}
113-
114100
private void lookupAttr(Callable<Object> createValue, String attrName, boolean expectNoValue) {
115101
PythonObjectLibrary lib = PythonObjectLibrary.getFactory().getUncached();
116102
execInContext(() -> {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 93 additions & 202 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
*/
66
package com.oracle.graal.python.builtins.modules;
77

8+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
9+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
10+
11+
import java.util.List;
12+
813
import com.oracle.graal.python.builtins.Builtin;
914
import com.oracle.graal.python.builtins.CoreFunctions;
1015
import com.oracle.graal.python.builtins.PythonBuiltins;
1116
import com.oracle.graal.python.builtins.objects.PNone;
1217
import com.oracle.graal.python.builtins.objects.complex.ComplexBuiltins;
1318
import com.oracle.graal.python.builtins.objects.complex.PComplex;
14-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
1519
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
20+
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
1621
import com.oracle.graal.python.nodes.ErrorMessages;
1722
import com.oracle.graal.python.nodes.PGuards;
1823
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -32,12 +37,6 @@
3237
import com.oracle.truffle.api.dsl.Specialization;
3338
import com.oracle.truffle.api.dsl.TypeSystemReference;
3439
import com.oracle.truffle.api.frame.VirtualFrame;
35-
import com.oracle.truffle.api.library.CachedLibrary;
36-
37-
import java.util.List;
38-
39-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
40-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
4140

4241
@CoreFunctions(defineModule = "cmath")
4342
public class CmathModuleBuiltins extends PythonBuiltins {
@@ -338,11 +337,11 @@ PComplex doDD(double r, double phi) {
338337
return rect(r, phi);
339338
}
340339

341-
@Specialization(limit = "2")
342-
PComplex doGeneral(Object r, Object phi,
343-
@CachedLibrary("r") PythonObjectLibrary rLib,
344-
@CachedLibrary("phi") PythonObjectLibrary phiLib) {
345-
return rect(rLib.asJavaDouble(r), phiLib.asJavaDouble(phi));
340+
@Specialization
341+
PComplex doGeneral(VirtualFrame frame, Object r, Object phi,
342+
@Cached PyFloatAsDoubleNode rAsDoubleNode,
343+
@Cached PyFloatAsDoubleNode phiAsDoubleNode) {
344+
return rect(rAsDoubleNode.execute(frame, r), phiAsDoubleNode.execute(frame, phi));
346345
}
347346

348347
@TruffleBoundary
@@ -1015,16 +1014,16 @@ boolean doCCNN(PComplex a, PComplex b, PNone relTolObj, PNone absTolObj) {
10151014
return isClose(a, b, DEFAULT_REL_TOL, DEFAULT_ABS_TOL);
10161015
}
10171016

1018-
@Specialization(limit = "2")
1017+
@Specialization
10191018
boolean doGeneral(VirtualFrame frame, Object aObj, Object bObj, Object relTolObj, Object absTolObj,
10201019
@Cached CoerceToComplexNode coerceAToComplex,
10211020
@Cached CoerceToComplexNode coerceBToComplex,
1022-
@CachedLibrary("relTolObj") PythonObjectLibrary relTolLib,
1023-
@CachedLibrary("absTolObj") PythonObjectLibrary absTolLib) {
1021+
@Cached PyFloatAsDoubleNode relAsDoubleNode,
1022+
@Cached PyFloatAsDoubleNode absAsDoubleNode) {
10241023
PComplex a = coerceAToComplex.execute(frame, aObj);
10251024
PComplex b = coerceBToComplex.execute(frame, bObj);
1026-
double relTol = PGuards.isNoValue(relTolObj) ? DEFAULT_REL_TOL : relTolLib.asJavaDouble(relTolObj);
1027-
double absTol = PGuards.isPNone(absTolObj) ? DEFAULT_ABS_TOL : absTolLib.asJavaDouble(absTolObj);
1025+
double relTol = PGuards.isNoValue(relTolObj) ? DEFAULT_REL_TOL : relAsDoubleNode.execute(frame, relTolObj);
1026+
double absTol = PGuards.isPNone(absTolObj) ? DEFAULT_ABS_TOL : absAsDoubleNode.execute(frame, absTolObj);
10281027
return isClose(a, b, relTol, absTol);
10291028
}
10301029

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/LocaleModuleBuiltins.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
import com.oracle.graal.python.builtins.PythonBuiltins;
5555
import com.oracle.graal.python.builtins.objects.PNone;
5656
import com.oracle.graal.python.builtins.objects.dict.PDict;
57-
import com.oracle.graal.python.builtins.objects.function.PArguments;
58-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
57+
import com.oracle.graal.python.lib.PyLongAsLongNode;
5958
import com.oracle.graal.python.nodes.ErrorMessages;
6059
import com.oracle.graal.python.nodes.PGuards;
6160
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -69,7 +68,6 @@
6968
import com.oracle.truffle.api.dsl.NodeFactory;
7069
import com.oracle.truffle.api.dsl.Specialization;
7170
import com.oracle.truffle.api.frame.VirtualFrame;
72-
import com.oracle.truffle.api.library.CachedLibrary;
7371

7472
@CoreFunctions(defineModule = "_locale")
7573
public class LocaleModuleBuiltins extends PythonBuiltins {
@@ -309,12 +307,11 @@ Object doWithLocaleID(int category, String posixLocaleID) {
309307
return toPosix(newLocale);
310308
}
311309

312-
@Specialization(replaces = {"doWithoutLocaleID", "doWithLocaleID"}, limit = "3")
310+
@Specialization(replaces = {"doWithoutLocaleID", "doWithLocaleID"})
313311
Object doGeneric(VirtualFrame frame, Object category, Object posixLocaleID,
314-
@CachedLibrary("category") PythonObjectLibrary categoryLib,
312+
@Cached PyLongAsLongNode asLongNode,
315313
@Cached CastToJavaStringNode castToJavaStringNode) {
316-
317-
long l = categoryLib.asJavaLongWithState(category, PArguments.getThreadState(frame));
314+
long l = asLongNode.execute(frame, category);
318315
if (!isValidCategory(l)) {
319316
throw raise(PythonErrorType.ValueError, ErrorMessages.INVALID_LOCALE_CATEGORY);
320317
}

0 commit comments

Comments
 (0)