Giter VIP home page Giter VIP logo

Comments (5)

moonheart08 avatar moonheart08 commented on May 14, 2024 2

This can be done with asserts, but I'd like it if there was shorter syntax that had the same effect.

assert(imm >= 0)
assert(imm <= 0xFF) ; assert that this unsigned(!) byte is within range.
assert(imm <=  0x7f)
assert(imm >= !0x7f) ; assert that this signed(!) byte is within range.

from customasm.

hlorenzi avatar hlorenzi commented on May 14, 2024 2

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 [7:0] slice syntax)

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!

from customasm.

hlorenzi avatar hlorenzi commented on May 14, 2024 1

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 {value: s32} or {value: u3}.

from customasm.

ClementNerma avatar ClementNerma commented on May 14, 2024

This can be done with asserts, but I'd like it if there was shorter syntax that had the same effect.

assert(imm >= 0)
assert(imm <= 0xFF) ; assert that this unsigned(!) byte is within range.
assert(imm <=  0x7f)
assert(imm >= !0x7f) ; assert that this signed(!) byte is within range.

I didn't think of this one, that's pretty clever :)

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 [7:0] slice syntax)

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!

Oh that's great! This syntax is far better that I proposed.
If you need help on specific implementation points, I'd be happy to help if I can :)

from customasm.

ClementNerma avatar ClementNerma commented on May 14, 2024

Oh that was quick :D
Thanks a lot for this improvement!

from customasm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.