|
1 | | -"""Primitive bytearray ops.""" |
| 1 | +"""Primitive bytearray ops. |
| 2 | +
|
| 3 | +NOTE: Most of these should be added to bytearray_extra_ops.c, which requires the |
| 4 | + BYTEARRAY_EXTRA_OPS primitive dependency, since these are used relatively rarely and we |
| 5 | + don't want to compile them unless needed. |
| 6 | +""" |
2 | 7 |
|
3 | 8 | from __future__ import annotations |
4 | 9 |
|
| 10 | +from mypyc.ir.deps import BYTEARRAY_EXTRA_OPS |
5 | 11 | from mypyc.ir.ops import ERR_MAGIC, ERR_NEVER |
6 | 12 | from mypyc.ir.rtypes import bit_rprimitive, bytearray_rprimitive, object_rprimitive |
7 | | -from mypyc.primitives.registry import function_op, load_address_op |
| 13 | +from mypyc.primitives.registry import function_op, load_address_op, custom_primitive_op |
8 | 14 |
|
9 | 15 | # Get the 'bytearray' type object. |
10 | 16 | load_address_op(name="builtins.bytearray", type=object_rprimitive, src="PyByteArray_Type") |
|
16 | 22 | return_type=bytearray_rprimitive, |
17 | 23 | c_function_name="PyByteArray_FromObject", |
18 | 24 | error_kind=ERR_MAGIC, |
| 25 | + dependencies=[BYTEARRAY_EXTRA_OPS], |
| 26 | +) |
| 27 | + |
| 28 | +# bytearray() -- construct empty bytearray |
| 29 | +function_op( |
| 30 | + name="builtins.bytearray", |
| 31 | + arg_types=[], |
| 32 | + return_type=bytearray_rprimitive, |
| 33 | + c_function_name="CPyByteArray_New", |
| 34 | + error_kind=ERR_MAGIC, |
19 | 35 | ) |
20 | 36 |
|
21 | | -# translate isinstance(obj, bytearray) |
22 | | -isinstance_bytearray = function_op( |
| 37 | +# isinstance(obj, bytearray) |
| 38 | +isinstance_bytearray = custom_primitive_op( |
23 | 39 | name="builtins.isinstance", |
24 | 40 | arg_types=[object_rprimitive], |
25 | 41 | return_type=bit_rprimitive, |
|
0 commit comments