34
34
import com .oracle .graal .python .builtins .objects .object .PythonObject ;
35
35
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
36
36
import com .oracle .graal .python .nodes .SpecialMethodNames ;
37
+ import com .oracle .graal .python .nodes .attributes .WriteAttributeToDynamicObjectNode ;
37
38
import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
38
39
import com .oracle .truffle .api .Assumption ;
39
40
import com .oracle .truffle .api .CompilerAsserts ;
@@ -49,8 +50,8 @@ public class PFunction extends PythonObject {
49
50
private static final Object [] EMPTY_DEFAULTS = new Object [0 ];
50
51
private final String name ;
51
52
private final String enclosingClassName ;
52
- private final Assumption codeStableAssumption = Truffle .getRuntime ().createAssumption ("function code unchanged for " + getQualifiedName () );
53
- private final Assumption defaultsStableAssumption = Truffle .getRuntime ().createAssumption ("function defaults unchanged " + getQualifiedName () );
53
+ private final Assumption codeStableAssumption = Truffle .getRuntime ().createAssumption ();
54
+ private final Assumption defaultsStableAssumption = Truffle .getRuntime ().createAssumption ();
54
55
private final PythonObject globals ;
55
56
private final PCell [] closure ;
56
57
private final boolean isStatic ;
@@ -64,6 +65,11 @@ public PFunction(LazyPythonClass clazz, String name, String enclosingClassName,
64
65
65
66
public PFunction (LazyPythonClass clazz , String name , String enclosingClassName , RootCallTarget callTarget , PythonObject globals , Object [] defaultValues , PKeyword [] kwDefaultValues ,
66
67
PCell [] closure ) {
68
+ this (clazz , name , enclosingClassName , callTarget , globals , defaultValues , kwDefaultValues , closure , null );
69
+ }
70
+
71
+ public PFunction (LazyPythonClass clazz , String name , String enclosingClassName , RootCallTarget callTarget , PythonObject globals , Object [] defaultValues , PKeyword [] kwDefaultValues ,
72
+ PCell [] closure , WriteAttributeToDynamicObjectNode writeAttrNode ) {
67
73
super (clazz );
68
74
this .name = name ;
69
75
this .code = new PCode (PythonBuiltinClassType .PCode , callTarget );
@@ -73,13 +79,17 @@ public PFunction(LazyPythonClass clazz, String name, String enclosingClassName,
73
79
this .defaultValues = defaultValues == null ? EMPTY_DEFAULTS : defaultValues ;
74
80
this .kwDefaultValues = kwDefaultValues == null ? PKeyword .EMPTY_KEYWORDS : kwDefaultValues ;
75
81
this .closure = closure ;
76
- addDefaultConstants (this . getStorage (), name , enclosingClassName );
82
+ addDefaultConstants (writeAttrNode , getStorage (), name , enclosingClassName );
77
83
}
78
84
79
- @ TruffleBoundary
80
- private static void addDefaultConstants (DynamicObject storage , String name , String enclosingClassName ) {
81
- storage .define (__NAME__ , name );
82
- storage .define (__QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
85
+ private static void addDefaultConstants (WriteAttributeToDynamicObjectNode writeAttrNode , DynamicObject storage , String name , String enclosingClassName ) {
86
+ if (writeAttrNode != null ) {
87
+ writeAttrNode .execute (storage , __NAME__ , name );
88
+ writeAttrNode .execute (storage , __QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
89
+ } else {
90
+ storage .define (__NAME__ , name );
91
+ storage .define (__QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
92
+ }
83
93
}
84
94
85
95
public boolean isStatic () {
0 commit comments