circuitpython/py/makeobjdefiner.py
Jeff Epler a13829ff55 core: Use a bitfield to track slot status.
This reduces the size from 12 to 2 bytes.

It does assume an efficient population count instruction,
which is not guaranteed.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-19 16:26:39 -05:00

16 lines
608 B
Python

for i in range(13):
r = range(i)
filled_slots = "|".join(f"slot_weight_##f{j}" for j in r) if i else "0"
slots = "".join(
f"\n [MP_OBJ_FIND_SLOT_STATIC(f{j}, {filled_slots})] = v{j}, \\" for j in r
)
print(f"""\
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{"".join(f", f{j}, v{j}" for j in r)}) \\
const _struct_type _typename = {{ \\
.base = {{ &mp_type_type }}, \\
.flags = _flags, \\
.name = _name, \\
.filled_slots = {filled_slots}, \\
.slots = {{ \\{slots}
}}, \\
}}""")