adam-mcdaniel/oakc

Support for binary, octal and hexadecimal integer literals

Opened this issue · 3 comments

It would be nice to support the following integer literals:

let binary = 0b0110;
let octal = 0o777;
let hex = 0xdead;

I think forcing the b, o and x to be lower case would be a good idea. Taken from Rust.

How would these be represented in the backend? Until we support using integers or characters as the de-facto representation of data on the memory tape, I think that we cant use hex, octal, or binary in a meaningful way. I would like to implement memory as an array of characters, but that would definitely require several more machine code instructions. I don't think that's necessarily a bad thing, though.

How do you think we should make the change from doubles to bytes in memory? I think that we should just introduce push_double, push_int, push_byte, pop_double, pop_int, pop_byte functions where they pop different sizes of memory off of the stack.

Ah right, I didn't think about float representation since im limited to 16 bit wide integers in my implementation. I think having different data types would be a good idea as a tape of floats is very limiting. Having different push/pop functions should be a good start but that would require a definition on how operations on mixed data types would work. Or how they are forbidden. And ofcourse how a cast should be implemented.
I would prefer names like i32 over int as it would be easier to infer the width of the data type, but that is just a suggestion.