MCPcopy Create free account
hub / github.com/Nuitka/Nuitka / generateMakeGeneratorObjectCode

Function generateMakeGeneratorObjectCode

nuitka/code_generation/GeneratorCodes.py:155–202  ·  view source on GitHub ↗
(to_name, expression, emit, context)

Source from the content-addressed store, hash-verified

153
154
155def generateMakeGeneratorObjectCode(to_name, expression, emit, context):
156 generator_object_body = expression.subnode_generator_ref.getFunctionBody()
157
158 closure_variables = expression.getClosureVariableVersions()
159
160 closure_name, closure_copy = getClosureCopyCode(
161 closure_variables=closure_variables, context=context
162 )
163
164 args = ["tstate"]
165 if closure_name:
166 args.append(closure_name)
167
168 # Special case empty generators.
169 if generator_object_body.subnode_body is None:
170 emit(
171 template_make_empty_generator
172 % {
173 "closure_copy": indented(closure_copy),
174 "to_name": to_name,
175 "generator_module": getModuleAccessCode(context),
176 "generator_name_obj": context.getConstantCode(
177 constant=generator_object_body.getFunctionName()
178 ),
179 "generator_qualname_obj": getFunctionQualnameObj(
180 generator_object_body, context
181 ),
182 "code_identifier": context.getCodeObjectHandle(
183 code_object=generator_object_body.getCodeObject()
184 ),
185 "closure_name": closure_name if closure_name is not None else "NULL",
186 "closure_count": len(closure_variables),
187 }
188 )
189 else:
190 emit(
191 template_make_generator
192 % {
193 "generator_maker_identifier": _getGeneratorMakerIdentifier(
194 generator_object_body.getCodeName()
195 ),
196 "to_name": to_name,
197 "args": ", ".join(str(arg) for arg in args),
198 "closure_copy": indented(closure_copy),
199 }
200 )
201
202 context.addCleanupTempName(to_name)
203
204
205# Part of "Nuitka", an optimizing Python compiler that is compatible and

Callers

nothing calls this directly

Calls 15

getClosureCopyCodeFunction · 0.85
indentedFunction · 0.85
getModuleAccessCodeFunction · 0.85
getFunctionQualnameObjFunction · 0.85
lenFunction · 0.85
getFunctionBodyMethod · 0.80
emitFunction · 0.50
getConstantCodeMethod · 0.45
getFunctionNameMethod · 0.45
getCodeObjectHandleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…