43
43
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
44
44
import com .oracle .graal .python .builtins .objects .cext .CArrayWrappers .CStringWrapper ;
45
45
import com .oracle .graal .python .builtins .objects .common .DynamicObjectStorage .PythonObjectDictStorage ;
46
- import com .oracle .graal .python .builtins .objects .object .PythonObject ;
47
46
import com .oracle .graal .python .builtins .objects .str .PString ;
48
47
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
49
48
import com .oracle .truffle .api .CompilerAsserts ;
@@ -58,9 +57,23 @@ public abstract class NativeWrappers {
58
57
59
58
public abstract static class PythonNativeWrapper implements TruffleObject {
60
59
60
+ private Object delegate ;
61
61
private Object nativePointer ;
62
62
63
- public abstract Object getDelegate ();
63
+ public PythonNativeWrapper () {
64
+ }
65
+
66
+ public PythonNativeWrapper (Object delegate ) {
67
+ this .delegate = delegate ;
68
+ }
69
+
70
+ public Object getDelegate () {
71
+ return delegate ;
72
+ }
73
+
74
+ protected void setDelegate (Object delegate ) {
75
+ this .delegate = delegate ;
76
+ }
64
77
65
78
public Object getNativePointer () {
66
79
return nativePointer ;
@@ -92,6 +105,13 @@ public abstract static class DynamicObjectNativeWrapper extends PythonNativeWrap
92
105
93
106
private PythonObjectDictStorage nativeMemberStore ;
94
107
108
+ public DynamicObjectNativeWrapper () {
109
+ }
110
+
111
+ public DynamicObjectNativeWrapper (Object delegate ) {
112
+ super (delegate );
113
+ }
114
+
95
115
public PythonObjectDictStorage createNativeMemberStore () {
96
116
if (nativeMemberStore == null ) {
97
117
nativeMemberStore = new PythonObjectDictStorage (SHAPE .newInstance ());
@@ -110,14 +130,12 @@ public PythonObjectDictStorage getNativeMemberStore() {
110
130
*/
111
131
public static class PythonObjectNativeWrapper extends DynamicObjectNativeWrapper {
112
132
113
- private final PythonAbstractObject pythonObject ;
114
-
115
133
public PythonObjectNativeWrapper (PythonAbstractObject object ) {
116
- this . pythonObject = object ;
134
+ super ( object ) ;
117
135
}
118
136
119
137
public PythonAbstractObject getPythonObject () {
120
- return pythonObject ;
138
+ return ( PythonAbstractObject ) getDelegate () ;
121
139
}
122
140
123
141
public static DynamicObjectNativeWrapper wrap (PythonAbstractObject obj , ConditionProfile noWrapperProfile ) {
@@ -130,38 +148,25 @@ public static DynamicObjectNativeWrapper wrap(PythonAbstractObject obj, Conditio
130
148
return nativeWrapper ;
131
149
}
132
150
133
- @ Override
134
- public Object getDelegate () {
135
- return pythonObject ;
136
- }
137
-
138
151
@ Override
139
152
public String toString () {
140
153
CompilerAsserts .neverPartOfCompilation ();
141
- return String .format ("PythonObjectNativeWrapper(%s, isNative=%s)" , pythonObject , isNative ());
154
+ return String .format ("PythonObjectNativeWrapper(%s, isNative=%s)" , getDelegate () , isNative ());
142
155
}
143
156
}
144
157
145
158
public abstract static class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
146
159
147
- private PythonObject materializedObject ;
148
-
149
160
protected abstract Object getBoxedValue ();
150
161
151
- @ Override
152
- public Object getDelegate () {
153
- if (materializedObject != null ) {
154
- return materializedObject ;
155
- }
156
- return getBoxedValue ();
162
+ // this method exists just for readability
163
+ public Object getMaterializedObject () {
164
+ return getDelegate ();
157
165
}
158
166
159
- void setMaterializedObject (PythonObject materializedObject ) {
160
- this .materializedObject = materializedObject ;
161
- }
162
-
163
- PythonObject getMaterializedObject () {
164
- return materializedObject ;
167
+ // this method exists just for readability
168
+ public void setMaterializedObject (Object materializedPrimitive ) {
169
+ setDelegate (materializedPrimitive );
165
170
}
166
171
}
167
172
@@ -372,21 +377,14 @@ public String toString() {
372
377
*/
373
378
public static class PySequenceArrayWrapper extends PythonNativeWrapper {
374
379
375
- private final Object delegate ;
376
-
377
380
/** Number of bytes that constitute a single element. */
378
381
private final int elementAccessSize ;
379
382
380
383
public PySequenceArrayWrapper (Object delegate , int elementAccessSize ) {
381
- this . delegate = delegate ;
384
+ super ( delegate ) ;
382
385
this .elementAccessSize = elementAccessSize ;
383
386
}
384
387
385
- @ Override
386
- public Object getDelegate () {
387
- return delegate ;
388
- }
389
-
390
388
public int getElementAccessSize () {
391
389
return elementAccessSize ;
392
390
}
@@ -402,37 +400,26 @@ public ForeignAccess getForeignAccess() {
402
400
}
403
401
404
402
public static class TruffleObjectNativeWrapper extends PythonNativeWrapper {
405
- private final TruffleObject foreignObject ;
406
403
407
404
public TruffleObjectNativeWrapper (TruffleObject foreignObject ) {
408
- this .foreignObject = foreignObject ;
409
- }
410
-
411
- public TruffleObject getForeignObject () {
412
- return foreignObject ;
405
+ super (foreignObject );
413
406
}
414
407
415
408
public static TruffleObjectNativeWrapper wrap (TruffleObject foreignObject ) {
416
409
assert !(foreignObject instanceof PythonNativeWrapper ) : "attempting to wrap a native wrapper" ;
417
410
return new TruffleObjectNativeWrapper (foreignObject );
418
411
}
419
-
420
- @ Override
421
- public Object getDelegate () {
422
- return foreignObject ;
423
- }
424
412
}
425
413
426
414
abstract static class PyUnicodeWrapper extends PythonNativeWrapper {
427
- private final PString delegate ;
428
415
429
416
public PyUnicodeWrapper (PString delegate ) {
430
- this . delegate = delegate ;
417
+ super ( delegate ) ;
431
418
}
432
419
433
420
@ Override
434
421
public PString getDelegate () {
435
- return delegate ;
422
+ return ( PString ) super . getDelegate () ;
436
423
}
437
424
438
425
@ Override
@@ -452,7 +439,6 @@ public static class PyUnicodeData extends PyUnicodeWrapper {
452
439
public PyUnicodeData (PString delegate ) {
453
440
super (delegate );
454
441
}
455
-
456
442
}
457
443
458
444
/**
0 commit comments