Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement C FFI for purescript-integers #31

Closed
felixSchl opened this issue Oct 3, 2018 · 2 comments
Closed

Implement C FFI for purescript-integers #31

felixSchl opened this issue Oct 3, 2018 · 2 comments

Comments

@felixSchl
Copy link
Collaborator

Required by #12

@felixSchl
Copy link
Collaborator Author

felixSchl commented Oct 4, 2018

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.

@felixSchl
Copy link
Collaborator Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant