Bit fields. Easier to understand?


#1

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.


#2

Yes, bit fields is a nice way to do it! I’ll use that idea next release.


#3

Do you have an ETA on the next release, or is it still in very early stages?


#4

I don’t have a release planned, because I don’t think there are any outstanding issues that need to be fixed. Just improvements like this bit fields update. Are you aware of any?


#5

I haven’t found any more bugs yet, if you don’t have anything else planned, that’s fine.