runway-compiler icon indicating copy to clipboard operation
runway-compiler copied to clipboard

Add an `Integer` primitive.

Open joelburget opened this issue 9 years ago • 3 comments

It's sometimes convenient to specify something as an integer, rather than supplying a possible range. This implementation is probably not robust enough and should be backed by bignum, but I'm treating it as an experiment.

Generalizing, it would be nice to add a primitive String type.

I understand the appeal in having a minimal language with a small surface area, however builtins are rather convenient.

Test plan:

  • npm test
  • Run this contract: https://gist.github.com/joelburget/7b9693bb4abde38a046ad2ab3e758e62

joelburget avatar Jul 06 '16 18:07 joelburget

By the way, this is more of an RFC than a serious pull request. Curious whether there's interest in something like this in the language.

joelburget avatar Jul 06 '16 19:07 joelburget

The problem with having unconstrained integers is that you can't exhaustively search through them in the check phase.

dgryski avatar Jul 06 '16 20:07 dgryski

I'd be ok with an Integer as shorthand for a (signed/unsigned?) number that's at least 32 bits large. That's pretty much what your PR implements, so that's cool. I'm trying to keep it possible for a more efficient compiler to execute models without storing model state on the heap, so I'd like to avoid bignum if at all possible. For the same reason, Vector[Integer] should probably be disallowed, as that'd allocate gigabytes of memory.

Strings feel like a separate discussion. I've thought about having string literals for print statements before (or better yet, format strings). Do you have a use case for manipulating strings at runtime?

ongardie-sfdc avatar Jul 08 '16 23:07 ongardie-sfdc