View Ticket
Improved integer syntax. [55a5b57c3b]. check-in: 946bd10827 user: robin.hansen tags: trunk
09:26 New ticket [55a5b57c3b] 0.3.0: Integer improvements. artifact: 4a57ca5977 user: robin.hansen

Ticket UUID: 55a5b57c3ba6bc14344d83baf320576cda41859b
Title: 0.3.0: Integer improvements
Status: Open Type: Language_Proposal
Severity: Important System: Compiler
Resolution: Modified: 2021-08-10 09:26:00
User Comments:
robin.hansen added on 2021-08-10 09:26:00:

Integer improvements

The current support for integers in Stabel is quite limited. You can perform basic operations like equality, addition, subtraction, multiplication and division, as well as two-three additional operations defined in the standard library.

Note that there is no comparison functions, no bitwise functions or more advanced math functions.

In addition, the only form of integer literals currently supported is positive integers in base-10 format.

If Stabel want to be a general purpose language, the support for integers has to be improved.


  • Support most, if not all, of the basic integer operations currently available in web assembly
  • Support negative integers in base 10 format
  • Add support for hex literals
  • Add support for binary literals
  • Let integers use underscore as a separator, to make big numbers easier to read


  • Add support for variable sized integers (8-bit, 16-bit, 64-bit) at this time. This is planned for a future release
  • Unsigned integers. Not sure if they're really needed? A lot of languages does fine without them (like Java)
  • Octal literals. I've personally never seen these being used. Would love to be told of a valid use case
  • Floats. This will be a looked at in a future release


When it comes to improving literal formats, we'll stick to what's known to work well in other languages.

  • 0x marks the beginning of a hex literal: 0xFFFF
  • 0b marks the beginning of a binary literal: 0b0101
  • Underscores can be used to improve readability: 1_000, 0b01_00, 0xFA_01

For negative integers in base 10, I propose the negative sign being postfix like so: 100-

This is different from most other languages, but in most other languages the minus symbol isn't a valid function name, which it is in Stabel. By having the minus sign as postfix we avoid complicated rules in the parser for what constitutes a number and what constitutes a function.

When it comes to supporting additional operations, I propose that extra functionality is moved to math and bitwise modules depending on what categories those fit in. This requires some refactoring in the compiler around handling builtins, but is something that would likely have to be done anyway for supporting strings and arrays.

I also propose that in addition to supporting all intrinsic integer operations of the wasm spec, that we try to support all math operations available in the Elm core library for integers. If nothing else, we should at least be as good as Elm after the next major release.