Esempio n. 1
0
def make_overload_template(func,
                           overload_func,
                           jit_options,
                           strict,
                           inline,
                           prefer_literal=False,
                           **kwargs):
    """
    Make a template class for function *func* overloaded by *overload_func*.
    Compiler options are passed as a dictionary to *jit_options*.
    """
    func_name = getattr(func, '__name__', str(func))
    name = "OverloadTemplate_%s" % (func_name, )
    base = _OverloadFunctionTemplate
    dct = dict(key=func,
               _overload_func=staticmethod(overload_func),
               _impl_cache={},
               _compiled_overloads={},
               _jit_options=jit_options,
               _strict=strict,
               _inline=staticmethod(InlineOptions(inline)),
               _inline_overloads={},
               prefer_literal=prefer_literal,
               metadata=kwargs)
    return type(base)(name, (base, ), dct)
Esempio n. 2
0
def make_overload_attribute_template(typ,
                                     attr,
                                     overload_func,
                                     inline,
                                     prefer_literal=False,
                                     base=_OverloadAttributeTemplate,
                                     **kwargs):
    """
    Make a template class for attribute *attr* of *typ* overloaded by
    *overload_func*.
    """
    assert isinstance(typ, types.Type) or issubclass(typ, types.Type)
    name = "OverloadAttributeTemplate_%s_%s" % (typ, attr)
    # Note the implementation cache is subclass-specific
    dct = dict(
        key=typ,
        _attr=attr,
        _impl_cache={},
        _inline=staticmethod(InlineOptions(inline)),
        _inline_overloads={},
        _overload_func=staticmethod(overload_func),
        prefer_literal=prefer_literal,
        metadata=kwargs,
    )
    obj = type(base)(name, (base, ), dct)
    return obj