New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specifying literals size #26
Comments
This can be done with asserts, but I'd like it if there was shorter syntax that had the same effect.
|
Oh, yeah! This was definitely in the plans. My planned syntax for this would be: example {value: u8} -> 0x10 @ value[7:0] ; unsigned 8-bit constraint, accepts 0x00 through 0xff
example {value: s8} -> 0x10 @ value[7:0] ; signed 8-bit constraint, accepts -0x80 through 0x7f (Perhaps even allowing you to suppress the These would throw errors similarly to the asserts moonheart08 posted above. But right now, you must use explicit asserts to get this behavior. I'll try to work on this feature as soon as possible! |
I didn't think of this one, that's pretty clever :)
Oh that's great! This syntax is far better that I proposed. |
Done! You can now use this syntax, and even elide slices on argument usage. There is a third parameter type too: example {value: u8} -> 0x10 @ value ; unsigned 8-bit constraint, accepts 0x00 through 0xff
example {value: s8} -> 0x10 @ value ; signed 8-bit constraint, accepts -0x80 through 0x7f
example {value: i8} -> 0x10 @ value ; signed/unsigned 8-bit constraint, accepts -0x80 through 0xff And, of course, you can use whichever number of bits you like, such as |
Oh that was quick :D |
Hi there,
I'm using CustomASM for quite a bit of time now and I found it really enjoyable to use.
Still, I have one problem that is quite problematic to me: it's not possible to specify the maximum size of literals.
To understand the problem, let's consider the following ASM definition:
As oyu can see, the
example
instruction only uses 1 byte of its only operand.Now let's consider we use this instruction like this:
This code will produce the following output:
The problem is we lose here the most significant byte of the operand in the second call. This is an error that can happen, but after compiling if we do not read the produced assembly we'll just be stuck with a bug that's hard to debug.
So I think it would be really useful to specify the maximum size of a literal, and throw a compilation error if the provided one exceeds this size. Something like this for instance:
Or whatever syntax you may choose. In the case the literal is higher than 0xFF, an error would be thrown to indicate the literal is too big.
I don't know if this is complicated to implement though.
The text was updated successfully, but these errors were encountered: