I have noticed in the ulisp implementation, the field minmax
in the tbl_entry_t struct is just an opaque uint8_t. It isn’t entirely clear what the bits mean, and so in my fork I replaced all of David’s octal muck with a macro that constructs the required numbers from the function type and minimum/maximum parameters. (This may have been the source of some of the confusion when other users were trying to apply my patches and I had forgot to convert the macro forms back to the octal numbers.)
However, it just dawned on me that C has had bit-field members in structs since, like, forever. Compare:
typedef const struct {
PGM_P string;
fn_ptr_type fptr;
uint8_t minmax;
const char *doc;
} tbl_entry_t;
/* snip */
{string14, sp_defun, 0327, doc14},
With:
typedef const struct {
PGM_P string;
fn_ptr_type fptr;
uint8_t funtype: 2;
uint8_t minargs: 3;
uint8_t maxargs: 3;
const char *doc;
} tbl_entry_t;
/* snip */
{string14, sp_defun, SPECIAL_FORMS, 2, 7, doc14},
Being able to put the enum constant in the definition makes it much more clear exactly what type of function it is, rather than just “2”. It’s also future-proof.