61
61
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ObjectUpcallNodeGen ;
62
62
import com .oracle .graal .python .builtins .objects .cext .CExtNodesFactory .ToJavaNodeGen ;
63
63
import 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 ;
67
64
import 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 ;
70
65
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PrimitiveNativeWrapper ;
71
66
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonClassNativeWrapper ;
72
67
import com .oracle .graal .python .builtins .objects .cext .NativeWrappers .PythonNativeWrapper ;
@@ -282,25 +277,25 @@ Object doBoolean(boolean b,
282
277
PInt boxed = factory ().createInt (b );
283
278
DynamicObjectNativeWrapper nativeWrapper = boxed .getNativeWrapper ();
284
279
if (profile .profile (nativeWrapper == null )) {
285
- nativeWrapper = BoolNativeWrapper . create (b );
280
+ nativeWrapper = PrimitiveNativeWrapper . createBool (b );
286
281
boxed .setNativeWrapper (nativeWrapper );
287
282
}
288
283
return nativeWrapper ;
289
284
}
290
285
291
286
@ Specialization
292
287
Object doInteger (int i ) {
293
- return IntNativeWrapper . create (i );
288
+ return PrimitiveNativeWrapper . createInt (i );
294
289
}
295
290
296
291
@ Specialization
297
292
Object doLong (long l ) {
298
- return LongNativeWrapper . create (l );
293
+ return PrimitiveNativeWrapper . createLong (l );
299
294
}
300
295
301
296
@ Specialization
302
297
Object doDouble (double d ) {
303
- return DoubleNativeWrapper . create (d );
298
+ return PrimitiveNativeWrapper . createDouble (d );
304
299
}
305
300
306
301
@ Specialization
@@ -383,32 +378,32 @@ public abstract static class AsPythonObjectNode extends CExtBaseNode {
383
378
384
379
public abstract Object execute (Object value );
385
380
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 ();
389
384
}
390
385
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 ();
394
389
}
395
390
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 ();
399
394
}
400
395
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 ();
404
399
}
405
400
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 ();
409
404
}
410
405
411
- @ Specialization (guards = {"!isBoolNativeWrapper( object)" , "isNative(object)" })
406
+ @ Specialization (guards = {"!object.isBool( )" , "isNative(object)" })
412
407
Object doPrimitiveNativeWrapper (PrimitiveNativeWrapper object ) {
413
408
return getMaterializeNode ().execute (object );
414
409
}
@@ -482,10 +477,6 @@ protected static boolean isPrimitiveNativeWrapper(PythonNativeWrapper object) {
482
477
return object instanceof PrimitiveNativeWrapper ;
483
478
}
484
479
485
- protected static boolean isBoolNativeWrapper (PythonNativeWrapper object ) {
486
- return object instanceof BoolNativeWrapper ;
487
- }
488
-
489
480
protected boolean isForeignObject (TruffleObject obj , GetLazyClassNode getClassNode , IsBuiltinClassProfile isForeignClassProfile ) {
490
481
return isForeignClassProfile .profileClass (getClassNode .execute (obj ), PythonBuiltinClassType .TruffleObject );
491
482
}
@@ -520,9 +511,9 @@ public abstract static class MaterializeDelegateNode extends CExtBaseNode {
520
511
521
512
public abstract Object execute (PythonNativeWrapper object );
522
513
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 ());
526
517
object .setMaterializedObject (materializedInt );
527
518
if (materializedInt .getNativeWrapper () != null ) {
528
519
object .setNativePointer (materializedInt .getNativeWrapper ().getNativePointer ());
@@ -532,33 +523,33 @@ PInt doBoolNativeWrapper(BoolNativeWrapper object) {
532
523
return materializedInt ;
533
524
}
534
525
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 ());
538
529
object .setMaterializedObject (materializedInt );
539
530
materializedInt .setNativeWrapper (object );
540
531
return materializedInt ;
541
532
}
542
533
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 ());
546
537
object .setMaterializedObject (materializedInt );
547
538
materializedInt .setNativeWrapper (object );
548
539
return materializedInt ;
549
540
}
550
541
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 ());
554
545
object .setMaterializedObject (materializedInt );
555
546
materializedInt .setNativeWrapper (object );
556
547
return materializedInt ;
557
548
}
558
549
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 ());
562
553
object .setMaterializedObject (materializedInt );
563
554
materializedInt .setNativeWrapper (object );
564
555
return materializedInt ;
@@ -1158,29 +1149,14 @@ public static AsDouble create() {
1158
1149
return value .getValue ();
1159
1150
}
1160
1151
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 ();
1179
1155
}
1180
1156
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 ();
1184
1160
}
1185
1161
1186
1162
// TODO: this should just use the builtin constructor node so we don't duplicate the corner
@@ -1246,24 +1222,14 @@ long run(PFloat value) {
1246
1222
return (long ) value .getValue ();
1247
1223
}
1248
1224
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 ( );
1252
1228
}
1253
1229
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 ();
1267
1233
}
1268
1234
1269
1235
@ Specialization
0 commit comments