Skip to content
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

Custom assert messages #191

Merged
merged 1 commit into from
Dec 27, 2023
Merged

Conversation

bwburnsides
Copy link
Contributor

@bwburnsides bwburnsides commented Dec 26, 2023

The builtin assert now takes a string as an optional second argument. When present, it will be used as a custom error message if the condition fails.

ex without custom message:

  --> example.asm:10:1:
 8 | } 
 9 |  
10 | ld 0x70 ; error: failed / note:_:3: within / error:_:5: assertion 
   | ^^^^^^^                                                            
11 | 
   + note: within `test`, rule 0
   --> example.asm:3:5:
  3 |     ld {x} => 
    |     ^^^^^^     
    + error: assertion failed
    --> example.asm:5:9:
   3 |     ld {x} => 
   4 |     { 
   5 |         assert(x < 0x10) 
     |         ^^^^^^^^^^^^^^^^  
   6 |         0x55 @ x`8 
   7 |     } 

ex with custom message:

  --> example.asm:10:1:
 8 | } 
 9 |  
10 | ld 0x70 ; error: failed / note:_:3: within / error:_:5: assertion 
   | ^^^^^^^                                                            
11 | 
   + note: within `test`, rule 0
   --> example.asm:3:5:
  3 |     ld {x} => 
    |     ^^^^^^     
    + error: assertion failed: Your assertion has failed
    --> example.asm:5:9:
   3 |     ld {x} => 
   4 |     { 
   5 |         assert(x < 0x10, "Your assertion has failed") 
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
   6 |         0x55 @ x`8 
   7 |     } 

MineRobber9000 added a commit to MineRobber9000/customasm that referenced this pull request Dec 27, 2023
Adds 2 new forms of `incbin`:

- `incbin(relative_filename, start)`: includes `relative_filename` starting from offset `start`
- `incbin(relative_filename, start, size)`: includes `size` bytes from `relative_filename` starting from offset `start`

I'd also like to make `incbinstr` and `inchexstr` work similarly, but I'm not sure how to make it work.

When hlorenzi#191 gets merged, `ensure_inc_args` can be replaced with a call to `query.ensure_min_max_arg_number(1,3)?;`. Since I don't have that merged locally, I just wrote a quick and dirty function to do it.
@hlorenzi hlorenzi force-pushed the CustomAssertMessages branch from 91d72dc to c0eace2 Compare December 27, 2023 18:43
@hlorenzi hlorenzi force-pushed the CustomAssertMessages branch from c0eace2 to fd4032c Compare December 27, 2023 18:45
@hlorenzi hlorenzi merged commit cbe63b6 into hlorenzi:main Dec 27, 2023
1 check passed
MineRobber9000 added a commit to MineRobber9000/customasm that referenced this pull request Dec 27, 2023
Adds 2 new forms of `incbin`:

- `incbin(relative_filename, start)`: includes `relative_filename` starting from offset `start`
- `incbin(relative_filename, start, size)`: includes `size` bytes from `relative_filename` starting from offset `start`

I'd also like to make `incbinstr` and `inchexstr` work similarly, but I'm not sure how to make it work.

When hlorenzi#191 gets merged, `ensure_inc_args` can be replaced with a call to `query.ensure_min_max_arg_number(1,3)?;`. Since I don't have that merged locally, I just wrote a quick and dirty function to do it.
MineRobber9000 added a commit to MineRobber9000/customasm that referenced this pull request Dec 28, 2023
Adds 2 new forms of `incbin`:

- `incbin(relative_filename, start)`: includes `relative_filename` starting from offset `start`
- `incbin(relative_filename, start, size)`: includes `size` bytes from `relative_filename` starting from offset `start`

I'd also like to make `incbinstr` and `inchexstr` work similarly, but I'm not sure how to make it work.

When hlorenzi#191 gets merged, `ensure_inc_args` can be replaced with a call to `query.ensure_min_max_arg_number(1,3)?;`. Since I don't have that merged locally, I just wrote a quick and dirty function to do it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants