(
builder: IRBuilder, main_singledispatch_function_name: str, fitem: FuncDef
)
| 963 | |
| 964 | |
| 965 | def generate_singledispatch_dispatch_function( |
| 966 | builder: IRBuilder, main_singledispatch_function_name: str, fitem: FuncDef |
| 967 | ) -> None: |
| 968 | line = fitem.line |
| 969 | current_func_decl = builder.mapper.func_to_decl[fitem] |
| 970 | arg_info = get_args(builder, current_func_decl.sig.args, line) |
| 971 | |
| 972 | dispatch_func_obj = builder.self() |
| 973 | |
| 974 | arg_type = builder.builder.get_type_of_obj(arg_info.args[0], line) |
| 975 | dispatch_cache = builder.builder.get_attr( |
| 976 | dispatch_func_obj, "dispatch_cache", dict_rprimitive, line |
| 977 | ) |
| 978 | call_find_impl, use_cache, call_func = BasicBlock(), BasicBlock(), BasicBlock() |
| 979 | get_result = builder.primitive_op(dict_get_method_with_none, [dispatch_cache, arg_type], line) |
| 980 | is_not_none = builder.translate_is_op(get_result, builder.none_object(), "is not", line) |
| 981 | impl_to_use = Register(object_rprimitive) |
| 982 | builder.add_bool_branch(is_not_none, use_cache, call_find_impl) |
| 983 | |
| 984 | builder.activate_block(use_cache) |
| 985 | builder.assign(impl_to_use, get_result, line) |
| 986 | builder.goto(call_func) |
| 987 | |
| 988 | builder.activate_block(call_find_impl) |
| 989 | find_impl = builder.load_module_attr_by_fullname("functools._find_impl", line) |
| 990 | registry = load_singledispatch_registry(builder, dispatch_func_obj, line) |
| 991 | uncached_impl = builder.py_call(find_impl, [arg_type, registry], line) |
| 992 | builder.call_c(exact_dict_set_item_op, [dispatch_cache, arg_type, uncached_impl], line) |
| 993 | builder.assign(impl_to_use, uncached_impl, line) |
| 994 | builder.goto(call_func) |
| 995 | |
| 996 | builder.activate_block(call_func) |
| 997 | gen_calls_to_correct_impl(builder, impl_to_use, arg_info, fitem, line) |
| 998 | |
| 999 | |
| 1000 | def gen_calls_to_correct_impl( |
no test coverage detected
searching dependent graphs…