adam-mcdaniel / oakc

A portable programming language with a compact intermediate representation
Apache License 2.0
725 stars 21 forks source link

Support for binary, octal and hexadecimal integer literals #71

Open kevinramharak opened 4 years ago

kevinramharak commented 4 years ago

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.

adam-mcdaniel commented 4 years ago

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.

adam-mcdaniel commented 4 years ago

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.

kevinramharak commented 4 years ago

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.