pure-c/purec

Implement C FFI for purescript-integers

felixSchl opened this issue · 2 comments

Required by #12

I would love to get some help with this: https://github.com/pure-c/purescript-integers/blob/c/src/Data/Int.c. What's a good way to handle NaN? Treat it strictly as a number, or some sort of hybrid? How to deal with partiality and type mismatches? The latest commit details the state of the C FFI for purescript-integers:

(WIP) Implement C FFI 

Noteworty:

* Drop dependency on purescript-global
* Data.Int.toStringAs currently only supports radix 8, 10, and 16.
  The function is partial, and so is the JS FFI, since only values in
  range 2 to 32 are allowed in JS. We further limit to 8, 10, and 16
  for no particular reason other than no developer time to implement.
* Data.Int.rem returns NaN when divisor is 0 to mimic JS.
  This requires storing it as a PURS_ANY_TAG_NUM, which invalidates
  the type signature (it's supposed to return an Int)
* (WIP) Data.Int.quot: what should happen when divided by 0?
* (WIP) Data.Int.Bits.*: NOT IMPLEMENTED YET

Edit:

Re radix related partiality, I just noticed that Radix does not export it's constructor, so while the function itself remains partial, there's no way to produce an invalid radix in the first place, since the radix ensures only valid values are available. I guess for the C fork, we could change the radix function as a quick measure until someone devotes time to adding support for other bases.

Alright, purescript-integers passes it's test suite now, but a few things are unchecked for, so still a bit of guess work involved.

Updated notes:

  • Drop dependency on purescript-global
  • Most of the stuff in Data.Int.Bits is untested, especially '>>>'.
  • ToString is only implemented for bases 8, 10, and 16 (base 2 notably
    missing, but should be able to print in any base later on).
  • Some tests around max int size don't apply to PureC, so they've been
    commented out
  • Data.Int.rem returns NaN when divisor is 0 to mimic JS.
    This requires storing it as a PURS_ANY_TAG_NUM, which invalidates
    the type signature (it's supposed to return an Int)