Generates a wrapper for native __bool__ methods.
(cl: ClassIR, fn: FuncIR, emitter: Emitter)
| 596 | |
| 597 | |
| 598 | def generate_bool_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: |
| 599 | """Generates a wrapper for native __bool__ methods.""" |
| 600 | name = f"{DUNDER_PREFIX}{fn.name}{cl.name_prefix(emitter.names)}" |
| 601 | emitter.emit_line(f"static int {name}(PyObject *self) {{") |
| 602 | emitter.emit_line( |
| 603 | "{}val = {}(self);".format( |
| 604 | emitter.ctype_spaced(fn.ret_type), emitter.native_function_call(fn.decl) |
| 605 | ) |
| 606 | ) |
| 607 | emitter.emit_error_check("val", fn.ret_type, "return -1;") |
| 608 | # This wouldn't be that hard to fix but it seems unimportant and |
| 609 | # getting error handling and unboxing right would be fiddly. (And |
| 610 | # way easier to do in IR!) |
| 611 | assert is_bool_rprimitive(fn.ret_type), "Only bool return supported for __bool__" |
| 612 | emitter.emit_line("return val;") |
| 613 | emitter.emit_line("}") |
| 614 | |
| 615 | return name |
| 616 | |
| 617 | |
| 618 | def generate_del_item_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str: |
nothing calls this directly
no test coverage detected
searching dependent graphs…