hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
704 stars 55 forks source link

Custom assert messages #191

Closed bwburnsides closed 9 months ago

bwburnsides commented 9 months ago

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 |     }