6161import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ObjectUpcallNodeGen ;
6262import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ToJavaNodeGen ;
6363import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ToSulongNodeGen ;
64- import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .BoolNativeWrapper ;
65- import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .ByteNativeWrapper ;
66- import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .DoubleNativeWrapper ;
6764import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .DynamicObjectNativeWrapper ;
68- import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .IntNativeWrapper ;
69- import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .LongNativeWrapper ;
7065import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PrimitiveNativeWrapper ;
7166import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonClassNativeWrapper ;
7267import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonNativeWrapper ;
@@ -282,25 +277,25 @@ Object doBoolean(boolean b,
282277 PInt boxed = factory ().createInt (b );
283278 DynamicObjectNativeWrapper nativeWrapper = boxed .getNativeWrapper ();
284279 if (profile .profile (nativeWrapper == null )) {
285- nativeWrapper = BoolNativeWrapper . create (b );
280+ nativeWrapper = PrimitiveNativeWrapper . createBool (b );
286281 boxed .setNativeWrapper (nativeWrapper );
287282 }
288283 return nativeWrapper ;
289284 }
290285
291286 @ Specialization
292287 Object doInteger (int i ) {
293- return IntNativeWrapper . create (i );
288+ return PrimitiveNativeWrapper . createInt (i );
294289 }
295290
296291 @ Specialization
297292 Object doLong (long l ) {
298- return LongNativeWrapper . create (l );
293+ return PrimitiveNativeWrapper . createLong (l );
299294 }
300295
301296 @ Specialization
302297 Object doDouble (double d ) {
303- return DoubleNativeWrapper . create (d );
298+ return PrimitiveNativeWrapper . createDouble (d );
304299 }
305300
306301 @ Specialization
@@ -383,32 +378,32 @@ public abstract static class AsPythonObjectNode extends CExtBaseNode {
383378
384379 public abstract Object execute (Object value );
385380
386- @ Specialization
387- boolean doBoolNativeWrapper (BoolNativeWrapper object ) {
388- return object .getValue ();
381+ @ Specialization ( guards = "object.isBool()" )
382+ boolean doBoolNativeWrapper (PrimitiveNativeWrapper object ) {
383+ return object .getBool ();
389384 }
390385
391- @ Specialization (guards = " !isNative(object)" )
392- byte doByteNativeWrapper (ByteNativeWrapper object ) {
393- return object .getValue ();
386+ @ Specialization (guards = { "object.isByte()" , " !isNative(object)"} )
387+ byte doByteNativeWrapper (PrimitiveNativeWrapper object ) {
388+ return object .getByte ();
394389 }
395390
396- @ Specialization (guards = " !isNative(object)" )
397- int doIntNativeWrapper (IntNativeWrapper object ) {
398- return object .getValue ();
391+ @ Specialization (guards = { "object.isInt()" , " !isNative(object)"} )
392+ int doIntNativeWrapper (PrimitiveNativeWrapper object ) {
393+ return object .getInt ();
399394 }
400395
401- @ Specialization (guards = " !isNative(object)" )
402- long doLongNativeWrapper (LongNativeWrapper object ) {
403- return object .getValue ();
396+ @ Specialization (guards = { "object.isLong()" , " !isNative(object)"} )
397+ long doLongNativeWrapper (PrimitiveNativeWrapper object ) {
398+ return object .getLong ();
404399 }
405400
406- @ Specialization (guards = " !isNative(object)" )
407- double doDoubleNativeWrapper (DoubleNativeWrapper object ) {
408- return object .getValue ();
401+ @ Specialization (guards = { "object.isDouble()" , " !isNative(object)"} )
402+ double doDoubleNativeWrapper (PrimitiveNativeWrapper object ) {
403+ return object .getDouble ();
409404 }
410405
411- @ Specialization (guards = {"!isBoolNativeWrapper( object)" , "isNative(object)" })
406+ @ Specialization (guards = {"!object.isBool( )" , "isNative(object)" })
412407 Object doPrimitiveNativeWrapper (PrimitiveNativeWrapper object ) {
413408 return getMaterializeNode ().execute (object );
414409 }
@@ -482,10 +477,6 @@ protected static boolean isPrimitiveNativeWrapper(PythonNativeWrapper object) {
482477 return object instanceof PrimitiveNativeWrapper ;
483478 }
484479
485- protected static boolean isBoolNativeWrapper (PythonNativeWrapper object ) {
486- return object instanceof BoolNativeWrapper ;
487- }
488-
489480 protected boolean isForeignObject (TruffleObject obj , GetLazyClassNode getClassNode , IsBuiltinClassProfile isForeignClassProfile ) {
490481 return isForeignClassProfile .profileClass (getClassNode .execute (obj ), PythonBuiltinClassType .TruffleObject );
491482 }
@@ -520,9 +511,9 @@ public abstract static class MaterializeDelegateNode extends CExtBaseNode {
520511
521512 public abstract Object execute (PythonNativeWrapper object );
522513
523- @ Specialization (guards = "!isMaterialized(object)" )
524- PInt doBoolNativeWrapper (BoolNativeWrapper object ) {
525- PInt materializedInt = factory ().createInt (object .getValue ());
514+ @ Specialization (guards = { "!isMaterialized(object)" , "object.isBool()" } )
515+ PInt doBoolNativeWrapper (PrimitiveNativeWrapper object ) {
516+ PInt materializedInt = factory ().createInt (object .getBool ());
526517 object .setMaterializedObject (materializedInt );
527518 if (materializedInt .getNativeWrapper () != null ) {
528519 object .setNativePointer (materializedInt .getNativeWrapper ().getNativePointer ());
@@ -532,33 +523,33 @@ PInt doBoolNativeWrapper(BoolNativeWrapper object) {
532523 return materializedInt ;
533524 }
534525
535- @ Specialization (guards = "!isMaterialized(object)" )
536- PInt doByteNativeWrapper (ByteNativeWrapper object ) {
537- PInt materializedInt = factory ().createInt (object .getValue ());
526+ @ Specialization (guards = { "!isMaterialized(object)" , "object.isByte()" } )
527+ PInt doByteNativeWrapper (PrimitiveNativeWrapper object ) {
528+ PInt materializedInt = factory ().createInt (object .getByte ());
538529 object .setMaterializedObject (materializedInt );
539530 materializedInt .setNativeWrapper (object );
540531 return materializedInt ;
541532 }
542533
543- @ Specialization (guards = "!isMaterialized(object)" )
544- PInt doIntNativeWrapper (IntNativeWrapper object ) {
545- PInt materializedInt = factory ().createInt (object .getValue ());
534+ @ Specialization (guards = { "!isMaterialized(object)" , "object.isInt()" } )
535+ PInt doIntNativeWrapper (PrimitiveNativeWrapper object ) {
536+ PInt materializedInt = factory ().createInt (object .getInt ());
546537 object .setMaterializedObject (materializedInt );
547538 materializedInt .setNativeWrapper (object );
548539 return materializedInt ;
549540 }
550541
551- @ Specialization (guards = "!isMaterialized(object)" )
552- PInt doLongNativeWrapper (LongNativeWrapper object ) {
553- PInt materializedInt = factory ().createInt (object .getValue ());
542+ @ Specialization (guards = { "!isMaterialized(object)" , "object.isLong()" } )
543+ PInt doLongNativeWrapper (PrimitiveNativeWrapper object ) {
544+ PInt materializedInt = factory ().createInt (object .getLong ());
554545 object .setMaterializedObject (materializedInt );
555546 materializedInt .setNativeWrapper (object );
556547 return materializedInt ;
557548 }
558549
559- @ Specialization (guards = "!isMaterialized(object)" )
560- PFloat doDoubleNativeWrapper (DoubleNativeWrapper object ) {
561- PFloat materializedInt = factory ().createFloat (object .getValue ());
550+ @ Specialization (guards = { "!isMaterialized(object)" , "object.isDouble()" } )
551+ PFloat doDoubleNativeWrapper (PrimitiveNativeWrapper object ) {
552+ PFloat materializedInt = factory ().createFloat (object .getDouble ());
562553 object .setMaterializedObject (materializedInt );
563554 materializedInt .setNativeWrapper (object );
564555 return materializedInt ;
@@ -1158,29 +1149,14 @@ public static AsDouble create() {
11581149 return value .getValue ();
11591150 }
11601151
1161- @ Specialization
1162- double doBoolNativeWrapper (BoolNativeWrapper object ) {
1163- return PInt .intValue (object .getValue ());
1164- }
1165-
1166- @ Specialization
1167- double doByteNativeWrapper (ByteNativeWrapper object ) {
1168- return object .getValue ();
1169- }
1170-
1171- @ Specialization
1172- double doIntNativeWrapper (IntNativeWrapper object ) {
1173- return object .getValue ();
1174- }
1175-
1176- @ Specialization
1177- double doLongNativeWrapper (LongNativeWrapper object ) {
1178- return object .getValue ();
1152+ @ Specialization (guards = "!object.isDouble()" )
1153+ double doLongNativeWrapper (PrimitiveNativeWrapper object ) {
1154+ return object .getLong ();
11791155 }
11801156
1181- @ Specialization
1182- double doDoubleNativeWrapper (DoubleNativeWrapper object ) {
1183- return object .getValue ();
1157+ @ Specialization ( guards = "object.isDouble()" )
1158+ double doDoubleNativeWrapper (PrimitiveNativeWrapper object ) {
1159+ return object .getDouble ();
11841160 }
11851161
11861162 // TODO: this should just use the builtin constructor node so we don't duplicate the corner
@@ -1246,24 +1222,14 @@ long run(PFloat value) {
12461222 return (long ) value .getValue ();
12471223 }
12481224
1249- @ Specialization
1250- long doBoolNativeWrapper ( BoolNativeWrapper object ) {
1251- return PInt . intValue ( object .getValue () );
1225+ @ Specialization ( guards = "!object.isDouble()" )
1226+ long doLongNativeWrapper ( PrimitiveNativeWrapper object ) {
1227+ return object .getLong ( );
12521228 }
12531229
1254- @ Specialization
1255- long doByteNativeWrapper (ByteNativeWrapper object ) {
1256- return object .getValue ();
1257- }
1258-
1259- @ Specialization
1260- long doIntNativeWrapper (IntNativeWrapper object ) {
1261- return object .getValue ();
1262- }
1263-
1264- @ Specialization
1265- long doLongNativeWrapper (LongNativeWrapper object ) {
1266- return object .getValue ();
1230+ @ Specialization (guards = "object.isDouble()" )
1231+ long doDoubleNativeWrapper (PrimitiveNativeWrapper object ) {
1232+ return (long ) object .getDouble ();
12671233 }
12681234
12691235 @ Specialization
0 commit comments