Skip to content

Commit e4d6980

Browse files
committed
MethodBuiltins: add __getattr__ and __func__ nodes
1 parent 2094f4c commit e4d6980

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_class-set-attrib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018,2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__CODE__;
3030
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DEFAULTS__;
31+
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DICT__;
3132
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__FUNC__;
3233
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__KWDEFAULTS__;
34+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
3335
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;
3436
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REDUCE__;
3537
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
@@ -43,6 +45,7 @@
4345
import com.oracle.graal.python.builtins.PythonBuiltins;
4446
import com.oracle.graal.python.builtins.objects.PNone;
4547
import com.oracle.graal.python.builtins.objects.function.PKeyword;
48+
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
4649
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
4750
import com.oracle.graal.python.nodes.SpecialAttributeNames;
4851
import com.oracle.graal.python.nodes.attributes.GetAttributeNode;
@@ -93,6 +96,26 @@ protected Object doIt(VirtualFrame frame, PMethod self,
9396
}
9497
}
9598

99+
@Builtin(name = __DICT__, minNumOfPositionalArgs = 1, isGetter = true)
100+
@GenerateNodeFactory
101+
public abstract static class DictNode extends PythonBuiltinNode {
102+
@Specialization
103+
protected Object doIt(VirtualFrame frame, PMethod self,
104+
@Cached("create(__GETATTRIBUTE__)") LookupAndCallBinaryNode getDict) {
105+
return getDict.executeObject(frame, self.getFunction(), __DICT__);
106+
}
107+
}
108+
109+
@Builtin(name = __GETATTR__, minNumOfPositionalArgs = 2)
110+
@GenerateNodeFactory
111+
public abstract static class GetattrNode extends PythonBuiltinNode {
112+
@Specialization
113+
protected Object doIt(VirtualFrame frame, PMethod self, Object key,
114+
@Cached("create()") ObjectBuiltins.GetAttributeNode objectGetattrNode) {
115+
return objectGetattrNode.execute(frame, self.getFunction(), key);
116+
}
117+
}
118+
96119
@Builtin(name = __REPR__, minNumOfPositionalArgs = 1)
97120
@GenerateNodeFactory
98121
public abstract static class ReprNode extends PythonUnaryBuiltinNode {

0 commit comments

Comments
 (0)