Esempio n. 1
0
    def _initialize(self):
        if self.co_cellvars:
            argcount = self.co_argcount
            assert argcount >= 0  # annotator hint
            if self.co_flags & CO_VARARGS:
                argcount += 1
            if self.co_flags & CO_VARKEYWORDS:
                argcount += 1
            # Cell vars could shadow already-set arguments.
            # The compiler used to be clever about the order of
            # the variables in both co_varnames and co_cellvars, but
            # it no longer is for the sake of simplicity.  Moreover
            # code objects loaded from CPython don't necessarily follow
            # an order, which could lead to strange bugs if .pyc files
            # produced by CPython are loaded by PyPy.  Note that CPython
            # contains the following bad-looking nested loops at *every*
            # function call!

            # Precompute what arguments need to be copied into cellvars
            args_as_cellvars = []
            argvars = self.co_varnames
            cellvars = self.co_cellvars
            for i in range(len(cellvars)):
                cellname = cellvars[i]
                for j in range(argcount):
                    if cellname == argvars[j]:
                        # argument j has the same name as the cell var i
                        while len(args_as_cellvars) <= i:
                            args_as_cellvars.append(-1)  # pad
                        args_as_cellvars[i] = j
            self._args_as_cellvars = args_as_cellvars[:]
        else:
            self._args_as_cellvars = []

        self._compute_flatcall()

        if self.space.config.objspace.std.withmapdict:
            from pypy.objspace.std.mapdict import init_mapdict_cache
            init_mapdict_cache(self)

        cui = self.space.code_unique_ids
        self._unique_id = cui.code_unique_id
        cui.code_unique_id += 4  # so we have two bits that we can mark stuff
Esempio n. 2
0
    def _initialize(self):
        if self.co_cellvars:
            argcount = self.co_argcount
            assert argcount >= 0     # annotator hint
            if self.co_flags & CO_VARARGS:
                argcount += 1
            if self.co_flags & CO_VARKEYWORDS:
                argcount += 1
            # Cell vars could shadow already-set arguments.
            # The compiler used to be clever about the order of
            # the variables in both co_varnames and co_cellvars, but
            # it no longer is for the sake of simplicity.  Moreover
            # code objects loaded from CPython don't necessarily follow
            # an order, which could lead to strange bugs if .pyc files
            # produced by CPython are loaded by PyPy.  Note that CPython
            # contains the following bad-looking nested loops at *every*
            # function call!

            # Precompute what arguments need to be copied into cellvars
            args_as_cellvars = []
            argvars = self.co_varnames
            cellvars = self.co_cellvars
            for i in range(len(cellvars)):
                cellname = cellvars[i]
                for j in range(argcount):
                    if cellname == argvars[j]:
                        # argument j has the same name as the cell var i
                        while len(args_as_cellvars) <= i:
                            args_as_cellvars.append(-1)   # pad
                        args_as_cellvars[i] = j
            self._args_as_cellvars = args_as_cellvars[:]
        else:
            self._args_as_cellvars = []

        self._compute_flatcall()

        if self.space.config.objspace.std.withmapdict:
            from pypy.objspace.std.mapdict import init_mapdict_cache
            init_mapdict_cache(self)

        cui = self.space.code_unique_ids
        self._unique_id = cui.code_unique_id
        cui.code_unique_id += 4  # so we have two bits that we can mark stuff
Esempio n. 3
0
    def _initialize(self):
        from pypy.objspace.std.mapdict import init_mapdict_cache
        from pypy.interpreter.nestedscope import CellFamily
        if self.co_cellvars:
            argcount = self.co_argcount
            assert argcount >= 0  # annotator hint
            if self.co_flags & CO_VARARGS:
                argcount += 1
            if self.co_flags & CO_VARKEYWORDS:
                argcount += 1
            argvars = self.co_varnames
            cellvars = self.co_cellvars
            args_as_cellvars = _compute_args_as_cellvars(
                argvars, cellvars, argcount)
            self._args_as_cellvars = args_as_cellvars
            self.cell_families = [CellFamily(name) for name in cellvars]
        else:
            self._args_as_cellvars = []
            self.cell_families = []

        self._compute_flatcall()

        init_mapdict_cache(self)