|
45 | 45 | import static com.oracle.graal.python.nodes.SpecialMethodNames.T___NEW__; |
46 | 46 | import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REDUCE__; |
47 | 47 | import static com.oracle.graal.python.nodes.SpecialMethodNames.T___REPR__; |
48 | | -import static com.oracle.graal.python.util.PythonUtils.EMPTY_TRUFFLESTRING_ARRAY; |
49 | 48 | import static com.oracle.graal.python.util.PythonUtils.toTruffleStringArrayUncached; |
50 | | -import static com.oracle.graal.python.util.PythonUtils.tsArray; |
51 | 49 | import static com.oracle.graal.python.util.PythonUtils.tsLiteral; |
52 | 50 |
|
53 | 51 | import java.util.ArrayList; |
54 | 52 | import java.util.List; |
55 | 53 | import java.util.Objects; |
56 | 54 |
|
57 | 55 | import com.oracle.graal.python.PythonLanguage; |
| 56 | +import com.oracle.graal.python.annotations.Builtin; |
58 | 57 | import com.oracle.graal.python.builtins.Python3Core; |
59 | 58 | import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
60 | 59 | import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; |
61 | 60 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
62 | | -import com.oracle.graal.python.builtins.objects.function.PArguments; |
63 | 61 | import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; |
64 | | -import com.oracle.graal.python.builtins.objects.function.Signature; |
| 62 | +import com.oracle.graal.python.builtins.objects.tuple.StructSequenceFactory.GetStructMemberNodeGen; |
65 | 63 | import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor; |
66 | 64 | import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass; |
67 | 65 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass; |
|
74 | 72 | import com.oracle.graal.python.nodes.ErrorMessages; |
75 | 73 | import com.oracle.graal.python.nodes.HiddenAttr; |
76 | 74 | import com.oracle.graal.python.nodes.PRaiseNode; |
77 | | -import com.oracle.graal.python.nodes.PRootNode; |
78 | 75 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode; |
79 | 76 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode; |
| 77 | +import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; |
| 78 | +import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode; |
80 | 79 | import com.oracle.graal.python.runtime.PythonContext; |
81 | 80 | import com.oracle.graal.python.runtime.object.PFactory; |
82 | 81 | import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage; |
| 82 | +import com.oracle.graal.python.util.PythonUtils.PrototypeNodeFactory; |
83 | 83 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
84 | | -import com.oracle.truffle.api.frame.VirtualFrame; |
| 84 | +import com.oracle.truffle.api.dsl.Specialization; |
85 | 85 | import com.oracle.truffle.api.strings.TruffleString; |
86 | 86 |
|
87 | 87 | /** |
@@ -228,47 +228,34 @@ private static void copyMethod(PythonLanguage language, PythonAbstractClass klas |
228 | 228 | } |
229 | 229 |
|
230 | 230 | private static void createMember(PythonLanguage language, Object klass, TruffleString name, TruffleString doc, int idx) { |
231 | | - GetStructMemberNode rootNode = language.createStructSeqIndexedMemberAccessCachedRootNode((l) -> new GetStructMemberNode(l, idx), idx); |
232 | | - PBuiltinFunction getter = PFactory.createBuiltinFunction(language, name, klass, 0, 0, rootNode); |
| 231 | + BuiltinFunctionRootNode rootNode = language.createStructSeqIndexedMemberAccessCachedRootNode( |
| 232 | + l -> new BuiltinFunctionRootNode(l, GetStructMemberNode.BUILTIN, new PrototypeNodeFactory<>(GetStructMemberNodeGen.create(idx)), true), idx); |
| 233 | + int flags = PBuiltinFunction.getFlags(GetStructMemberNode.BUILTIN, rootNode.getSignature()); |
| 234 | + PBuiltinFunction getter = PFactory.createBuiltinFunction(language, name, klass, 0, flags, rootNode); |
233 | 235 | GetSetDescriptor callable = PFactory.createGetSetDescriptor(language, getter, null, name, klass, false); |
234 | 236 | if (doc != null) { |
235 | 237 | callable.setAttribute(T___DOC__, doc); |
236 | 238 | } |
237 | 239 | WriteAttributeToObjectNode.getUncached().execute(klass, name, callable); |
238 | 240 | } |
239 | 241 |
|
240 | | - private static class GetStructMemberNode extends PRootNode { |
241 | | - public static final Signature SIGNATURE = new Signature(-1, false, -1, tsArray("$self"), EMPTY_TRUFFLESTRING_ARRAY); |
| 242 | + @Builtin(name = "structseq_get_member", minNumOfPositionalArgs = 1, parameterNames = "$self") |
| 243 | + abstract static class GetStructMemberNode extends PythonUnaryBuiltinNode { |
| 244 | + private static final Builtin BUILTIN = GetStructMemberNode.class.getAnnotation(Builtin.class); |
242 | 245 | private final int fieldIdx; |
243 | 246 |
|
244 | | - GetStructMemberNode(PythonLanguage language, int fieldIdx) { |
245 | | - super(language); |
| 247 | + GetStructMemberNode(int fieldIdx) { |
246 | 248 | this.fieldIdx = fieldIdx; |
247 | 249 | } |
248 | 250 |
|
249 | | - @Override |
250 | | - public Object execute(VirtualFrame frame) { |
251 | | - PTuple self = (PTuple) PArguments.getArgument(frame, 0); |
| 251 | + @Specialization |
| 252 | + Object getMember(PTuple self) { |
252 | 253 | if (self.getSequenceStorage() instanceof NativeSequenceStorage && fieldIdx >= self.getSequenceStorage().length()) { |
253 | 254 | throw PRaiseNode.raiseStatic(this, NotImplementedError, ErrorMessages.UNSUPPORTED_ACCESS_OF_STRUCT_SEQUENCE_NATIVE_STORAGE); |
254 | 255 | } |
255 | 256 | return SequenceStorageNodes.GetItemScalarNode.executeUncached(self.getSequenceStorage(), fieldIdx); |
256 | 257 | } |
257 | 258 |
|
258 | | - @Override |
259 | | - public Signature getSignature() { |
260 | | - return SIGNATURE; |
261 | | - } |
262 | | - |
263 | | - @Override |
264 | | - public boolean isInternal() { |
265 | | - return true; |
266 | | - } |
267 | | - |
268 | | - @Override |
269 | | - public boolean isPythonInternal() { |
270 | | - return true; |
271 | | - } |
272 | 259 | } |
273 | 260 |
|
274 | 261 | static TruffleString getTpName(Object cls) { |
|
0 commit comments