`Char#ord` at compile time

Ahoy-hoy Ary!

The use case is protocol implementation. There’s a recurring pattern across a number of vendors to use ascii chars (presumably for readability / typability) as the basis of a socket API. This may be something like:

SOH <command> STX <data>, ... ETX

where <command> is a single byte.

The ideal way of modelling this is an Enum as it provides neat serialisation and deserialisation, while keeping type safety. This is all do-able, but requires a manual conversion to the byte value.

enum Command : UInt8
  Foo = 0x61 # 'a'
  Bar = 0x62 # 'b'
  # ...
end

Not a major issue, but given all vendor docs will refer to the character based values, it just an extra layer of conversation that a human (or external tool) is needing to do.

This complexity then levels up if you say move to a two byte <command> field that you may want to pack into a UInt16.

enum Command : UInt16
  Foo = 0x6178 # 'a', 'x'
  Bar = 0x6279 # 'b', 'y'
  # ...
end

A solution that would solve both of these is a CharLiteral#ord that spits out a NumberLiteral. This would provide the ability to do any bitpacking within a macro context. Alternatively, allowing expressions that assign enum values to evaluate the same way constants elsewhere. Ideally both!

Happy to dive into either of these with a PR, but keen to ensure I’m not missing something first.