File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 85
85
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyGetAttr ;
86
86
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyGetItem ;
87
87
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyHasAttr ;
88
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyIsNumber ;
88
89
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyIsTrue ;
89
90
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyListAppend ;
90
91
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyContextFunctions .GraalHPyListNew ;
@@ -246,7 +247,8 @@ enum HPyContextMembers {
246
247
CTX_BYTES ("ctx_Bytes" ),
247
248
CTX_RICHCOMPARE ("ctx_RichCompare" ),
248
249
CTX_RICHCOMPAREBOOL ("ctx_RichCompareBool" ),
249
- CTX_HASH ("ctx_Hash" );
250
+ CTX_HASH ("ctx_Hash" ),
251
+ CTX_NUMBER_CHECK ("ctx_Number_Check" );
250
252
251
253
private final String name ;
252
254
@@ -534,6 +536,7 @@ private static Object[] createMembers(PythonContext context) {
534
536
members [HPyContextMembers .CTX_RICHCOMPARE .ordinal ()] = new GraalHPyRichcompare (false );
535
537
members [HPyContextMembers .CTX_RICHCOMPAREBOOL .ordinal ()] = new GraalHPyRichcompare (true );
536
538
members [HPyContextMembers .CTX_HASH .ordinal ()] = new GraalHPyCallBuiltinFunction (BuiltinNames .HASH , 1 , GraalHPyConversionNodeSupplier .TO_INT64 );
539
+ members [HPyContextMembers .CTX_NUMBER_CHECK .ordinal ()] = new GraalHPyIsNumber ();
537
540
return members ;
538
541
}
539
542
Original file line number Diff line number Diff line change @@ -1588,4 +1588,28 @@ Object execute(Object[] arguments,
1588
1588
}
1589
1589
}
1590
1590
}
1591
+
1592
+ @ ExportLibrary (InteropLibrary .class )
1593
+ public static final class GraalHPyIsNumber extends GraalHPyContextFunction {
1594
+
1595
+ @ ExportMessage
1596
+ Object execute (Object [] arguments ,
1597
+ @ Cached HPyAsContextNode asContextNode ,
1598
+ @ Cached HPyAsPythonObjectNode asPythonObjectNode ,
1599
+ @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
1600
+ @ Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode ) throws ArityException {
1601
+ if (arguments .length != 2 ) {
1602
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1603
+ throw ArityException .create (2 , arguments .length );
1604
+ }
1605
+ GraalHPyContext nativeContext = asContextNode .execute (arguments [0 ]);
1606
+ Object receiver = asPythonObjectNode .execute (nativeContext , arguments [1 ]);
1607
+ try {
1608
+ return lib .canBePInt (receiver ) || lib .canBeJavaDouble (receiver );
1609
+ } catch (PException e ) {
1610
+ transformExceptionToNativeNode .execute (nativeContext , e );
1611
+ return nativeContext .getNullHandle ();
1612
+ }
1613
+ }
1614
+ }
1591
1615
}
You can’t perform that action at this time.
0 commit comments