kiedtl / finwe

A concatenative language for the Uxn VM with full compiler-enforced stack safety.
MIT License
35 stars 0 forks source link

Don't panic on underflow/overflow when testing #20

Open kiedtl opened 1 month ago

kiedtl commented 1 month ago

image

Panic'ing was good placeholder behavior (so not technically a bug), but ideally this should print a backtrace and continue on with testing.

kiedtl commented 1 month ago

Really this is an issue with the underlying emulator rather than the test harness.

In addition to printing a stack trace, the instruction should be identified properly, as part of the backtrace:

at Instruction: Orot <sk>
at foo:12
at bar:84
kiedtl commented 1 month ago

Right after creating this issue, ran into another backtrace-related problem:

image

This happens because the current function is pushing stuff onto the return stack, so when backtrace unwinds it can't handle RST size not being even.

I've patched this for now with a "paranoid mode" for backtrace-printing that decrements ptr by 1 if the RST size isn't event, effectively treating every possible pair of bytes as if it were an address (yes, this results in a lot of junk data in the trace), but ideally if the return stack state is known at time of panic then the VM should simply skip those bytes that aren't addresses.