32
32
import com .oracle .graal .python .builtins .CoreFunctions ;
33
33
import com .oracle .graal .python .builtins .PythonBuiltins ;
34
34
import com .oracle .graal .python .builtins .objects .PNone ;
35
- import com .oracle .graal .python .nodes .ModuleRootNode ;
36
- import com .oracle .graal .python .nodes .function .FunctionRootNode ;
35
+ import com .oracle .graal .python .builtins .objects .PNotImplemented ;
37
36
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
38
37
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
39
- import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
40
38
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
41
39
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
42
40
import com .oracle .truffle .api .dsl .NodeFactory ;
43
41
import com .oracle .truffle .api .dsl .Specialization ;
44
- import com .oracle .truffle .api .nodes .RootNode ;
45
- import com .oracle .truffle .api .source .SourceSection ;
46
42
47
43
@ CoreFunctions (extendClasses = PCode .class )
48
44
public class CodeBuiltins extends PythonBuiltins {
@@ -54,96 +50,153 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
54
50
55
51
@ Builtin (name = "co_freevars" , fixedNumOfArguments = 1 , isGetter = true )
56
52
@ GenerateNodeFactory
57
- public abstract static class FreeVarsNode extends PythonBuiltinNode {
53
+ public abstract static class GetFreeVarsNode extends PythonBuiltinNode {
58
54
@ Specialization
59
- protected Object doIt (PCode self ) {
60
- RootNode rootNode = self .getRootNode ();
61
- if (rootNode instanceof FunctionRootNode ) {
62
- return factory ().createTuple (((FunctionRootNode ) rootNode ).getFreeVars ());
63
- } else if (rootNode instanceof GeneratorFunctionRootNode ) {
64
- return factory ().createTuple (((GeneratorFunctionRootNode ) rootNode ).getFreeVars ());
65
- } else {
66
- return PNone .NONE ;
55
+ protected Object get (PCode self ) {
56
+ Object [] freeVars = self .getFreeVars ();
57
+ if (freeVars != null ) {
58
+ return factory ().createTuple (freeVars );
67
59
}
60
+ return PNone .NONE ;
68
61
}
69
62
}
70
63
71
64
@ Builtin (name = "co_cellvars" , fixedNumOfArguments = 1 , isGetter = true )
72
65
@ GenerateNodeFactory
73
- public abstract static class CellVarsNode extends PythonBuiltinNode {
66
+ public abstract static class GetCellVarsNode extends PythonBuiltinNode {
74
67
@ Specialization
75
- protected Object doIt (PCode self ) {
76
- RootNode rootNode = self .getRootNode ();
77
- if (rootNode instanceof FunctionRootNode ) {
78
- return factory ().createTuple (((FunctionRootNode ) rootNode ).getCellVars ());
79
- } else if (rootNode instanceof GeneratorFunctionRootNode ) {
80
- return factory ().createTuple (((GeneratorFunctionRootNode ) rootNode ).getCellVars ());
81
- } else {
82
- return PNone .NONE ;
68
+ protected Object get (PCode self ) {
69
+ Object [] cellVars = self .getCellVars ();
70
+ if (cellVars != null ) {
71
+ return factory ().createTuple (cellVars );
83
72
}
73
+ return PNone .NONE ;
84
74
}
85
75
}
86
76
87
77
@ Builtin (name = "co_filename" , fixedNumOfArguments = 1 , isGetter = true )
88
78
@ GenerateNodeFactory
89
- public abstract static class FilenameNode extends PythonBuiltinNode {
79
+ public abstract static class GetFilenameNode extends PythonBuiltinNode {
90
80
@ Specialization
91
- protected Object doIt (PCode self ) {
92
- RootNode rootNode = self .getRootNode ();
93
- if (rootNode == null ) {
94
- return self .getFilename ();
95
- }
96
- SourceSection src = rootNode .getSourceSection ();
97
- if (src != null ) {
98
- return src .getSource ().getName ();
99
- } else if (rootNode instanceof ModuleRootNode ) {
100
- return ((ModuleRootNode ) rootNode ).getName ();
101
- } else {
102
- return PNone .NONE ;
81
+ protected Object get (PCode self ) {
82
+ String filename = self .getFilename ();
83
+ if (filename != null ) {
84
+ return filename ;
103
85
}
86
+ return PNone .NONE ;
104
87
}
105
88
}
106
89
107
90
@ Builtin (name = "co_firstlineno" , fixedNumOfArguments = 1 , isGetter = true )
108
91
@ GenerateNodeFactory
109
- public abstract static class LinenoNode extends PythonBuiltinNode {
92
+ public abstract static class GetLinenoNode extends PythonBuiltinNode {
110
93
@ Specialization
111
- @ TruffleBoundary
112
- protected Object doIt (PCode self ) {
113
- RootNode rootNode = self .getRootNode ();
114
- if (rootNode == null ) {
115
- return self .getFirstLineNo ();
116
- }
117
- SourceSection sourceSection = rootNode .getSourceSection ();
118
- if (sourceSection == null ) {
119
- return 1 ;
120
- } else {
121
- return sourceSection .getStartLine ();
122
- }
94
+ protected Object get (PCode self ) {
95
+ return self .getFirstLineNo ();
123
96
}
124
97
}
125
98
126
99
@ Builtin (name = "co_name" , fixedNumOfArguments = 1 , isGetter = true )
127
100
@ GenerateNodeFactory
128
- public abstract static class NameNode extends PythonBuiltinNode {
101
+ public abstract static class GetNameNode extends PythonBuiltinNode {
129
102
@ Specialization
130
103
@ TruffleBoundary
131
- protected Object doIt (PCode self ) {
132
- RootNode rootNode = self .getRootNode ();
133
- String name ;
134
- if (rootNode instanceof ModuleRootNode ) {
135
- name = "<module>" ;
136
- } else if (rootNode instanceof FunctionRootNode ) {
137
- name = ((FunctionRootNode ) rootNode ).getFunctionName ();
138
- } else if (rootNode == null ) {
139
- name = self .getName ();
140
- } else {
141
- name = rootNode .getName ();
142
- }
104
+ protected Object get (PCode self ) {
105
+ String name = self .getName ();
143
106
if (name != null ) {
144
107
return name ;
145
108
}
146
109
return PNone .NONE ;
147
110
}
148
111
}
112
+
113
+ @ Builtin (name = "co_argcount" , fixedNumOfArguments = 1 , isGetter = true )
114
+ @ GenerateNodeFactory
115
+ public abstract static class GetArgCountNode extends PythonBuiltinNode {
116
+ @ Specialization
117
+ protected Object get (PCode self ) {
118
+ return PNotImplemented .NOT_IMPLEMENTED ;
119
+ }
120
+ }
121
+
122
+ @ Builtin (name = "co_kwonlyargcount" , fixedNumOfArguments = 1 , isGetter = true )
123
+ @ GenerateNodeFactory
124
+ public abstract static class GetKnownlyArgCountNode extends PythonBuiltinNode {
125
+ @ Specialization
126
+ protected Object get (PCode self ) {
127
+ return PNotImplemented .NOT_IMPLEMENTED ;
128
+ }
129
+ }
130
+
131
+ @ Builtin (name = "co_nlocals" , fixedNumOfArguments = 1 , isGetter = true )
132
+ @ GenerateNodeFactory
133
+ public abstract static class GetNLocalsNode extends PythonBuiltinNode {
134
+ @ Specialization
135
+ protected Object get (PCode self ) {
136
+ return PNotImplemented .NOT_IMPLEMENTED ;
137
+ }
138
+ }
139
+
140
+ @ Builtin (name = "co_stacksize" , fixedNumOfArguments = 1 , isGetter = true )
141
+ @ GenerateNodeFactory
142
+ public abstract static class GetStackSizeNode extends PythonBuiltinNode {
143
+ @ Specialization
144
+ protected Object get (PCode self ) {
145
+ return PNotImplemented .NOT_IMPLEMENTED ;
146
+ }
147
+ }
148
+
149
+ @ Builtin (name = "co_flags" , fixedNumOfArguments = 1 , isGetter = true )
150
+ @ GenerateNodeFactory
151
+ public abstract static class GetFlagsNode extends PythonBuiltinNode {
152
+ @ Specialization
153
+ protected Object get (PCode self ) {
154
+ return PNotImplemented .NOT_IMPLEMENTED ;
155
+ }
156
+ }
157
+
158
+ @ Builtin (name = "co_code" , fixedNumOfArguments = 1 , isGetter = true )
159
+ @ GenerateNodeFactory
160
+ public abstract static class GetCodeNode extends PythonBuiltinNode {
161
+ @ Specialization
162
+ protected Object get (PCode self ) {
163
+ return PNotImplemented .NOT_IMPLEMENTED ;
164
+ }
165
+ }
166
+
167
+ @ Builtin (name = "co_consts" , fixedNumOfArguments = 1 , isGetter = true )
168
+ @ GenerateNodeFactory
169
+ public abstract static class GetConstsNode extends PythonBuiltinNode {
170
+ @ Specialization
171
+ protected Object get (PCode self ) {
172
+ return PNotImplemented .NOT_IMPLEMENTED ;
173
+ }
174
+ }
175
+
176
+ @ Builtin (name = "co_names" , fixedNumOfArguments = 1 , isGetter = true )
177
+ @ GenerateNodeFactory
178
+ public abstract static class GetNamesNode extends PythonBuiltinNode {
179
+ @ Specialization
180
+ protected Object get (PCode self ) {
181
+ return PNotImplemented .NOT_IMPLEMENTED ;
182
+ }
183
+ }
184
+
185
+ @ Builtin (name = "co_varnames" , fixedNumOfArguments = 1 , isGetter = true )
186
+ @ GenerateNodeFactory
187
+ public abstract static class GetVarNamesNode extends PythonBuiltinNode {
188
+ @ Specialization
189
+ protected Object get (PCode self ) {
190
+ return PNotImplemented .NOT_IMPLEMENTED ;
191
+ }
192
+ }
193
+
194
+ @ Builtin (name = "co_lnotab" , fixedNumOfArguments = 1 , isGetter = true )
195
+ @ GenerateNodeFactory
196
+ public abstract static class GetLNoTabNode extends PythonBuiltinNode {
197
+ @ Specialization
198
+ protected Object get (PCode self ) {
199
+ return PNotImplemented .NOT_IMPLEMENTED ;
200
+ }
201
+ }
149
202
}
0 commit comments