ams-hackers / gbforth

👾 A Forth-based Game Boy development kit
https://gbforth.org
MIT License
128 stars 24 forks source link

Assertion lib #337

Closed tkers closed 2 years ago

tkers commented 2 years ago

Includes words for assertions as defined in gforth:

Example usage:

require assert.fs
2 assert-level!

: main
  assert( depth 0= )
  \ do other things here...
  assert2( big-computation 42 = )
  \ some more stuff...
  bye ;

Error message I initially defined the behaviour of the "error handler" to simply show a message assertion failed and run bye to stop execution directly, but this would make it hard to know which assertion to check (the target device is not able to show a stack trace on THROW).

The current version shows the possibility to include a file.fs:42 in the error message, which is great for debugging, but comes at the cost of using more ROM to store the filenames and linenumbers in.

Of course, you can always disable assertions you don't need anymore, but I'm not sure what the better tradeoff is yet.

Todo