Commits

Ronan Lamy  committed 84b08ae

Add property HostCode.is_generator

  • Participants
  • Parent commits e94ac64
  • Branches translation-cleanup

Comments (0)

Files changed (2)

File pypy/objspace/flow/bytecode.py

 from pypy.interpreter.pycode import PyCode, BytecodeCorruption
 from pypy.tool.stdlib_opcode import (host_bytecode_spec, EXTENDED_ARG,
         HAVE_ARGUMENT)
+from pypy.interpreter.astcompiler.consts import CO_GENERATOR
 
 class HostCode(PyCode):
     """
 
         opname = self.opnames[opcode]
         return next_instr, opname, oparg
+
+    @property
+    def is_generator(self):
+        return bool(self.co_flags & CO_GENERATOR)

File pypy/objspace/flow/flowcontext.py

 from pypy.interpreter.error import OperationError
 from pypy.interpreter import pyframe, nestedscope
 from pypy.interpreter.argument import ArgumentsForTranslation
-from pypy.interpreter.astcompiler.consts import CO_GENERATOR
 from pypy.interpreter.pyopcode import (Return, Yield, SuspendedUnroller,
         SReturnValue, BytecodeCorruption)
 from pypy.objspace.flow import operation
 class FlowSpaceFrame(pyframe.CPythonFrame):
 
     def __init__(self, space, code, func, constargs=None):
-        self.is_generator = bool(code.co_flags & CO_GENERATOR)
         w_globals = Constant(func.func_globals)
         class outerfunc: pass # hack
         if func.func_closure is not None:
             name = name.replace(c, '_')
 
         initialblock = SpamBlock(self.getstate())
-        if self.is_generator:
+        if self.pycode.is_generator:
             initialblock.operations.append(
                 SpaceOperation('generator_mark', [], Variable()))
         graph = FunctionGraph(name, initialblock)
         # itself
         graph.signature = self.pycode.signature()
         graph.defaults = func.func_defaults or ()
-        graph.is_generator = self.is_generator
+        graph.is_generator = self.pycode.is_generator
         return graph
 
     def getstate(self):
         return jumpto
 
     def YIELD_VALUE(self, _, next_instr):
-        assert self.is_generator
+        assert self.pycode.is_generator
         w_result = self.popvalue()
         self.space.do_operation('yield', w_result)
         # XXX yield expressions not supported. This will blow up if the value