Exemplo n.º 1
0
 def wrapped(func):
     jitted_func = njit(signature)(func)
     func_name = func.__name__
     scope = {
         func_name: jitted_func,
         'SQLITE_NULL': SQLITE_NULL,
         'sqlite3_result_null': sqlite3_result_null,
     }
     scope.update(CONVERTERS)
     scope.update((f.__name__, f) for f in RESULT_SETTERS.values())
     final_func_name = '{}_scalar'.format(func_name)
     genmod = gen_scalar(jitted_func, final_func_name)
     mod = ast.fix_missing_locations(genmod)
     bytecode = compile(mod, __file__, 'exec')
     exec(bytecode, scope)
     return scope[final_func_name]
Exemplo n.º 2
0
    def cls_wrapper(cls):
        class_type = cls.class_type
        instance_type = class_type.instance_type
        jitmethods = class_type.jitmethods

        # don't make decisions about what to do with NULL values for users
        step_signature = void(instance_type, *signature.args)
        jitmethods['step'].compile(step_signature)

        # aggregates can always return a NULL value
        finalize_signature = signature.return_type(instance_type)
        jitmethods['finalize'].compile(finalize_signature)

        func_name = camel_to_snake(cls.__name__)
        step_name = '{}_step'.format(func_name)
        finalize_name = '{}_finalize'.format(func_name)

        step_mod = gen_step(cls, step_name)
        finalize_mod = gen_finalize(cls, finalize_name)

        genmod = ast.Module(body=step_mod.body + finalize_mod.body)

        mod = ast.fix_missing_locations(genmod)

        code = compile(mod, __file__, 'exec')
        scope = {
            cls.__name__: cls,
            'sqlite3_aggregate_context': sqlite3_aggregate_context,
            'sqlite3_result_null': sqlite3_result_null,
            'unsafe_cast': unsafe_cast,
            'sizeof': sizeof,
            'not_null': not_null,
            'SQLITE_NULL': SQLITE_NULL,
        }
        scope.update(CONVERTERS)
        scope.update((func.__name__, func) for func in RESULT_SETTERS.values())
        exec(code, scope)

        step = scope[step_name]
        finalize = scope[finalize_name]

        cls.step.address = step.address
        cls.finalize.address = finalize.address
        return cls