73
73
import com .oracle .graal .python .builtins .objects .str .PString ;
74
74
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
75
75
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
76
- import com .oracle .graal .python .nodes .BuiltinNames ;
77
76
import com .oracle .graal .python .nodes .PBaseNode ;
78
77
import com .oracle .graal .python .nodes .PGuards ;
79
78
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
80
79
import com .oracle .graal .python .nodes .SpecialMethodNames ;
81
80
import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
82
81
import com .oracle .graal .python .nodes .attributes .LookupInheritedAttributeNode ;
82
+ import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
83
83
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
84
84
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
85
85
import com .oracle .graal .python .nodes .object .GetClassNode ;
104
104
import com .oracle .truffle .api .interop .TruffleObject ;
105
105
import com .oracle .truffle .api .interop .UnknownIdentifierException ;
106
106
import com .oracle .truffle .api .interop .UnsupportedMessageException ;
107
+ import com .oracle .truffle .api .interop .UnsupportedTypeException ;
107
108
import com .oracle .truffle .api .nodes .Node ;
108
109
import com .oracle .truffle .api .nodes .UnexpectedResultException ;
110
+ import com .oracle .truffle .api .profiles .ConditionProfile ;
109
111
import com .oracle .truffle .api .profiles .ValueProfile ;
110
112
111
113
@ MessageResolution (receiverType = PythonNativeWrapper .class )
@@ -428,6 +430,22 @@ Object doImFunc(PBuiltinMethod object, @SuppressWarnings("unused") String key) {
428
430
return getToSulongNode ().execute (object .getFunction ());
429
431
}
430
432
433
+ @ Specialization
434
+ Object doMemoryview (PMemoryView object , String key ,
435
+ @ Cached ("create()" ) ReadAttributeFromObjectNode readAttrNode ,
436
+ @ Cached ("createReadNode()" ) Node readNode ,
437
+ @ Cached ("createBinaryProfile()" ) ConditionProfile isNativeObject ) {
438
+ Object delegateObj = readAttrNode .execute (object , "__c_memoryview" );
439
+ if (isNativeObject .profile (delegateObj instanceof PythonNativeObject )) {
440
+ try {
441
+ return ForeignAccess .sendRead (readNode , (TruffleObject ) ((PythonNativeObject ) delegateObj ).object , key );
442
+ } catch (UnsupportedMessageException | UnknownIdentifierException e ) {
443
+ throw e .raise ();
444
+ }
445
+ }
446
+ throw new IllegalStateException ("delegate of memoryview object is not native" );
447
+ }
448
+
431
449
@ Fallback
432
450
Object doGeneric (Object object , String key ) {
433
451
// This is the preliminary generic case: There are native members we know that they
@@ -446,11 +464,6 @@ protected boolean eq(String expected, String actual) {
446
464
return expected .equals (actual );
447
465
}
448
466
449
- protected boolean isMemoryView (Object obj ) {
450
- // TODO
451
- return getClass (obj ).getName ().equals (BuiltinNames .MEMORYVIEW );
452
- }
453
-
454
467
public static ReadNativeMemberNode create () {
455
468
return ReadNativeMemberNodeGen .create ();
456
469
}
@@ -486,6 +499,10 @@ private PythonClass getClass(Object obj) {
486
499
}
487
500
return getClassNode .execute (obj );
488
501
}
502
+
503
+ protected Node createReadNode () {
504
+ return Message .READ .createNode ();
505
+ }
489
506
}
490
507
491
508
@ Resolve (message = "WRITE" )
@@ -554,6 +571,22 @@ Object doMdDef(PythonObject object, @SuppressWarnings("unused") String key, Obje
554
571
return value ;
555
572
}
556
573
574
+ @ Specialization
575
+ Object doMemoryview (PMemoryView object , String key , Object value ,
576
+ @ Cached ("create()" ) ReadAttributeFromObjectNode readAttrNode ,
577
+ @ Cached ("createWriteNode()" ) Node writeNode ,
578
+ @ Cached ("createBinaryProfile()" ) ConditionProfile isNativeObject ) {
579
+ Object delegateObj = readAttrNode .execute (object , "__c_memoryview" );
580
+ if (isNativeObject .profile (delegateObj instanceof PythonNativeObject )) {
581
+ try {
582
+ return ForeignAccess .sendWrite (writeNode , (TruffleObject ) ((PythonNativeObject ) delegateObj ).object , key , value );
583
+ } catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException e ) {
584
+ throw e .raise ();
585
+ }
586
+ }
587
+ throw new IllegalStateException ("delegate of memoryview object is not native" );
588
+ }
589
+
557
590
@ Fallback
558
591
Object doGeneric (Object object , String key , Object value ) {
559
592
// This is the preliminary generic case: There are native members we know that they
@@ -581,10 +614,13 @@ private HashingStorageNodes.SetItemNode getSetItemNode() {
581
614
return setItemNode ;
582
615
}
583
616
617
+ protected Node createWriteNode () {
618
+ return Message .WRITE .createNode ();
619
+ }
620
+
584
621
public static WriteNativeMemberNode create () {
585
622
return WriteNativeMemberNodeGen .create ();
586
623
}
587
-
588
624
}
589
625
590
626
@ Resolve (message = "EXECUTE" )
0 commit comments