4 ms·
I’m writing my own programming language that deals with this in a different way. You have your variables, and you have qualifiers like const or mutable. There’s
by bruce343434 5y ago
I’m writing my own programming language that deals with this in a different way. You have your variables, and you have qualifiers like const or mutable. There’s also storage order qualifiers. When you say “bigend i32” that means a 32 bit integer which will be laid out as big endian in memory. But you can still use it normally, to the programmer it has no weird inverted value.
https://gitlab.com/xmdr/ananke/-/blob/master/drafts/example.md https://gitlab.com/xmdr/ananke/-/blob/master/drafts/example....
So far, progress has been a bit slow. I still don’t have a working interpreter, not to mention compiler, because I find myself tweaking the syntax a lot. Perhaps later in december it will have finalized enough for me to dare write it out.
- Findecanor 5y agoI agree with this. Having it declared once and letting the compiler handle it would be more convenient and invite fewer errors than requiring the programmer to insert a conversion every time the variable needs to be read or written. Endianness in bitfields is not straightforward though.
- bruce343434 5y agoyou're right, and I'm still struggling with how to do this syntactically in a way that makes sense.
- tjalfi 5y agoIf you're looking for prior art, Ada has the Bit_Order and Scalar_Storage_Order attributes[0]; the latter is a GNAT extension. [0] https://www.adacore.com/gems/gem-140-bridging-the-endianness-gap https://www.adacore.com/gems/gem-140-bridging-the-endianness...
- brandmeyer 5y agoIf you're gong to the trouble to use an overlay structure to represent the serialization of an object, then the most optimal thing to do is to perform the endianness conversion once at the boundary between the outside world and the program. Adding type annotations encourages a coding style that makes many conversions at every point of use, instead of only once at the boundary.