HigherOrderCO/hvm-64

add support for more numeric operations

Closed this issue · 0 comments

Add support for u8/i8/u16/i16/u32/i32 numbers and operations (currently, there's just u60, which should be kept).

The relevant code will mostly be in ops.rs and a little in ast.rs.

Number nodes should stay largely as-is; the type of a number will not be explicitly stored in the node; instead, operations will be typed. The one change I would suggest though is switching the representation of a number value from a u64 to an i64, to make sign-extension stuff easy. I don't have any strong opinions on how the Op type is represented, but it needs to be convertible to/from a 16-bit integer. Currently, it's just a simple enum; I'd probably suggest making it a #[repr(transparent)] struct(Type, OpKind), with two separate enums that each fit in a byte, but I'm flexible.

The numbers should be represented such that they can sensibly be implicitly casted between; i.e. 1 should have the same representation in all the integer types, and -1 should have the same representation in all signed integer types (and be uN::MAX in all the unsigned types).

For the syntax, I'd suggest type.op (e.g. u8.-), with op being a shorthand for u60.op (for back-compact). Also, IMO support for negative numbers would be good in the syntax, so #-1, and I think numbers should be printed as signed (so #-1 is printed as that instead of #1152921504606846975; makes the u60 readback weird, but that's fine IMO).