Exemple #1
0
    def typeof_global(self, inst, target, gvar):
        try:
            typ = self.resolve_value_type(inst, gvar.value)
        except TypingError as e:
            if (gvar.name == self.func_id.func_name
                    and gvar.name in _temporary_dispatcher_map):
                # Self-recursion case where the dispatcher is not (yet?) known
                # as a global variable
                typ = types.Dispatcher(_temporary_dispatcher_map[gvar.name])
            else:
                e.patch_message("Untyped global name '%s': %s" %
                                (gvar.name, e))
                raise

        if isinstance(typ, types.Dispatcher) and typ.dispatcher.is_compiling:
            # Recursive call
            callframe = self.context.callstack.findfirst(
                typ.dispatcher.py_func)
            if callframe is not None:
                typ = types.RecursiveCall(typ)
            else:
                raise NotImplementedError("call to %s: unsupported recursion" %
                                          typ.dispatcher)

        if isinstance(typ, types.Array):
            # Global array in nopython mode is constant
            typ = typ.copy(readonly=True)

        self.sentry_modified_builtin(inst, gvar)
        self.lock_type(target.name, typ, loc=inst.loc)
        self.assumed_immutables.add(inst)
Exemple #2
0
    def typeof_global(self, inst, target, gvar):
        typ = self.context.resolve_value_type(gvar.value)

        if (typ is None and gvar.name == self.py_func.__name__
                and gvar.name in _temporary_dispatcher_map):
            # Self-recursion case where the dispatcher is not (yet?) known
            # as a global variable
            typ = types.Dispatcher(_temporary_dispatcher_map[gvar.name])

        if isinstance(typ, types.Dispatcher) and typ.dispatcher.is_compiling:
            # Recursive call
            if typ.dispatcher.py_func is self.py_func:
                typ = types.RecursiveCall(typ)
            else:
                raise NotImplementedError(
                    "call to %s: mutual recursion not supported" %
                    typ.dispatcher)

        if isinstance(typ, types.Array):
            # Global array in nopython mode is constant
            # XXX why layout='C'?
            typ = typ.copy(layout='C', readonly=True)

        if typ is not None:
            self.sentry_modified_builtin(inst, gvar)
            self.lock_type(target.name, typ, loc=inst.loc)
            self.assumed_immutables.add(inst)
        else:
            raise TypingError("Untyped global name '%s'" % gvar.name,
                              loc=inst.loc)