Create an __init__ that sets registry and dispatch_cache to empty dicts
(builder: IRBuilder)
| 1093 | |
| 1094 | |
| 1095 | def generate_singledispatch_callable_class_ctor(builder: IRBuilder) -> None: |
| 1096 | """Create an __init__ that sets registry and dispatch_cache to empty dicts""" |
| 1097 | line = builder.fn_info.fitem.line |
| 1098 | class_ir = builder.fn_info.callable_class.ir |
| 1099 | with builder.enter_method(class_ir, "__init__", bool_rprimitive): |
| 1100 | empty_dict = builder.call_c(dict_new_op, [], line) |
| 1101 | builder.add(SetAttr(builder.self(), "registry", empty_dict, line)) |
| 1102 | cache_dict = builder.call_c(dict_new_op, [], line) |
| 1103 | dispatch_cache_str = builder.load_str("dispatch_cache") |
| 1104 | # use the py_setattr_op instead of SetAttr so that it also gets added to our __dict__ |
| 1105 | builder.primitive_op(py_setattr_op, [builder.self(), dispatch_cache_str, cache_dict], line) |
| 1106 | # the generated C code seems to expect that __init__ returns a char, so just return 1 |
| 1107 | builder.add(Return(Integer(1, bool_rprimitive, line), line)) |
| 1108 | |
| 1109 | |
| 1110 | def add_register_method_to_callable_class(builder: IRBuilder, fn_info: FuncInfo) -> None: |
no test coverage detected
searching dependent graphs…